如何使用 Amazon RDS Proxy 連線到我的 Amazon RDS for MySQL 資料庫執行個體或 Aurora MySQL 相容的資料庫叢集?

2 分的閱讀內容
0

我想使​​用 Amazon Relational Database Service (Amazon RDS) 代理程式連線到 Amazon RDS for MySQL 資料庫執行個體或 Amazon Aurora MySQL 相容版本資料庫叢集。

解決方法

先決條件: 您的 Proxy 必須與資料庫位於同一個虛擬私有雲端 (VPC) 中。您可以讓資料庫公開存取,但 Proxy 無法公開存取。

建立 Proxy 並將其連接到您的資料庫執行個體

請完成下列步驟:

  1. 在 AWS Secrets Manager 中建立資料庫憑證
    注意: 建立密碼時,請使用與資料庫相同的使用者名稱和密碼。

  2. (選用) 建立 AWS Identity and Access Management (IAM) 政策和 IAM 角色
    注意: Amazon RDS Proxy 會自動建立 IAM 角色。但是,您可以建立自己的 IAM 角色。

  3. 建立 Proxy

  4. 執行下列命令,檢查 Proxy 端點是否可存取:

    nc -zv proxy_endpoint 3306

    **注意:**將 proxy_endpoint 替換為您的 Proxy 伺服器的位址。只在與 Proxy 位於同一 VPC 中的 Amazon Elastic Compute Cloud (Amazon EC2) 電腦上執行上述命令。該命令不會在本機電腦上執行。
    輸出範例:

    Connection to test-proxy.proxy-#############.eu-west-1.rds.amazonaws.com 3306 port [tcp/mysql] succeeded
  5. 執行下列命令,以使用 Proxy 連線到 RDS 資料庫執行個體:

    mysql -h proxy_endpoint -u username -p

    **注意:**將 proxy_endpoint 替換為您的 Proxy 伺服器的位址。
    輸出範例:

    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>

(選用) 使用具有 TLS/SSL 連線的 Proxy

請完成下列步驟:

  1. 建立 Proxy 時,請開啟需要傳輸層安全性。您也可以修改現有的 Proxy
    注意: 當您使用 TLS/SSL 通訊協定時,Proxy 會拒絕純文字連線。

  2. 從 Amazon Trust Services 下載 Amazon Root CA 1 信任存放庫 .pem 檔案:

    wget https://www.amazontrust.com/repository/AmazonRootCA1.pem
  3. 執行下列命令,以使用 TLS/SSL 連線到資料庫執行個體

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

    或者,您可以使用 TLS/SSL VERIFY\ _IDENTITY 模式執行下列命令,以連線到資料庫執行個體:

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

    注意: Proxy 使用萬用字元憑證。如果您使用 MySQL 用戶端以 TLS/SSL 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.

相關資訊

RDS Proxy 伺服器疑難排解

Amazon RDS Proxy