Hal*_*lex 4 amazon-ec2 amazon-web-services spring-boot amazon-elastic-beanstalk
我有一个 SpringBoot 应用程序,可以很好地部署到 AWS Beanstalk,并且默认的 nginx 代理可以正常工作,允许我通过端口 80 进行连接。
按照此处的说明进行操作: https: //docs.aws.amazon.com/elasticbeanstalk/latest/dg/https-singleinstance.html,并使用我的另一个使用此确切配置的项目进行验证,Beanstalk 无法部署应用程序错误:
2020/05/29 01:27:56.418780 [ERROR] An error occurred during execution of command [app-deploy] - [CheckProcfileForJavaApplication]. Stop running the command. Error: there is no Procfile and no .jar file at root level of your source bundle
我的war文件的内容是这样的:
app.war
    -.ebextensions
        -nginx/conf.d/https.conf
        -https-instance-single.config
        -https-instance.config
    -web-inf/
我的配置文件作为有效的 yaml 文件传递。(这些文件与 AWS 文档中的文件以及在我的其他项目中使用的文件相同。)
我使用的是单个实例,端口 443 设置为开放。
这些是各个日志文件中报告的错误:
----------------------------------------
/var/log/eb-engine.log
----------------------------------------
2020/05/29 01:37:53.054366 [ERROR] /usr/bin/id: healthd: no such user
...
2020/05/29 01:37:53.254965 [ERROR] Created symlink from /etc/systemd/system/multi-user.target.wants/healthd.service to /etc/systemd/system/healthd.service.
...
2020/05/29 01:37:53.732794 [ERROR] Created symlink from /etc/systemd/system/multi-user.target.wants/cfn-hup.service to /etc/systemd/system/cfn-hup.service.
----------------------------------------
/var/log/cfn-hup.log
----------------------------------------
ReadTimeout: HTTPSConnectionPool(host='sqs.us-east-1.amazonaws.com', port=443): Read timed out. (read timeout=23)
根据 @Dean Wookey 对 Java 11 的回答,我已经成功部署了 Spring Boot 应用程序 jar 以及 .ebextensions 文件夹。我刚刚将 Maven antrun 插件添加到我的 Maven 构建配置中,对于输出,我收到 .zip 文件,其中包含同一级别的 .ebextensions 文件夹和 spring Boot .jar 文件。只需将此最终 zip 文件部署到 AWS UI 控制台即可。
以下是maven antrun插件配置
....
<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.8</version>
            <executions>
                <execution>
                    <id>prepare</id>
                    <phase>package</phase>
                    <configuration>
                        <tasks>
                            <copy todir="${project.build.directory}/${project.build.finalName}/" overwrite="false">
                                <fileset dir="./" includes=".ebextensions/**"/>
                                <fileset dir="${project.build.directory}" includes="*.jar"/>
                            </copy>
                            <zip destfile="${project.build.directory}/${project.build.finalName}.zip" basedir="${project.build.directory}/${project.build.finalName}"/>
                        </tasks>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
....
Java 和 Linux 版本的问题
如果您使用 Java 8 和 Linux 2.10.9 代码将正常工作并覆盖 ngingx 配置,但如果您选择 Corretto 11 和 Linux 2.2.3 则会出现以下错误。
错误:源包的根级别没有 Procfile 和 .jar 文件
使用 Java 8 创建新环境并再次部署应用程序将解决问题。
小智 5
另一种方法是将源 jar 包打包到还包含 .ebextensions 文件夹的 zip 中,而不是按照 vaquar khan 的答案中所述更改为 java 8。
换句话说:
source.zip
    -.ebextensions
        -nginx/conf.d/https.conf
        -https-instance-single.config
        -https-instance.config
    -web-inf/
    -app.war
如果您查看最新文档https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/platforms-linux-extend.html,您会看到 nginx 配置现在位于 .platform 文件夹中,所以你的结构将是:
source.zip
    -.ebextensions
        -https-instance-single.config
        -https-instance.config
    -.platform
        -nginx/conf.d/https.conf
    -web-inf/
    -app.war
| 归档时间: | 
 | 
| 查看次数: | 3805 次 | 
| 最近记录: |