简体   繁体   English

无法使用 PgAdmin 连接到 Amazon Aurora

[英]Unable to connect to Amazon Aurora with PgAdmin

I created an Amazon Aurora Postgres DB on my AWS account, and am now trying to connect to it using PgAdmin.我在我的 AWS 账户上创建了一个 Amazon Aurora Postgres 数据库,现在正在尝试使用 PgAdmin 连接到它。 I enter in the db name, username, password, and host, and port.我输入数据库名称、用户名、密码、主机和端口。 When I try to connect I get this issue.当我尝试连接时,我遇到了这个问题。

Unable to connect to server:

could not connect to server: Operation timed out
Is the server running on host "host_name.us-east-2.rds.amazonaws.com" (IP Address) and accepting
TCP/IP connections on port 5432?

I'm new to Amazon Aurora, and am not sure what my next step has to be to connect.我是 Amazon Aurora 的新手,不确定下一步要连接的内容。 I read the documentation, but can't find what I'm looking for.我阅读了文档,但找不到我要找的东西。 I'm also getting the same error when I try to connect to it with my production server that houses my Django application.当我尝试使用包含我的 Django 应用程序的生产服务器连接到它时,我也遇到了同样的错误。

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'dbname',
        'USER': 'username',
        'PASSWORD': 'password',
        'HOST': 'hostname.us-east-2.rds.amazonaws.com',
        'PORT': '5432'
    }
}

And I'm getting a similar issue我也遇到了类似的问题

django.db.utils.OperationalError: could not connect to server: Connection timed out
        Is the server running on host "hostname.us-east-2.rds.amazonaws.com" (IP Address) and accepting
        TCP/IP connections on port 5432?

您应该将要尝试从EC2中的“安全组”下连接的IP添加到RDS的安全组中,作为传入的mysql连接

I posted this answer to a similar question about PostgreSQL here, and thought this may be helpful even with Aurora: django cannot connect to RDS postgresql 我在这里发布了有关PostgreSQL的类似问题的答案,并认为即使使用Aurora,这也可能有所帮助: django无法连接到RDS postgresql

When you're trying to use an existing RDS database with Django on EC2 or EB, you'll have to adjust the security groups, and then get the proper parameters and set them as environment variables (RDS_*) 当您尝试在EC2或EB上将现有RDS数据库与Django一起使用时,必须调整安全组,然后获取适当的参数并将其设置为环境变量(RDS_ *)

1) Create RDS, and match these up: 1)创建RDS,并进行匹配:

Environment variables - RDS console label

RDS_HOSTNAME - Endpoint (this is the hostname)
RDS_PORT - Port
RDS_DB_NAME –  DB Name
RDS_USERNAME –  Username
RDS_PASSWORD – Password you set for your DB

2) Set those using, for example, eb setenv 2)使用eb setenv设置那些

3) Go to your EC2/ EB instance and get the security group for that eg awseb-z-afsafdsaf-stack-AWSEBSecurityGroup-asfdsadfasdf and for the load balancer: awseb-e-adsfadsf-stack-AWSEBLoadBalancerSecurityGroup-asdfadsf 3)转到您的EC2 / EB实例,并获取该安全组,例如awseb-z-afsafdsaf-stack-AWSEBSecurityGroup-asfdsadfasdf和负载均衡器: awseb-e-adsfadsf-stack-AWSEBLoadBalancerSecurityGroup-asdfadsf

4) Go to the panel for your RDS instance, scroll down to Security Groups and take note of which security group it has. 4)转到RDS实例的面板,向下滚动到“安全组”,并记下它具有的安全组。 eg rds-launch-wizard-1 (ab-sdjfalkajsdf39) 例如rds-launch-wizard-1 (ab-sdjfalkajsdf39)

5) Click modify for the RDS instance, and in the Security Groups setting in the middle, add the load balancer security group you found above. 5)单击修改RDS实例,然后在中间的“安全组”设置中,添加您在上面找到的负载均衡器安全组。 It should have suggestions. 它应该有建议。

6) Go to the EC2 Dashboard and choose security groups from the menu on the left. 6)转到EC2仪表板,然后从左侧菜单中选择安全组。

7) Select the load balancer security group, and add an Outbound rule. 7)选择负载均衡器安全组,然后添加出站规则。 Type should be your RDS type (PostgreSQL) and the destination should be custom & the RDS instance's security group. Type应该是您的RDS类型(PostgreSQL),目的地应该是custom和RDS实例的安全组。 Save. 救。

8) Do the same for Inbound, use the same RDS type & Destination 8)对入站执行相同的操作,使用相同的RDS类型和目标

9) Select the RDS security group, and add an Inbound rule, similar to 8, but using the EC2 or EB instance that you got in step 2. 9)选择RDS安全组,并添加一个入站规则,类似于8,但使用在步骤2中获得的EC2或EB实例。

10) Save, you're done. 10)保存,就完成了。 They should be able to work together now. 他们现在应该能够一起工作。

I'm not 100% certain all these steps are necessary, one or two might not be, but this got the job done for me. 我不是100%肯定所有这些步骤都是必要的,可能不需要一两个步骤,但这为我完成了工作。

One thing to keep in mind with aws RDS is that if you using capacity type(mean role) as the serverless type which means AWS RDS will manage to compute the capacity of the DB instance to match your application's usage. aws RDS 要记住的一件事是,如果您使用容量类型(平均角色)作为无服务器类型,这意味着 AWS RDS 将设法计算数据库实例的容量以匹配您的应用程序的使用情况。 There will be other things also in serverless.无服务器中还会有其他东西。 And this makes your server not public accessible(same as ElasticCache) but can connect using Data API or put your EC2 instance/lambda function inside the same VPC in which this database lies.这使您的服务器不可公开访问(与 ElasticCache 相同),但可以使用数据 API 进行连接或将您的 EC2 实例/lambda 函数放在该数据库所在的同一 VPC 中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM