AWS RDS Aurora Serverless 로컬 접속 ( local ) 개발 인스턴스 구성


작업 개요

- Aurora Serverless 의 end point는 내부 end point이기 때문에 로컬에서 접근하기위해서는 우회 방법이 필요하다.

해당 가이드는 haproxy 오픈소스 로드벨런서를 사용해 외부에서 접근 가능하도록 하기 위함이다.

작업 환경 

서비스 : EC2

AMI : Amazon Linux AMI 2018.03.0

보안그룹 : EC2에서 Aurora Serverless에 접근 가능하도록 설정한다. 

또한 EC2에 외부에서 접근 가능 하도록 설정한다.

작업 내용 

haproxy 오픈소스 로드벨런서를 EC2 안에 구성을 하고 로드벨런서에  Aurora Serverless를 연결해 로컬에서 Aurora Serverless에 접속 가능 하도록 한다.



작업 절차 


      1. ec2 생성  

          - test 인스턴스 img :  Amazon Linux AMI 2018.03.0 (HVM), SSD Volume Type


      2. haproxy 구성을 위해 필요 페키지 설치

          - sudo yum -y install haproxy mysql


      3. EC2에서 Aurora Serverless에 접근 가능한지 먼저 확인한다.

          - mysql -h'[end-point]' -u[mysql - user] -p

            ex) mysql -h'test.cluster-cksasdwsxfewefd.ap-northeast-2.rds.amazonaws.com' -uuser -p


      4. haproxy config 파일 수정 -내용을 아래 내용으로 모두 변경한다.

          - sudo vi /etc/haproxy/haproxy.cfg

---------------------------------------------------------------------------------------------------------------------------------

        // 내용

        global


            log         127.0.0.1 local2


            chroot      /var/lib/haproxy

            maxconn     4000

            pidfile     /var/run/haproxy.pid

            user        haproxy

            group       haproxy

            daemon


            stats socket /var/lib/haproxy/stats



        defaults

            log                     global

            option                  tcplog

            option                  dontlognull

            option                  redispatch

            retries                 3

            timeout queue           1m

            timeout connect         10s

            timeout client          1m

            timeout server          1m

            timeout check           10s

            maxconn                 3000


        listen mysql-cluster 0.0.0.0:3306

              mode tcp

              balance roundrobin

              option tcpka

              #server sdm-db1 [aurora serverless end-point]:3306 check

              server sdm-db1 test.cluster-cksasdwsxfewefd.ap-northeast-2.rds.amazonaws.com:3306 check

----------------------------------------------------------------------------------------------------------------------------------------

****listen mysql-cluster 0.0.0.0:3306 에서 입력한 포트를 EC2 보안 그룹에서 외부에서 접속 가능하도록 열어준다.

 만약 여러 RDS를 대상으로 해당 작업을 해야하는 경우 포트만 다르게 여러 연결을 구성하면 된다.


        listen mysql-cluster 0.0.0.0:3306

              mode tcp

              balance roundrobin

              option tcpka

              #server sdm-db1 [aurora serverless end-point]:3306 check

              server sdm-db1 test.cluster-cksasdwsxfewefd.ap-northeast-2.rds.amazonaws.com:3306 check


        listen mysql-cluster 0.0.0.0:3305

              mode tcp

              balance roundrobin

              option tcpka

              #server sdm-db1 [aurora serverless end-point]:3306 check

              server sdm-db1 test.cluster-cksasdwsxfewefd.ap-northeast-2.rds.amazonaws.com:3306 check


      5. haproxy 재시작

          - sudo /etc/init.d/haproxy restart


이상 입니다. ㅎㅎ

그럼 오늘도 행복한 하루 되세요.

+ Recent posts