AWS

AWS : 3 Tier [WEB & ALB ์ƒ์„ฑ]

NENGIN 2024. 11. 23. 23:16

 

์ด์ „ ๊ธ€์—์„œ ์ด์–ด์ง‘๋‹ˆ๋‹ค

 

AWS : 3 Tier [์ดˆ๊ธฐ ์„ค์ • ๋ฐ ์ž‘์—…]

์ฐธ์กฐ๋งํฌ 0๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜๋Š” AWS ๊ณต๋ถ€ - 3 Tier ๊ตฌ์ถ• 1ํŽธ - ๊ตฌ์ถ• ๊ณ„ํš & VPC & Bastion HostAWS 3 Tier ๊ตฌ์ถ•ํ•˜๊ธฐ 1ํŽธ - ๊ตฌ์ถ• ๊ณ„ํš / ๋„คํŠธ์›Œํฌ ๊ตฌ์ถ• / Bastion Host ๊ตฌ์ถ•velog.io  1. ๊ตฌ์„ฑ๋„  2. vpc ๋ฐ ์„œ๋ธŒ๋„ท ์„ค์ •์„œ๋ธŒ๋„ท`

nenjin.tistory.com

 

 

 

 

 

5. WEB

5-1 ๋ณด์•ˆ๊ทธ๋ฃน ์ƒ์„ฑ

์ธ๋ฐ”์šด๋“œ ๊ทœ์น™ SSH๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ  Bastion-group์—๋งŒ ์ง€์ •ํ•œ๋‹ค

์˜ค์ง Bastion host๋งŒ WEB์„œ๋ฒ„ ๋‚ด๋ถ€์— ์ ‘๊ทผํ•˜๊ธฐ ์œ„ํ•œ ์„ค์ •์ด๋‹ค

 

5-2 Bastion ๋ณด์•ˆ๊ทธ๋ฃน ์•„์›ƒ๋ฐ”์šด๋“œ ์ถ”๊ฐ€

SSH WEB๋ณด์•ˆ๊ทธ๋ฃน์„ ์ถ”๊ฐ€ํ•œ๋‹ค

 

5-3 ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ

WEB ์ธ์Šคํ„ด์Šค ์‚ฌ์–‘์— ๋งž๋„๋ก ์ƒ์„ฑํ•˜๊ณ  WEB01๊ณผ WEB02์„œ๋ธŒ๋„ท์„ ์ง€์ •ํ•œ๋‹ค

 

5-4 SSH ์ ‘์†

window์— ์žˆ๋Š” ํŒŒ์ผ์„ Bastion host์˜ ๋””๋ ‰ํ„ฐ๋ฆฌ์— ๋Œ์–ด๋†“๋Š”๋‹ค 

[ec2-user@ip-10-0-118-11 ~]$ ls
real_mj.pem
[ec2-user@ip-10-0-118-11 ~]$ chmod 600 real_mj.pem
[ec2-user@ip-10-0-118-11 ~]$ ssh -i real_mj.pem ec2-user@10.0.118.37

pemํŒŒ์ผ ๊ถŒํ•œ์„ค์ • ํ›„ ๋ชจ๋“  WEB์„œ๋ฒ„์— ์ ‘์† ํ…Œ์ŠคํŠธ๋ฅผ ํ•œ๋‹ค

 

 

6. ALB

6-1 ๋ณด์•ˆ๊ทธ๋ฃน ์ƒ์„ฑ

80๋ฒˆ์„ ์ง€์ •ํ•˜๊ณ  ์ธ๋ฐ”์šด๋“œ๋Š” ์™ธ๋ถ€์—์„œ ์‚ฌ์šฉ์ž๋“ค์ด ์ ‘์†ํ•˜๋ฏ€๋กœ ๋ชจ๋“  IP์— ๋Œ€ํ•œ ์ ‘๊ทผ์„ ํ—ˆ์šฉํ•œ๋‹ค

์•„์›ƒ๋ฐ”์šด๋“œ๋Š” WEB๋…ธ๋“œ๋กœ ํŠธ๋ž˜ํ”ฝ์„ ์ „๋‹ฌํ•˜๊ธฐ ์œ„ํ•ด WEB ๋ณด์•ˆ๊ทธ๋ฃน๋งŒ ์ง€์ •ํ•œ๋‹ค

WEB ๋ณด์•ˆ๊ทธ๋ฃน์˜ ์ธ๋ฐ”์šด๋“œ ๊ทœ์น™์„ ์ˆ˜์ •ํ•œ๋‹ค

80๋ฒˆ์„ ์ถ”๊ฐ€ํ•˜๊ณ  ALB ๋ณด์•ˆ๊ทธ๋ฃน์„ ์ง€์ •ํ•œ๋‹ค

 

6-2 ๋Œ€์ƒ๊ทธ๋ฃน ์ƒ์„ฑ

์ƒํƒœ ๊ฒ€์‚ฌ ๊ฒฝ๋กœ๋ฅผ /index.html๋กœ ์„ค์ •ํ•˜๋Š” ๊ฒƒ์€ WEB ์„œ๋ฒ„์— HTTP ํ”„๋กœํ† ์ฝœ๋กœ ์ง€์ •ํ•œ ๊ฒฝ๋กœ์— ์ ‘๊ทผํ–ˆ์„ ๋•Œ,

ํŽ˜์ด์ง€ ์ฝ”๋“œ๊ฐ€ ์ž˜ ์ถœ๋ ฅ๋˜๋Š”์ง€์™€ ์ƒํƒœ ์ฝ”๋“œ๊ฐ€ 200๋ฒˆ๋Œ€์ธ์ง€๋กœ ์ƒํƒœ ๊ฒ€์‚ฌ๋ฅผ ํ•˜๋Š” ๊ฒƒ์ด๋‹ค

๊ทธ๋ฃน์— ํฌํ•จํ•  ์ธ์Šคํ„ด์Šค๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค

 

6-3 L/B ์ƒ์„ฑ

ALB๋ฅผ ์„ ํƒํ•œ๋‹ค

 

์ธํ„ฐ๋„ท ํŠธ๋ž˜ํ”ฝ์„ ๋ฐ›์•„์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— public ์„œ๋ธŒ๋„ท์„ ์ง€์ •ํ•œ๋‹ค

์ƒ์„ฑ ์™„๋ฃŒ

 

์ง€๊ธˆ๊นŒ์ง€์˜ front๋‹จ ๊ตฌ์„ฑ ์ •๋ฆฌ

1. ์ด์ค‘ํ™” ๊ตฌ์„ฑ : WEB์„œ๋ฒ„ 2๊ฐœ ์ƒ์„ฑ

2. ๋ฉ€ํ‹ฐ์กด ๊ตฌ์„ฑ : ๊ฐ€์šฉ์˜์—ญ A, C ๋ถ„๋ฆฌ

3. ํ์‡„๋ง ๊ตฌ์„ฑ : Private ์„œ๋ธŒ๋„ท ๊ตฌ์„ฑ

4. ALB ๋ถ€ํ•˜๋ถ„์‚ฐ์ฒ˜๋ฆฌ

 

7. Apache ์„ค์น˜

$ sudo yum install httpd
$ sudo systemctl start httpd
$ sudo systemctl enable httpd

$ sudo systemctl status httpd
โ— httpd.service - The Apache HTTP Server
     Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; pres
     Active: active (running) since Sun 2024-11-17 07:09:28 UTC; 20s ago
       Docs: man:httpd.service(8)
   Main PID: 8927 (httpd)
     Status: "Total requests: 0; Idle/Busy workers 100/0;Requests/sec: 0;
      Tasks: 177 (limit: 2321)
     Memory: 13.2M
        CPU: 75ms
     CGroup: /system.slice/httpd.service
             โ”œโ”€8927 /usr/sbin/httpd -DFOREGROUND
             โ”œโ”€8928 /usr/sbin/httpd -DFOREGROUND
             โ”œโ”€8929 /usr/sbin/httpd -DFOREGROUND
             โ”œโ”€8930 /usr/sbin/httpd -DFOREGROUND
             โ””โ”€8931 /usr/sbin/httpd -DFOREGROUND

Bastion host๋ฅผ ํ†ตํ•ด WEB01, WEB02 ์„œ๋ฒ„์— SSH ์ ‘์†ํ•œ๋‹ค

yum ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•œ httpd ์„ค์น˜๋ฅผ ์ง„ํ–‰ํ•œ๋‹ค

$ sudo su -
# cd /var/www/html
# vi index.html
hello from minjin

 

7-1 healthy check ๋ฌธ์ œ๋ฐœ์ƒ

[root@ip-10-0-118-37 ~]# netstat -antup | grep 80
tcp6       0      0 :::80                   :::*                    LISTEN      11830/httpd
tcp6       0      0 10.0.118.37:80          10.0.118.45:38970       TIME_WAIT   -
tcp6       0      0 10.0.118.37:80          10.0.118.52:12776       TIME_WAIT   -
tcp6       0      0 10.0.118.37:80          10.0.118.52:27166       TIME_WAIT   -
tcp6       0      0 10.0.118.37:80          10.0.118.45:12824       TIME_WAIT   -
udp6       0      0 fe80::7a:5fff:fe57::546 :::*                                1970/systemd-networ

๋กœ๋“œ๋ฐธ๋Ÿฐ์‹ฑ ๋Œ€์ƒ๊ทธ๋ฃน์—์„œ ๋“ฑ๋ก๋œ ๋Œ€์ƒ์˜ healthy check๊ฐ€ ์•ˆ ๋˜๋Š” ๋ฌธ์ œ ๋ฐœ์ƒ

ํ™•์ธํ•ด๋ณด๋‹ˆ ipv6 80๋ฒˆ ํฌํŠธ๋งŒ ์—ด๋ฆฌ๋Š” ๊ฒƒ์„ ์•Œ๊ฒŒ๋˜์—ˆ๋‹ค

๋ฌธ์ œ ํ•ด๊ฒฐ

# cd /etc/httpd/conf
# vim httpd.conf
 47 Listen 0.0.0.0:80

๊ธฐ์กด Listen 80 ๋กœ๋งŒ ๋˜์–ด์žˆ๋Š” ๋ถ€๋ถ„์„ 0.0.0.0:80์œผ๋กœ ๋ณ€๊ฒฝํ•˜์—ฌ

ipv6๊ฐ€ turn off ๋˜๋„๋ก conf ํŒŒ์ผ์„ ์ˆ˜์ •ํ–ˆ๋‹ค

# systemctl restart httpd
# netstat -lntp | grep 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      13544/httpd

80๋ฒˆ ํฌํŠธ๊ฐ€ ์ž˜ ์—ด๋ ธ๋‹ค

healthy check๋ฅผ ์™„๋ฃŒํ–ˆ๋‹ค

ALB ๋กœ๋“œ๋ฐธ๋Ÿฐ์„œ์˜ dns ์ฃผ์†Œ๋กœ ์ ‘์†ํ•œ๋‹ค

 

 

 

 

 

๋‹ค์Œ ๊ธ€์€ WAS & NLB ์ƒ์„ฑ์œผ๋กœ ์ด์–ด์ง‘๋‹ˆ๋‹ค

 

AWS : 3 Tier [WAS & NLB ์ƒ์„ฑ]

8. WAS8-1 ๋ณด์•ˆ๊ทธ๋ฃน ์ƒ์„ฑ 8-2 Bastion ๋ณด์•ˆ๊ทธ๋ฃน ์•„์›ƒ๋ฐ”์šด๋“œ ์ถ”๊ฐ€SSH WAS ๋ณด์•ˆ๊ทธ๋ฃน์„ ์ถ”๊ฐ€ํ•œ๋‹ค 8-3 ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ์ธ์Šคํ„ด์Šค ์‚ฌ์–‘๊ณผ ์„œ๋ธŒ๋„ท์— ์ฃผ์˜ํ•˜์—ฌ 2๊ฐœ์˜ WAS ์„œ๋ฒ„๋ฅผ ์ƒ์„ฑํ•œ๋‹ค  9. Tomcat ์„ค์น˜- root ๊ณ„์ •

nenjin.tistory.com