Bastion Host ์ฌ์ฉํ์ฌ RDS ์ ์ํ๊ธฐ
2023-09-25
๐งถ #BastionHost #RDS
Bastion Host ๋ก ๊ตฌ์ฑ๋ EC2์์ mysql ์ฌ์ฉ
์ ์ฉ ๋ฐฐ๊ฒฝ
- dev ํ๊ฒฝ์์ stg ํ๊ฒฝ์ผ๋ก RDS table์ ์ด๊ดํ๊ธฐ ์ํด์ mysql dump ๊ธฐ๋ฅ ์ฌ์ฉ
- AWS Bastion Host ๊ตฌ์ฑ ๋ฐ RDS ๊ตฌ์ฑ์ด ์๋ฃ๋์ด์๋ ์ํฉ์ ์ ์ ๋ก ์์ฑ๋จ
- window10 ํ๊ฒฝ์์ wsl ์ค์น ํ awscli ์ฌ์ฉํ์ฌ ๋ช ๋ น์ด ์คํ
1. .pem file ์ค๋น
- window ํ๊ฒฝ์์ MySQL Workbench ์ฌ์ฉ์ ์ํด ๋ก์ปฌ์
.pemํ์ผ์ ์ ์ฅํด๋์๋ค. - wsl์์ ์๋์ฐ์ ์ ์ฅ๋ ํ์ผ๊ฐ์ ๊ฒฝ์ฐ
/mnt๋๋ ํ ๋ฆฌ ํ์์์ ์กฐํ ๊ฐ๋ฅํ์ง๋ง ๋์ค์ ์ ์ํ๋ ค๊ณ ๋ช ๋ น์ด ๋ ๋ฆฌ๋ฉด Permission ์๋ฌ๊ฐ ๋ฐ์ํ๋ค. - ๋ฐ๋ผ์ wsl์์ ๋ฐ๋ก ์ฝ์ ์ ์๋ ์์น๋ก ํ์ผ copyํด๋๋ค โถ ๋์ค์ ~/.ssh ์์น์ config ํ์ผ ๋ง๋ค๊ฑฐ๋ผ์ ๊ฐ์ ์์น๋ก ๋ณต์ฌํ ๋ค ๊ถํ ์ฒ๋ฆฌ ํด๋์์.
1m3rri@hostname:/$ cp "/mnt/h/์๋ ์์น/key.pem" ~/.ssh/ 2m3rri@hostname:/$ sudo chmod 400 ~/.ssh/key.pem
2. aws ssm ์ค์น
1m3rri@hostname:/$ curl "https://s3.amazonaws.com/session-manager-downloads/plugin/latest/ubuntu_64bit/session-manager-plugin.deb" -o "session-manager-plugin.deb" 2m3rri@hostname:/$ sudo dpkg -i session-manager-plugin.deb 3m3rri@hostname:/$ session-manager-plugin 4 5The Session Manager plugin was installed successfully. Use the AWS CLI to start a session. 6 7m3rri@hostname:/$
3. config ์์ฑ
1m3rri@hostname:/$ sudo vim config 2 3host i-* mi-* 4 ProxyCommand sh -c "aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters 'portNumber=%p'" 5 User ec2-user 6 IdentityFile ./key.pem
- ec2-user : Bastion Host ํ๊ฒฝ์ EC2 user name์ ๊ผญ ec2-user๊ฐ ์๋ ์ ์์
4. ssh ์คํ
- EC2 console์์ ์ธ์คํด์ค ID ํ์ธ ํ์
1m3rri@hostname:/$ ssh i-***************** 2The authenticity of host 'i-***************** (<no hostip for proxy command>)' can't be established. 3ED25519 key fingerprint is SHA256:*****************/*****************. 4This host key is known by the following other names/addresses: 5 ~/.ssh/known_hosts:1: [hashed name] 6Are you sure you want to continue connecting (yes/no/[fingerprint])? yes 7Warning: Permanently added 'i-*****************' (ED25519) to the list of known hosts. 8Last login: Mon Sep 25 01:31:20 2023 from 61.74.175.54 9 10 __| __|_ ) 11 _| ( / Amazon Linux 2 AMI 12 ___|\___|___| 13 14https://aws.amazon.com/amazon-linux-2/ 1523 package(s) needed for security, out of 49 available 16Run "sudo yum update" to apply all updates.
5. mysql ์คํ
1[ec2-user@ip-172-00-0-000 ~]$ mysql -u[username] -h[mysql host name] -P3306 -p[password] 2Welcome to the MariaDB monitor. Commands end with ; or \g. 3Your MySQL connection id is 426485 4Server version: 8.0.26 Source distribution 5 6Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. 7 8Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 9 10MySQL [(none)]> use testdb; 11Reading table information for completion of table and column names 12You can turn off this feature to get a quicker startup with -A 13 14Database changed 15MySQL [testdb]> select * from user_info;
- mysql ๋ช
๋ น์ด ์คํ ์
-u,-h,-p๋ฑ์ ์ต์ ๋ค์ ๊ณต๋ฐฑ์ด ์์ด์ผํจ!(-P3306์ฐธ์กฐ)
์ฐธ์กฐ
musma - [์ค์ต] SSH์ฒ๋ผ ์์ฅํ๊ธฐ + ํฌํธ ํฌ์๋ฉ (๊ณ ๊ธ)
/end of Bastion Host ์ฌ์ฉํ์ฌ RDS ์ ์ํ๊ธฐ
CONTENT LISTMERRI๏ผs DEVELOG
2024-11-19
2023-02-21