在 AWS Beanstalk 上部署 SpringBoot - 应用程序启动,连接到 RDS-DB,但浏览器无法连接

Posted

技术标签:

【中文标题】在 AWS Beanstalk 上部署 SpringBoot - 应用程序启动,连接到 RDS-DB,但浏览器无法连接【英文标题】:Deploying SpringBoot on AWS Beanstalk - app starts, connects to RDS-DB, but browser can't connect 【发布时间】:2020-10-02 15:39:37 【问题描述】:

我现在正在学习 AWS,因此现在将我的 Spring Boot 应用程序部署在 AWS Elasctic Beanstalk 上,并将其连接到我放在 AWS RDS 上的 mariaDB 数据库。那是成功的!我可以在我的数据库中看到测试条目,并且 Elastic Beanstalk 日志文件显示 Spring 应用程序已启动并且运行状况检查正常。

但是当我点击应用程序studileih.eu-central-1.elasticbeanstalk.com 的链接时,我得到一个 404。 我还尝试了studileih.eu-central-1.elasticbeanstalk.com/5000,因为我的 Spring Boot 应用程序在端口 5000 上启动(我将其从 8080 更改为 5000,因为我认为 ElasticBeanstalk 需要端口 5000?)studileih.eu-central-1.elasticbeanstalk.com/allProducts 和 studileih.eu-central-1.elasticbeanstalk.com/5000/allProducts 因为 /allProducts 是我获取的端点要求。

Jun 12 17:42:41 ip-172-31-14-223 web: .   ____          _            __ _ _
Jun 12 17:42:41 ip-172-31-14-223 web: /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
Jun 12 17:42:41 ip-172-31-14-223 web: ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
Jun 12 17:42:41 ip-172-31-14-223 web: \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
Jun 12 17:42:41 ip-172-31-14-223 web: '  |____| .__|_| |_|_| |_\__, | / / / /
Jun 12 17:42:41 ip-172-31-14-223 web: =========|_|==============|___/=/_/_/_/
Jun 12 17:42:41 ip-172-31-14-223 web: :: Spring Boot ::        (v2.2.7.RELEASE)
Jun 12 17:42:41 ip-172-31-14-223 web: 2020-06-12 17:42:41.459  INFO 4050 --- [           main]     
c.e.studileih.StudileihApplication       : Starting StudileihApplication v0.0.1-SNAPSHOT on     
ip-172-31-14-223.eu-central-1.compute.internal with PID 4050 (/var/app/current/application.jar 
started by webapp in /var/app/current)
Jun 12 17:42:41 ip-172-31-14-223 web: 2020-06-12 17:42:41.471  INFO 4050 --- [           main] 
c.e.studileih.StudileihApplication       : No active profile set, falling back to default profiles:   
default
Jun 12 17:42:43 ip-172-31-14-223 web: 2020-06-12 17:42:43.721  INFO 4050 --- [           main] 
.s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT 
mode.
Jun 12 17:42:43 ip-172-31-14-223 web: 2020-06-12 17:42:43.912  INFO 4050 --- [           main] 
 .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 164ms. Found 
