小编Ste*_*oll的帖子

为什么在尝试使用 Java 连接到 RDS PostgreSQL 数据库时会收到 SocketTimeoutException?

我有一个 Spring 应用程序,我试图在 AWS 上托管,几天来我一直在努力配置。

我有一个 EC2 实例,并且能够通过 SSH 连接到它。我还在 AWS 中设置了 Postgres RDS 数据库,但我无法使用 IDE 中的代码连接到它,因此我尚未将应用程序上传到 EC2 实例。

我认为问题出在我的安全组上,正如application.propertiesAWS 文档和其他指南所建议的那样。

我一直试图了解安全组的来龙去脉,但这是一场斗争。我认为在实际生产环境中精确地使用我的 SG 极其重要,但我尝试仅将此应用程序用作演示。

任何允许连接到 RDS 数据库的松散配置现在都适合我。

application.properties

spring.datasource.url=jdbc:postgresql://myEndpoint:myPort/myAppName
spring.datasource.username=myDbUsername
spring.datasource.password=myDbPassword
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgresPlusDialect
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.show-sql=true
spring.session.jdbc.initialize-schema=always
spring.session.store-type=jdbc
spring.session.jdbc.table-name=spring_session
server.servlet.session.timeout=30m
Run Code Online (Sandbox Code Playgroud)

我尝试了多种 SG 配置,这里有 2 个示例:


RDS 配置 1

Public accessibility: Yes
VPC Security Groups: launch-wizard-1 (sg-id-1) / Active
Run Code Online (Sandbox Code Playgroud)

sg-id-1

Inbound rules:
rule 1 -- IP version: IPv4, Type: SSH, Protocol: TCP, Port range: MySSHPort, Source: 0.0.0.0/0 …
Run Code Online (Sandbox Code Playgroud)

java postgresql amazon-ec2 amazon-web-services amazon-rds

3
推荐指数
1
解决办法
5893
查看次数