Amazon RDS 프록시를 사용하여 MySQL을 실행하는 Amazon RDS(Amazon Relational Database Service) DB 인스턴스 또는 Amazon Aurora DB 클러스터에 연결하려면 어떻게 해야 합니까?
간략한 설명
Amazon RDS 프록시를 사용하여 애플리케이션에 대한 연결을 관리할 수 있습니다. RDS 프록시에서 지원하는 엔진에 대한 자세한 내용은 Amazon RDS 프록시와의 연결 관리를 참조하십시오.
해결 방법
시작하기 전에 Amazon RDS 프록시가 데이터베이스와 동일한 VPC에 있어야 합니다. 데이터베이스는 공개적으로 액세스할 수 있지만 프록시는 공개적으로 액세스할 수 없습니다.
1. AWS Secrets Manager에서 데이터베이스 자격 증명을 생성합니다.
참고: 보안 암호를 생성할 때 데이터베이스와 동일한 사용자 이름 및 암호를 사용합니다.
2. AWS Identity and Access Management(IAM) 정책 및 IAM 역할을 생성합니다.
참고: 이 단계는 선택 사항입니다. Amazon RDS 프록시는 3단계에서 자동으로 IAM 역할을 생성할 수 있습니다. 고유한 IAM 역할을 생성하려면 이 단계를 수행하십시오.
3. Amazon RDS 프록시를 생성합니다.
4. 프록시 엔드포인트에 연결할 수 있는지 확인합니다.
nc -zv <proxy_endpoint> 3306
이 명령은 다음과 비슷한 출력을 반환합니다.
nc -z test-proxy.proxy-xxxxxxxxxxxxx.eu-west-1.rds.amazonaws.com 3306
Connection to test-proxy.proxy-xxxxxxxxxxxxx.eu-west-1.rds.amazonaws.com 3306 port [tcp/mysql] succeeded!
참고: 이 명령은 RDS 프록시와 동일한 VPC에 있는 EC2 시스템에서만 실행할 수 있습니다. 이 명령은 로컬 컴퓨터에서 실행되지 않습니다.
5. Amazon RDS 프록시를 사용하여 RDS DB 인스턴스에 연결합니다.
mysql -h <proxy_end_point> -u username -p
이 명령은 다음과 비슷한 출력을 반환합니다.
mysql -h test-proxy.proxy-xxxxxxxxxxxxx.eu-west-1.rds.amazonaws.com -u admin -p
Enter 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 연결과 함께 Amazon RDS 프록시를 사용하여 RDS DB 인스턴스에 연결할 수 있습니다.
1. 선택적으로, Amazon RDS 프록시를 생성할 때 **전송 계층 보안 필요(Require Transport Layer Security)**를 활성화합니다. 기존 RDS 프록시를 수정하여 이 옵션을 활성화할 수도 있습니다.
참고: 파라미터를 **필수(Required)**로 변경하면 연결에 SSL을 사용해야 합니다. 모든 일반 텍스트 연결은 거부됩니다. 이 파라미터를 활성화하지 않으면 Amazon RDS 프록시가 SSL 사용 여부에 관계없이 RDS DB 인스턴스에 연결할 수 있습니다.
2. Amazon Trust Services에서 Amazon Root CA 1 trust store.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을 통해 연결합니다.
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 모드 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 프록시 문제 해결