2 JPA repository interfaces.
Jun 12 17:42:45 ip-172-31-14-223 web: 2020-06-12 17:42:45.720  INFO 4050 --- [           main] 
o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 5000 (http)
Jun 12 17:42:45 ip-172-31-14-223 web: 2020-06-12 17:42:45.751  INFO 4050 --- [           main] 
o.apache.catalina.core.StandardService   : Starting service [Tomcat]
Jun 12 17:42:45 ip-172-31-14-223 web: 2020-06-12 17:42:45.752  INFO 4050 --- [           main] 
org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.34]
Jun 12 17:42:45 ip-172-31-14-223 web: 2020-06-12 17:42:45.967  INFO 4050 --- [           main] 
o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
Jun 12 17:42:45 ip-172-31-14-223 web: 2020-06-12 17:42:45.970  INFO 4050 --- [           main] 
o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in  
4339 ms
Jun 12 17:42:47 ip-172-31-14-223 web: 2020-06-12 17:42:47.014  INFO 4050 --- [           main] 
o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
Jun 12 17:42:47 ip-172-31-14-223 web: 2020-06-12 17:42:47.140  INFO 4050 --- [           main] 
org.hibernate.Version                    : HHH000412: Hibernate ORM core version 5.4.15.Final
Jun 12 17:42:47 ip-172-31-14-223 web: 2020-06-12 17:42:47.475  INFO 4050 --- [           main] 
o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations 5.1.0.Final
Jun 12 17:42:47 ip-172-31-14-223 web: 2020-06-12 17:42:47.742  INFO 4050 --- [           main] 
com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
Jun 12 17:42:47 ip-172-31-14-223 web: 2020-06-12 17:42:47.932  INFO 4050 --- [           main] 
com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
Jun 12 17:42:47 ip-172-31-14-223 web: 2020-06-12 17:42:47.979  INFO 4050 --- [           main] 
org.hibernate.dialect.Dialect            : HHH000400: Using dialect: 
org.hibernate.dialect.MariaDB53Dialect
Jun 12 17:42:48 ip-172-31-14-223 web: 2020-06-12 17:42:48.207  WARN 4050 --- [           main] 
org.hibernate.cfg.AnnotationBinder       : HHH000503: A class should not be annotated with both 
@Inheritance and @MappedSuperclass. @Inheritance will be ignored for: 
com.example.studileih.Entity.BaseEntity.
Jun 12 17:42:49 ip-172-31-14-223 web: 2020-06-12 17:42:49.638  INFO 4050 --- [           main] 
org.hibernate.tuple.PojoInstantiator     : HHH000182: No default (no-argument) constructor for 
class: com.example.studileih.Entity.Country (class must be instantiated by Interceptor)
Jun 12 17:42:49 ip-172-31-14-223 web: 2020-06-12 17:42:49.763  INFO 4050 --- [           main] 
org.hibernate.tuple.PojoInstantiator     : HHH000182: No default (no-argument) constructor for 
class: com.example.studileih.Entity.City (class must be instantiated by Interceptor)
Jun 12 17:42:50 ip-172-31-14-223 web: 2020-06-12 17:42:50.133  INFO 4050 --- [           main] 
o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: 
[org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
Jun 12 17:42:50 ip-172-31-14-223 web: 2020-06-12 17:42:50.142  INFO 4050 --- [           main] 
j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 
'default'
Jun 12 17:42:50 ip-172-31-14-223 web: Hibernate: select `next_val` as id_val from 
`hibernate_sequence` for update
Jun 12 17:42:50 ip-172-31-14-223 web: Hibernate: update `hibernate_sequence` set `next_val`= ? where  
`next_val`=?
Jun 12 17:42:50 ip-172-31-14-223 web: Hibernate: insert into `product` (`created_at`, `updated_at`, 
`available`, `name`, `pic_paths`, `price`, `title`, `type`, `user_id`, `views`, `id`) values (?, ?, 
?, ?, ?, ?, ?, ?, ?, ?, ?)
Jun 12 17:42:51 ip-172-31-14-223 web: Hibernate: select `next_val` as id_val from 
`hibernate_sequence` for update
[... some more hibernate logs that I deleted for better readablility]
Jun 12 17:42:51 ip-172-31-14-223 web: 2020-06-12 17:42:51.295  WARN 4050 --- [           main]    
JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore,   
database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-
view to disable this warning
Jun 12 17:42:51 ip-172-31-14-223 web: 2020-06-12 17:42:51.592  INFO 4050 --- [           main] 
 o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
Jun 12 17:42:52 ip-172-31-14-223 web: 2020-06-12 17:42:52.069  INFO 4050 --- [           main] 
o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 5000 (http) with context path   
''
Jun 12 17:42:52 ip-172-31-14-223 web: 2020-06-12 17:42:52.078  INFO 4050 --- [           main] 
c.e.studileih.StudileihApplication       : Started StudileihApplication in 11.903 seconds (JVM 
running for 13.534)
Jun 12 17:43:16 ip-172-31-14-223 web: 2020-06-12 17:43:16.252  INFO 4050 --- [nio-5000-exec-1] 
o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
Jun 12 17:43:16 ip-172-31-14-223 web: 2020-06-12 17:43:16.254  INFO 4050 --- [nio-5000-exec-1] 
o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
Jun 12 17:43:16 ip-172-31-14-223 web: 2020-06-12 17:43:16.279  INFO 4050 --- [nio-5000-exec-1] 
o.s.web.servlet.DispatcherServlet        : Completed initialization in 25 ms


----------------------------------------
/var/log/nginx/access.log
----------------------------------------
77.190.237.177 - - [12/Jun/2020:17:34:32 +0000] "GET / HTTP/1.1" 404 306 "-" "Mozilla/5.0 (Windows    
NT 10.0; Win64; x64) AppleWebKit/537.36 (Khtml, like Gecko) Chrome/83.0.4103.97 Safari/537.36" "-"
77.190.237.177 - - [12/Jun/2020:17:34:33 +0000] "GET /favicon.ico HTTP/1.1" 404 143 
"http://studileih.eu-central-1.elasticbeanstalk.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64)    
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36" "-"
77.190.237.177 - - [12/Jun/2020:17:34:43 +0000] "GET /allproducts HTTP/1.1" 404 306 "-" "Mozilla/5.0     
(Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97   
Safari/537.36" "-"
77.190.237.177 - - [12/Jun/2020:17:35:26 +0000] "GET / HTTP/1.1" 404 306 "-" "Mozilla/5.0 (Windows 
 NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36" "-" 
 77.190.237.177 - - [12/Jun/2020:17:35:57 +0000] "GET / HTTP/1.1" 404 306 "-" "Mozilla/5.0 (Windows   
 NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36" "-"
77.190.237.177 - - [12/Jun/2020:17:36:05 +0000] "GET /allproducts HTTP/1.1" 404 306 "-" "Mozilla/5.0     
(Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97   
Safari/537.36" "-"
77.190.237.177 - - [12/Jun/2020:17:43:16 +0000] "GET / HTTP/1.1" 404 306 "-" "Mozilla/5.0 (Windows 
NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36" "-"
77.190.237.177 - - [12/Jun/2020:17:45:13 +0000] "GET / HTTP/1.1" 404 306 "-" "Mozilla/5.0 (Windows 
NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36" "-"
77.190.237.177 - - [12/Jun/2020:17:45:13 +0000] "GET /favicon.ico HTTP/1.1" 404 143 
"http://18.157.145.222/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like   
Gecko) Chrome/83.0.4103.97 Safari/537.36" "-"
77.190.237.177 - - [12/Jun/2020:17:45:39 +0000] "GET / HTTP/1.1" 404 306 "-" "Mozilla/5.0 (Windows 
NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36" "-"
77.190.237.177 - - [12/Jun/2020:17:45:54 +0000] "GET / HTTP/1.1" 404 306 "-" "Mozilla/5.0 (Windows 
NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36" "-"
77.190.237.177 - - [12/Jun/2020:17:46:13 +0000] "GET /5000 HTTP/1.1" 404 306 "-" "Mozilla/5.0 
(Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97   
Safari/537.36" "-" 
77.190.237.177 - - [12/Jun/2020:17:47:57 +0000] "GET / HTTP/1.1" 404 306 "-" "Mozilla/5.0 (Windows 
NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36" "-"


----------------------------------------
/var/log/nginx/error.log
----------------------------------------
(end of log)

【问题讨论】:

【参考方案1】:

我以为我已经将安全组入站规则设置为“允许来自任何地方的所有流量”,但这是错误的。添加它们后,它与 http://studileih.eu-central-1.elasticbeanstalk.com/allProducts 一起工作(不需要端口 5000)奇怪的是 HTTP 规则还不够强硬......:

那是直接在浏览器中的结果:

【讨论】:

以上是关于在 AWS Beanstalk 上部署 SpringBoot - 应用程序启动,连接到 RDS-DB,但浏览器无法连接的主要内容,如果未能解决你的问题,请参考以下文章

如何使用 aws cli 在 Elastic Beanstalk 上上传和部署?

如何在 AWS Elastic Beanstalk 上部署 next.js?

在 AWS Elastic Beanstalk 上部署 rails 应用程序

在 AWS Elastic Beanstalk 上部署 Geodjango 应用程序

使用 CLI 在 AWS Elastic Beanstalk 上部署 RoR 项目

在 AWS 弹性 beanstalk 上部署 Rails - 静态资产路由不起作用