简体   繁体   English

AWS:无法从我的机器连接到 RDS 数据库

[英]AWS: can't connect to RDS database from my machine

The EC2 instance/live web can connect just fine to the RDS database. EC2 instance/live web 可以很好地连接到 RDS 数据库。 But when I want to debug the code in my local machine, I can't connect to the database and got this error:但是当我想在我的本地机器上调试代码时,我无法连接到数据库并得到这个错误:

OperationalError: (2003, "Can't connect to MySQL server on 'aa9jliuygesv4w.c03i1 ck3o0us.us-east-1.rds.amazonaws.com' (10060)") OperationalError:(2003,“无法连接到'aa9jliuygesv4w.c03i1 ck3o0us.us-east-1.rds.amazonaws.com'(10060)上的MySQL服务器”)

I've added .pem and .ppk keys to .ssh and I already configure EB CLI.我已将.pem.ppk密钥添加到.ssh并且我已经配置了 EB CLI。 I don't know what should I do anymore.我不知道我该怎么办了。

FYI: The app is in Django仅供参考:该应用程序位于 Django

The EC2 instance/live web can connect just fine to the RDS database. EC2 实例/实时 Web 可以很好地连接到 RDS 数据库。 But when I want to debug the code in my local machine, I can't connect to the database and got this error:但是当我想在我的本地机器上调试代码时,我无法连接到数据库并得到这个错误:

OperationalError: (2003, "Can't connect to MySQL server on 'aa9jliuygesv4w.c03i1 ck3o0us.us-east-1.rds.amazonaws.com' (10060)") OperationalError: (2003, “无法连接到 MySQL 服务器上的 'aa9jliuygesv4w.c03i1 ck3o0us.us-east-1.rds.amazonaws.com' (10060)”)

I've added .pem and .ppk keys to .ssh and I already configure EB CLI.我已将.pem.ppk密钥添加到.ssh并且我已经配置了 EB CLI。 I don't know what should I do anymore.我不知道我该怎么办了。

FYI: The app is in Django仅供参考:该应用程序在 Django 中

The EC2 instance/live web can connect just fine to the RDS database. EC2 实例/实时 Web 可以很好地连接到 RDS 数据库。 But when I want to debug the code in my local machine, I can't connect to the database and got this error:但是当我想在我的本地机器上调试代码时,我无法连接到数据库并得到这个错误:

OperationalError: (2003, "Can't connect to MySQL server on 'aa9jliuygesv4w.c03i1 ck3o0us.us-east-1.rds.amazonaws.com' (10060)") OperationalError: (2003, “无法连接到 MySQL 服务器上的 'aa9jliuygesv4w.c03i1 ck3o0us.us-east-1.rds.amazonaws.com' (10060)”)

I've added .pem and .ppk keys to .ssh and I already configure EB CLI.我已将.pem.ppk密钥添加到.ssh并且我已经配置了 EB CLI。 I don't know what should I do anymore.我不知道我该怎么办了。

FYI: The app is in Django仅供参考:该应用程序在 Django 中

The EC2 instance/live web can connect just fine to the RDS database. EC2 实例/实时 Web 可以很好地连接到 RDS 数据库。 But when I want to debug the code in my local machine, I can't connect to the database and got this error:但是当我想在我的本地机器上调试代码时,我无法连接到数据库并得到这个错误:

OperationalError: (2003, "Can't connect to MySQL server on 'aa9jliuygesv4w.c03i1 ck3o0us.us-east-1.rds.amazonaws.com' (10060)") OperationalError: (2003, “无法连接到 MySQL 服务器上的 'aa9jliuygesv4w.c03i1 ck3o0us.us-east-1.rds.amazonaws.com' (10060)”)

I've added .pem and .ppk keys to .ssh and I already configure EB CLI.我已将.pem.ppk密钥添加到.ssh并且我已经配置了 EB CLI。 I don't know what should I do anymore.我不知道我该怎么办了。

FYI: The app is in Django仅供参考:该应用程序在 Django 中

