数据库
首页 > 数据库> > java – 在AWS-EC2上运行的SpringBoot应用程序无法连接到MySQL AWS-RDS数据库

java – 在AWS-EC2上运行的SpringBoot应用程序无法连接到MySQL AWS-RDS数据库

作者:互联网

我在运行我在EC2实例中开发的应用程序时遇到问题.当我执行.jar(java -jar app.jar)时,SpringBoot应用程序启动但尝试连接到我的MySQL RDS数据库时失败.问题是当我在我的机器上本地运行应用程序时,它与数据库连接没有任何问题.

我打开了应用程序运行的端口(8090)和MySql端口(3306),用于入站和出站流量:

enter image description here

这是我得到的错误:

2016-09-23 17:46:38.132  INFO 10161 --- [main] .t.TomcatEmbeddedServletContainerFactory : Server initialized with port: 8090
2016-09-23 17:46:38.604  INFO 10161 --- [main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2016-09-23 17:46:38.605  INFO 10161 --- [main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/7.0.54
2016-09-23 17:46:38.724  INFO 10161 --- [ost startStop 1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2016-09-23 17:46:38.725  INFO 10161 --- [ost startStop 1] o.s.web.context.ContextLoader: Root WebApplicationContext: initialization completed in 5028 ms
2016-09-23 17:48:48.476 ERROR 10161 --- [ost startStop 1] o.a.tomcat.jdbc.pool.ConnectionPool: Unable to create initial connections of pool.

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

任何想法我怎样才能解决这个问题?

非常感谢您的帮助

问候

安德烈斯

解决方法:

从您的描述和日志文件中,可能是网络配置是此原因.

您可能希望绘制实例的网络拓扑(区域/可用区域,VPC,子网,网络acl,安全组).当您执行更复杂的开发工作时,这将非常有用.
有很好的参考:VPC IntroductionSecurity in your VPCScenarios for Accessing a DB Instance in a VPC

我建议您进行以下操作以进行故障排除:

>检查EC2实例和RDS实例的安全组(SG)配置.
您可以通过转到EC2仪表板/ RDS仪表板 – >来查看此信息.单击实例并查看“安全组”说明,或者单击“设置”图标(显示/隐藏列)并勾选“安全组”.

在RDS的SG配置中:确保您具有从EC2实例的SG到端口3306的启用访问权限.您可以通过将EC2实例的SG ID放入配置的Source字段作为“自定义IP”值来实现.有关更多详细信息,请参阅上述参考中的第一个方案.
>使用mysql命令行测试EC2实例和RDS之间的连接.

希望能帮助到你.

标签:java,mysql,spring-boot,amazon-ec2,amazon-rds
来源: https://codeday.me/bug/20190828/1755983.html