将war文件部署到Tomcat时出现Elastic Beanstalk 502错误
Posted
技术标签:
【中文标题】将war文件部署到Tomcat时出现Elastic Beanstalk 502错误【英文标题】:Elastic Beanstalk 502 error when deploying war file to Tomcat 【发布时间】:2018-10-12 04:30:51 【问题描述】:我已将 Shopizer 战争文件部署到 Tomcat Elastic Beanstalk 实例。我已经配置了一个 mysql 数据库,据我所知,一切都应该是正确的。问题是当我尝试访问 URL 时出现 502 错误。我知道 Elastic Beanstalk 在 60 秒后超时,因此我增加了超时限制,但仍然遇到问题。
我在 Catalina.out 日志中注意到了这一点。我知道这只是一个警告,但它可能指向我的问题吗?
2018-05-02 06:02:51.220 WARN 3233 --- [-AdminTaskTimer] c.m.v.a.ThreadPoolAsynchronousRunner : com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@4446a77 -- 明显的死锁!!!完成状态: 托管线程:3 活动线程:3 活动任务: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@55aa1343 在线程上:C3P0PooledConnectionPoolManager[identityToken->1br9tjp9v8puiagh4cnwb|550ee827]-HelperThread-#2 com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@326b931e 在线程上:C3P0PooledConnectionPoolManager[identityToken->1br9tjp9v8puiagh4cnwb|550ee827]-HelperThread-#0 com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@7fc7b7d9 在线程上:C3P0PooledConnectionPoolManager[identityToken->1br9tjp9v8puiagh4cnwb|550ee827]-HelperThread-#1 待处理任务: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@591e9ef6 池线程堆栈跟踪: 线程[C3P0PooledConnectionPoolManager[identityToken->1br9tjp9v8puiagh4cnwb|550ee827]-HelperThread-#2,5,main] java.net.PlainSocketImpl.socketConnect(本机方法) java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) java.net.Socket.connect(Socket.java:589) com.mysql.cj.core.io.StandardSocketFactory.connect(StandardSocketFactory.java:202) com.mysql.cj.mysqla.io.MysqlaSocketConnection.connect(MysqlaSocketConnection.java:57) com.mysql.cj.mysqla.MysqlaSession.connect(MysqlaSession.java:122) com.mysql.cj.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:1619) com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:1601) com.mysql.cj.jdbc.ConnectionImpl.(ConnectionImpl.java:633) com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:347) com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:219) com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175) com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220) com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206) com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203) com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138) com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125) com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44) com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1870) com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696) 线程[C3P0PooledConnectionPoolManager[identityToken->1br9tjp9v8puiagh4cnwb|550ee827]-HelperThread-#0,5,main] java.net.PlainSocketImpl.socketConnect(本机方法) java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) java.net.Socket.connect(Socket.java:589) com.mysql.cj.core.io.StandardSocketFactory.connect(StandardSocketFactory.java:202) com.mysql.cj.mysqla.io.MysqlaSocketConnection.connect(MysqlaSocketConnection.java:57) com.mysql.cj.mysqla.MysqlaSession.connect(MysqlaSession.java:122) com.mysql.cj.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:1619) com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:1601) com.mysql.cj.jdbc.ConnectionImpl.(ConnectionImpl.java:633) com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:347) com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:219) com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175) com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220) com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206) com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203) com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138) com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125) com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44) com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1870) com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696) 线程[C3P0PooledConnectionPoolManager[identityToken->1br9tjp9v8puiagh4cnwb|550ee827]-HelperThread-#1,5,main] java.net.PlainSocketImpl.socketConnect(本机方法) java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) java.net.Socket.connect(Socket.java:589) com.mysql.cj.core.io.StandardSocketFactory.connect(StandardSocketFactory.java:202) com.mysql.cj.mysqla.io.MysqlaSocketConnection.connect(MysqlaSocketConnection.java:57) com.mysql.cj.mysqla.MysqlaSession.connect(MysqlaSession.java:122) com.mysql.cj.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:1619) com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:1601) com.mysql.cj.jdbc.ConnectionImpl.(ConnectionImpl.java:633) com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:347) com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:219) com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175) com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220) com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206) com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203) com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1138) com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1125) com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44) com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1870) com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)
2018-05-02 06:03:51.222 WARN 3233 --- [-AdminTaskTimer] cmvaThreadPoolAsynchronousRunner:任务 com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@55aa1343(在死锁的 PoolThread 中)未能在最长时间内完成60000 毫秒。尝试中断()。 2018-05-02 06:03:51.222 WARN 3233 --- [-AdminTaskTimer] c.m.v.a.ThreadPoolAsynchronousRunner:任务 com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@326b931e(在死锁的 PoolThread 中)未能在最长时间 60000 毫秒内完成。尝试中断()。 2018-05-02 06:03:51.222 WARN 3233 --- [-AdminTaskTimer] c.m.v.a.ThreadPoolAsynchronousRunner:任务 com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@7fc7b7d9(在死锁的 PoolThread 中)未能在最长时间 60000 毫秒内完成。尝试中断()。
【问题讨论】:
【参考方案1】:我搞砸了很多步骤,并没有仔细研究哪些有帮助,哪些没有。如果我有机会经历这些并提供更具体的帮助,我会的,但现在,这就是我所做的。
在sm-shop/src/main/resources/application.properties
添加:
server.port = 5000
从创建数据库开始。您将需要 database.properties 文件的详细信息。我创建了一个 mySQL Aurora 数据库。
将数据库属性添加到sm-shop/src/main/resources/database.properties
。
在 AWS 中,创建 Elastic Beanstalk 应用程序和环境。我使用了 Tomcat,因此必须构建一个 war 文件,并将其部署到环境中。
在配置>软件中设置如下:
Initial JVM heap size (Xms) = 1024m
Max JVM heap size (Xmx) = 1024m
XX:MaxPermSize = 256m
添加以下环境属性:
HIBERNATE_DIALECT = org.hibernate.dialect.MySQLDialect
JDBC_CONNECTION_STRING = jdbc:mysql://mydb.ptmjbhdur9pw.eu-west-2.rds.amazonaws.com:3306/SALESMANAGER?user=username&password=password&autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&&driverClass=com.mysql.cj.jdbc.Driver
SERVER_PORT = 5000
在配置中 > 修改实例:
Instance type = (at least)m1.small
EC2 安全组 - 我在这里勾选了数据库安全组。
在配置 > 负载均衡器中添加以下监听器:
Port = 8080
Protocol = HTTP
Instance Port = 8080
Instance Protocol = HTTP
当所有这些都完成并且我启动应用程序时没有任何明显的 AWS 问题时,应用程序不会加载,因此我检查了 Catalina 日志。它显示了与https://groups.google.com/forum/#!searchin/shopizer/ru%7Csort:date/shopizer/hQjqp_5UswI/goVKf5BTCQAJ 相同的错误,所以我进行了更改。应用程序现在加载。
我希望这可以节省一些时间(和悲伤)。
【讨论】:
以上是关于将war文件部署到Tomcat时出现Elastic Beanstalk 502错误的主要内容,如果未能解决你的问题,请参考以下文章
将 Spring Boot 应用程序部署到 Elastic Beanstalk 时出现 502 Bad Gateway
部署 SnappyData-0.5 pulse.war 时出现 Bean 缺失错误