简体   繁体   English

使用MySQL Workbench Security组通过EC2实例连接到Amazon RDS实例

[英]Connecting to Amazon RDS instance through EC2 instance using MySQL Workbench Security groups

I'm having difficulty to connect mysql Workbench to RDS. 我很难将mysql Workbench连接到RDS。 I contacted amazon support and they told me this 我联系了亚马逊支持,他们告诉了我

"I've looked at the configuration of the EB environment and the SG's and they're now in good order, the only item left, as I see its not possible to connect to the RDS DB remotely, the SG sg-882213c3 needs to have another rule added to allow connectivity from the computer with the mysql client. Perhaps, allow 0.0.0.0/0 to TCP port 3306 for temporary access or from the source IP of the computer." “我查看了EB环境和SG的配置,它们的状态良好,剩下的唯一项目,因为我认为无法远程连接到RDS DB,SG sg-882213c3需要添加了另一条规则,以允许从计算机与mysql客户端之间的连接。也许允许0.0.0.0/0到TCP端口3306进行临时访问,或从计算机的源IP。

so what I did is this 所以我要做的是

在此处输入图片说明

but the connection still failing 但是连接仍然失败

在此处输入图片说明

the pervious steps are 以前的步骤是

I created new new DB Instances called east-mysql2-instance1. 我创建了新的新数据库实例,称为east-mysql2-instance1。 For east-mysql2-instance1 Security group is set to rds-launch-wizard (sg-882213c3) and i did modify the inbound to Source sg-882213c3 (rds-launch-wizard). 对于east-mysql2-instance1,安全组设置为rds-launch-wizard(sg-882213c3),我确实将入站修改为Source sg-882213c3(rds-launch-wizard)。 but it wont let me change the type to Mysql/Aurora it stays at custom TCP Rule. 但它不会让我将类型更改为Mysql / Aurora,它停留在自定义TCP规则。

for EC2 Instance I have 2 running instances and I changed both Security groups to 对于EC2实例,我有2个正在运行的实例,并且将两个安全组都更改为
rds-launch-wizard and awseb-e-bdbjjgxvzd-stack-AWSEBSecurity rds-launch向导和awseb-e-bdbjjgxvzd-stack-AWSEBSecurity

I terminate my old environment and created new one called Borroup-env-1, I changed the EC2 security groups for the environment to awseb-e-bdbjjgxvzd-stack-AWSEBSecurityGroup-1PTJG896MEOYR and rds-launch-wizard. 我终止了旧环境,并创建了一个名为Borroup-env-1的新环境,将环境的EC2安全组更改为awseb-e-bdbjjgxvzd-stack-AWSEBSecurityGroup-1PTJG896MEOYR和rds-launch-wizard。 I changed Environment properties and added RDS_DB_NAME, RDS_HOSTNAME, RDS_PASSWORD, RDS_PORT, RDS_USERNAME 我更改了环境属性,并添加了RDS_DB_NAME,RDS_HOSTNAME,RDS_PASSWORD,RDS_PORT,RDS_USERNAME

It sounds like you wish to connect from an Amazon EC2 instance to an Amazon RDS instance. 听起来您好像希望从Amazon EC2实例连接到Amazon RDS实例。 Assuming that they are both in the same VPC , the easiest way to configure it is: 假设它们都在同一个VPC中 ,最简单的配置方法是:

  • Create an App-SG security group and associate it with the EC2 instance . 创建一个App-SG安全组并将其与EC2实例相关联。 Grant whatever access you need to login/use the instance. 授予您登录/使用实例所需的任何访问权限。
  • Create a RDS-SG security group and associate it with the RDS database. 创建一个RDS-SG安全组并将其与RDS数据库关联。 Permit inbound access from the App-SG security group on port 3306 (MySQL/Aurora). 允许来自App-SG安全组在端口3306(MySQL / Aurora)上的入站访问。

This basically says that any resources associated with App-SG will be permitted to access any resource associated with RDS-SG . 这基本上说,将允许与App-SG关联的任何资源访问与RDS-SG关联的任何资源。

If that doesn't work, then there's something else (aside from security groups) that needs to be configured. 如果这不起作用,则除了安全组外,还需要配置其他功能。

From your second screenshot, it looks like you are setting up a connection that is: 从第二个屏幕快照中,您似乎正在建立一个连接:

  1. SSH from your mac desktop to an ec2 instance 从Mac桌面到ec2实例的SSH
  2. connect form the ec2 instance to RDS 将ec2实例连接到RDS

If this is the situation you are wanting to achieve I would not be leaving a rule allowing 3306 from 0.0.0.0/0. 如果这是您要实现的情况,我不会留下允许从0.0.0.0/0到3306的规则。 This is allowing any IP address in the world to connect on port 3306 - a well known port. 这允许世界上任何IP地址都通过端口3306(众所周知的端口)进行连接。 Additionally, that advice seems to suggest putting that rule against the RDS instance? 另外,该建议似乎建议针对RDS实例设置该规则? Overkill - only needs to allow access from your EC2 instance or its subnet. 过度杀伤力-仅需要允许从您的EC2实例或其子网进行访问。

The first step I would take is use SSH on terminal to verify you can SSH from your mac to the EC2 instance - if this is not working, no point looking at SGs and rules between EC2 and RDS. 我要采取的第一步是在终端上使用SSH来验证您可以将SSH从Mac传输到EC2实例-如果此操作不起作用,则无需考虑SG和EC2与RDS之间的规则。 Once that is working, you can move forward to resolving the connectivity from the ec2 to the RDS. 一旦工作,您就可以继续解决从ec2到RDS的连接。 As John noted above, if both the RDS and the EC2 are in the same VPC, you can setup a SG allowing access to the RDS instance from the subnet that the EC2 is in. 如约翰在上文所述,如果RDS和EC2都在同一VPC中,则可以设置SG,以允许从EC2所在的子网访问RDS实例。

As an alternative solution, you can also setup to allow access to the RDS instance directly, without going through the EC2. 作为替代解决方案,您还可以设置为允许直接访问RDS实例,而无需通过EC2。 See Public Accessibility and also subnet requirements here: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_VPC.WorkingWithRDSInstanceinaVPC.html Depends on what kind of setup you want... 请参阅此处的公共可访问性以及子网要求: https : //docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_VPC.WorkingWithRDSInstanceinaVPC.html取决于所需的设置...

If the EC2 and RDS are not in the same VPC but are in the same region, you may want to look at setting up VPC peering: https://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/vpc-peering.html If they EC2 are RDS are not in the same region or same VPC, you may want to setup Inter region VPC peering: https://aws.amazon.com/about-aws/whats-new/2017/11/announcing-support-for-inter-region-vpc-peering/ 如果EC2和RDS不在同一VPC中,但在同一区域中,则您可能需要考虑设置VPC对等: https : //docs.aws.amazon.com/AmazonVPC/latest/UserGuide/vpc-peering .html如果它们的EC2和RDS不在同一区域或同一VPC中,则您可能希望设置区域间VPC对等: https : //aws.amazon.com/about-aws/whats-new/2017/11/anonuncing支持区域间vpc对等/

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

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