我如何使用 Amazon RDS 代理连接到我的 Amazon RDS for MySQL 数据库实例或 Aurora MySQL 兼容的数据库集群?

2 分钟阅读
0

我想使用 Amazon RDS 代理连接到我的 Amazon Relational Database Service(Amazon RDS)for MySQL 数据库实例。我也想使用 Amazon RDS 代理连接到 Amazon Aurora MySQL 兼容版数据库集群。

解决方法

在开始之前,您的 Amazon RDS 代理必须与数据库位于同一个虚拟私有云(VPC)中。您可以将数据库设置为可公开访问,但不能公开访问代理。

1.    在 AWS Secrets Manager 中创建数据库凭证
**注意:**创建密钥时,请使用与数据库相同的用户名和密码。

2.    (可选)创建一个 AWS Identity and Access Management(IAM)策略和一个 IAM 角色
**注意:**Amazon RDS 代理在步骤 3 中自动创建 IAM 角色。按照步骤 2 创建您自己的 IAM 角色。

3.    创建 Amazon RDS 代理

4.    要检查是否可访问代理端点,请运行以下命令:

nc -zv <proxy_endpoint> 3306

输出示例:

nc -z test-proxy.proxy-xxxxxxxxxxxxx.eu-west-1.rds.amazonaws.com 3306Connection to test-proxy.proxy-xxxxxxxxxxxxx.eu-west-1.rds.amazonaws.com 3306 port [tcp/mysql] succeeded!

**注意:**仅在与 Amazon RDS 代理位于同一 VPC 中的 Amazon Elastic Compute Cloud(Amazon EC2)计算机上运行上述命令。该命令不在本地计算机上运行。

5.    要使用 Amazon RDS 代理连接到 RDS 数据库实例,请运行以下命令:

mysql -h <proxy_end_point> -u username -p

输出示例:

mysql -h test-proxy.proxy-xxxxxxxxxxxxx.eu-west-1.rds.amazonaws.com -u admin -pEnter password: Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2946664484
Server version: 5.7.28-log
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>

也可以使用带 SSL/TLS 连接的 Amazon RDS 代理连接到数据库实例:

1.    (可选)创建 Amazon RDS 代理时,请启用需要传输层安全。您也可以修改现有的 Amazon RDS 代理
注意:将参数更改为必需时,连接必须使用 SSL/TLS。Amazon RDS 代理拒绝纯文本连接。如果您不更改参数,无论是否使用 SSL/TLS,Amazon RDS 代理都可以连接到数据库实例。

2.    从 Amazon Trust Services 下载 Amazon 根 CA 证书 1 信任存储 .pem 文件:

wget https://www.amazontrust.com/repository/AmazonRootCA1.pem

3.    使用 SSL 连接到数据库实例:

mysql -h test-proxy.proxy-xxxxxxxxxxxxx.eu-west-1.rds.amazonaws.com -u admin --ssl-mode=REQUIRED --ssl-ca=AmazonRootCA1.pem -p

您也可以运行以下命令使用 SSL/TLS 连接到数据库实例:

mysql -h test-proxy.proxy-xxxxxxxxxxxxx.eu-west-1.rds.amazonaws.com -u admin --ssl-mode=VERIFY_IDENTITY --ssl-ca=AmazonRootCA1.pem -p

**注意:**Amazon RDS 代理使用通配符证书。如果使用 MySQL 客户端连接 SSL/TLS VERIFY\ _IDENTITY 模式,则必须使用兼容 MySQL 8.0 的 mysql 命令。

连接后,数据库实例将返回以下输出:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12659040
Server version: 5.7.28-log
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

相关信息

Amazon RDS 代理故障排除

使用 Amazon RDS 代理

AWS 官方
AWS 官方已更新 7 个月前