The EC2 instance/live web can connect just fine to the RDS database. EC2 实例/实时 Web 可以很好地连接到 RDS 数据库。 But when I want to debug the code in my local machine, I can't connect to the database and got this error:但是当我想在我的本地机器上调试代码时,我无法连接到数据库并得到这个错误:

OperationalError: (2003, "Can't connect to MySQL server on 'aa9jliuygesv4w.c03i1 ck3o0us.us-east-1.rds.amazonaws.com' (10060)") OperationalError: (2003, “无法连接到 MySQL 服务器上的 'aa9jliuygesv4w.c03i1 ck3o0us.us-east-1.rds.amazonaws.com' (10060)”)

I've added .pem and .ppk keys to .ssh and I already configure EB CLI.我已将.pem.ppk密钥添加到.ssh并且我已经配置了 EB CLI。 I don't know what should I do anymore.我不知道我该怎么办了。

FYI: The app is in Django仅供参考:该应用程序在 Django 中

The EC2 instance/live web can connect just fine to the RDS database. EC2 实例/实时 Web 可以很好地连接到 RDS 数据库。 But when I want to debug the code in my local machine, I can't connect to the database and got this error:但是当我想在我的本地机器上调试代码时,我无法连接到数据库并得到这个错误:

OperationalError: (2003, "Can't connect to MySQL server on 'aa9jliuygesv4w.c03i1 ck3o0us.us-east-1.rds.amazonaws.com' (10060)") OperationalError: (2003, “无法连接到 MySQL 服务器上的 'aa9jliuygesv4w.c03i1 ck3o0us.us-east-1.rds.amazonaws.com' (10060)”)

I've added .pem and .ppk keys to .ssh and I already configure EB CLI.我已将.pem.ppk密钥添加到.ssh并且我已经配置了 EB CLI。 I don't know what should I do anymore.我不知道我该怎么办了。

FYI: The app is in Django仅供参考:该应用程序在 Django 中

The EC2 instance/live web can connect just fine to the RDS database. EC2 实例/实时 Web 可以很好地连接到 RDS 数据库。 But when I want to debug the code in my local machine, I can't connect to the database and got this error:但是当我想在我的本地机器上调试代码时,我无法连接到数据库并得到这个错误:

OperationalError: (2003, "Can't connect to MySQL server on 'aa9jliuygesv4w.c03i1 ck3o0us.us-east-1.rds.amazonaws.com' (10060)") OperationalError: (2003, “无法连接到 MySQL 服务器上的 'aa9jliuygesv4w.c03i1 ck3o0us.us-east-1.rds.amazonaws.com' (10060)”)

I've added .pem and .ppk keys to .ssh and I already configure EB CLI.我已将.pem.ppk密钥添加到.ssh并且我已经配置了 EB CLI。 I don't know what should I do anymore.我不知道我该怎么办了。

FYI: The app is in Django仅供参考:该应用程序在 Django 中

The EC2 instance/live web can connect just fine to the RDS database. EC2 实例/实时 Web 可以很好地连接到 RDS 数据库。 But when I want to debug the code in my local machine, I can't connect to the database and got this error:但是当我想在我的本地机器上调试代码时,我无法连接到数据库并得到这个错误:

OperationalError: (2003, "Can't connect to MySQL server on 'aa9jliuygesv4w.c03i1 ck3o0us.us-east-1.rds.amazonaws.com' (10060)") OperationalError: (2003, “无法连接到 MySQL 服务器上的 'aa9jliuygesv4w.c03i1 ck3o0us.us-east-1.rds.amazonaws.com' (10060)”)

I've added .pem and .ppk keys to .ssh and I already configure EB CLI.我已将.pem.ppk密钥添加到.ssh并且我已经配置了 EB CLI。 I don't know what should I do anymore.我不知道我该怎么办了。

FYI: The app is in Django仅供参考:该应用程序在 Django 中

The EC2 instance/live web can connect just fine to the RDS database. EC2 实例/实时 Web 可以很好地连接到 RDS 数据库。 But when I want to debug the code in my local machine, I can't connect to the database and got this error:但是当我想在我的本地机器上调试代码时,我无法连接到数据库并得到这个错误:

OperationalError: (2003, "Can't connect to MySQL server on 'aa9jliuygesv4w.c03i1 ck3o0us.us-east-1.rds.amazonaws.com' (10060)") OperationalError: (2003, “无法连接到 MySQL 服务器上的 'aa9jliuygesv4w.c03i1 ck3o0us.us-east-1.rds.amazonaws.com' (10060)”)

I've added .pem and .ppk keys to .ssh and I already configure EB CLI.我已将.pem.ppk密钥添加到.ssh并且我已经配置了 EB CLI。 I don't know what should I do anymore.我不知道我该怎么办了。

FYI: The app is in Django仅供参考:该应用程序在 Django 中

The EC2 instance/live web can connect just fine to the RDS database. EC2 实例/实时 Web 可以很好地连接到 RDS 数据库。 But when I want to debug the code in my local machine, I can't connect to the database and got this error:但是当我想在我的本地机器上调试代码时,我无法连接到数据库并得到这个错误:

OperationalError: (2003, "Can't connect to MySQL server on 'aa9jliuygesv4w.c03i1 ck3o0us.us-east-1.rds.amazonaws.com' (10060)") OperationalError: (2003, “无法连接到 MySQL 服务器上的 'aa9jliuygesv4w.c03i1 ck3o0us.us-east-1.rds.amazonaws.com' (10060)”)

I've added .pem and .ppk keys to .ssh and I already configure EB CLI.我已将.pem.ppk密钥添加到.ssh并且我已经配置了 EB CLI。 I don't know what should I do anymore.我不知道我该怎么办了。

FYI: The app is in Django仅供参考:该应用程序在 Django 中

In case you've tried all answers above try this... Recreate the database....如果您已经尝试了上述所有答案,请尝试此操作...重新创建数据库....

AWS on database creation provides an option to allow public/private access access AWS 在数据库创建方面提供了一个允许公共/私有访问访问的选项

在此处输入图片说明

The ideal debugging checklist is:理想的调试清单是:

  • Instance's "Publicly Accessible" property should be enabled应启用实例的“可公开访问”属性
  • The security group attached to the instance should have open inbound rules (as open as you'd want)附加到实例的安全组应该具有开放的入站规则(如您所愿开放)
  • The funny part is still if you're not able to access it - then the problem surely is with your instance lying in a private subnet of the respective VPC.有趣的是,如果您无法访问它 - 那么问题肯定出在您的实例位于相应 VPC 的私有子网中。

However, there're more secure ways to access your RDS instance.但是,有更安全的方式来访问您的 RDS 实例。 The best bet would be not make it publicly accessible, lock down security groups and have a P2P relay endpoint (think Tailscale).最好的选择是不公开访问,锁定安全组并拥有 P2P 中继端点(想想 Tailscale)。

I'm sure it's not the proper answer but I added the inte.net gateway to all my private su.net route tables.. Even though the private su.nets and the public su.nets are in the su.netgroup.我确定这不是正确的答案,但我将 inte.net 网关添加到我所有的私有 su.net 路由表中。即使私有 su.net 和公共 su.net 在 su.net 组中。

I know much time has passed since this question was originally asked, but for me none of the above worked.我知道自从最初提出这个问题以来已经过去了很多时间,但对我来说以上都没有用。

What did work was creating a peering connection between my default VPC and the VPC in which the database was created, as it appears that when connecting to resources in AWS, it automatically goes through the default VPC.起作用的是在我的默认 VPC 和创建数据库的 VPC 之间创建对等连接,因为看起来当连接到 AWS 中的资源时,它会自动通过默认 VPC。

enter image description here在此处输入图像描述

Then, set up routing using the peering connection between the 2 VPCs.然后,使用 2 个 VPC 之间的对等连接设置路由。 Also, make sure that your security groups permits postgres ports from your default VPC CIDR block as well.此外,请确保您的安全组也允许来自默认 VPC CIDR 块的 postgres 端口。 And finally, make sure all the su.nets are associated with your route table accessing this peering connection.最后,确保所有 su.net 都与访问此对等连接的路由表相关联。

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

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