1. Project ์๋ฒ ๊ตฌ์ฑ
[1] AutoScaling ํ๊ฒฝ์์ API call ์ ๊ดํ ๊ณ ๋ฏผ

ํ๋ก์ ํธ์ ๊ตฌ์ฑ์ Gradle ๊ธฐ๋ฐ ๋ฉํฐ ๋ชจ๋๋ก ๊ตฌ์ฑ๋์ด ์์๋ค. ์ด์ ํ๋ก์ ํธ ์ธํ๋ผ์ ๋ค๋ฅธ ์ ์ BFF ํจํด(Backend For Frontend) ์ผ๋ก ๊ตฌ์ฑํ๊ณ ์์ด conference, analysis server ์ api call ์ ํด์ผ ํ๋ค๋ ์ ์ด ๊ฐ์ฅ ํฐ ์ฐจ์ด์๋ค. ํ๋ก์ ํธ ํ๊ฒฝ์ ๊ตฌ์ฑํ๋ฉด์ ๊ฐ์ฅ ๊ณ ๋ฏผ๋์๋ ์ ์ Scale out ํ๊ฒฝ์์ ์ด๋ป๊ฒ api call ์ ํ ๊ฒ์ธ๊ฐ? ์ด๋ค.
API call ์ ํ๋ ๊ฐ์ฅ ๊ฐ๋จํ ๋ฐฉ๋ฒ์ IP, PORT ์ ๊ดํ ์๋ฒ ์คํ์ ๊ธฐ๋ฐ์ผ๋ก ์์ฒญํ๋ ๊ฒ์ด๋ค. ํ์ง๋ง Scale out ํ๊ฒฝ์์๋ ์์ธํ ์๋ฒ ์คํ์ ์๋ ๊ฒ์ ํ๊ณ๊ฐ ์๋ค. Scale out ๋๋ ์๋ฒ ์คํ์ ์ถ๊ฐํ๊ณ , ๋ฐ๋๋ก Sclae in ํ๋ ์๋ฒ ์คํ์ ์ ๊ฑฐํ๋ ์์ ์ WAS ๊ฐ ๋ด๋นํ๋๋ฐ ํ๊ณ๊ฐ ์กด์ฌํ๋ค. ๋ํ ๋ถํ๊ฐ ๋ฎ์ ์๋ฒ์ WAS ๊ฐ ์ ํํ๋ ๊ณผ์ ๊ณผ ๊ฐ์ด ํธ๋ํฝ์ ์ ์ฐํ Scale out ํ๊ฒฝ์ ์ํด ์ ํํ ๋ฐฉ๋ฒ์ application load balancer ์ด๋ค.
[2] AWS Load balancer ๋ฅผ ๊ธฐ๋ฐํ ์ํคํ ์ฒ ๊ตฌ์ฑ
AWS application load balancer ์ ๊ท์น์ ์๋ง๋ ์์ฒญ์ target group ์ ํตํด ์์ฒญ์ ๋ผ์ฐํ ํ๋ค. header, path, http method ์ ๋ณด๋ค๋ก ๋ผ์ฐํ ๊ท์น์ ์ค์ ํ ์ ์๋ค. ๋ํ AWS ๋ CIDR ๊ธฐ๋ฐ์ source IP ๋ ์กฐ๊ฑด์ ์ ๊ณตํ๋ค. application load balancer ๋ public, private ๊ด๊ณ์์ด DNS ๋ฅผ ์ ๊ณตํ๋ค. DNS ์ด๋ฆ์ ํตํด load balancer ์ ์์ฒญํ๋ฉด ์ค์ ๋ ๋ด์ฉ์ ํ ๋๋ก ๋ผ์ฐํ , ๋ถํ ๋ถ์ฐ์ ์ง์ํ๋ค.
๊ตฌ์ฑํ architecture ๋ ์๋์ ๊ฐ๋ค. load balancer ๋ 2๊ฐ๋ฅผ ๊ตฌ์ฑํ๊ณ ์ธํฐ๋ท ๊ฒฝ๊ณ์ ๋ด๋ถ ์์ฒญ์ ์ฒ๋ฆฌํ๋ application load balancer ๋ฅผ ๊ตฌ์ฑํ๋ค. HTTPS ์์ฒญ์ url path ๋ฅผ ์ด์ฉํ ํํฐ๋งํ์ฌ ํด๋น target group ์๊ฒ ๋ผ์ฐํ ํ๋๋ก ๊ตฌ์ฑํ๋ค.


2. ํ๋ฒ ๋ง๋ค์ด ๋ณด์.
[1] launch template ๊ตฌ์ฑํ๊ธฐ
1. ์ ํ๋ฆฌ์ผ์ด์ ๋ฐ OS ์ด๋ฏธ์ง : amazon linux
2. ์ธ์คํด์ค ์ ํ : t2.micro
3. ๋ณด์ ๊ทธ๋ฃน(inbound)
- TCP 8080 ๋์ญ : load balancer security group ์ค์
4. ๋คํธ์ํฌ ์ค์ (๊ณ ๊ธ ๋คํธ์ํฌ ๊ตฌ์ฑ)

5. ๊ณ ๊ธ ์ธ๋ถ ์ ๋ณด
- IAM ์ญํ > S3 FullAccess + CloudWatchAgentServerPolicy

6. ์ฌ์ฉ์ ๋ฐ์ดํฐ (๋ถํ ํ, shell ๋ช ๋ น์ด ์ถ๊ฐ ์ค์ )
#!/bin/bash
su ec2-user
sudo yum install -y amazon-cloudwatch-agent
sudo aws s3 cp s3://[s3-bucket-์ด๋ฆ]/config.json /opt/aws/amazon-cloudwatch-agent/bin/config.json
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json
sudo yum install -y java-17-amazon-corretto
aws s3 cp s3://[s3-bucket-์ด๋ฆ]/member-0.0.1-SNAPSHOT.jar /home/ec2-user
nohup java -jar -Dspring.profiles.active=prod /home/ec2-user/member-0.0.1-SNAPSHOT.jar 1> logs.out 2>&1 &
[2] load balancer ์์ฑ
1. ๋ก๋ ๋ฐธ๋ฐ์ ์ ํ ๋น๊ต ๋ฐ ์ ํ
- application load balancer
2. ์ฒด๊ณ
- ์ธํฐ๋ท ๊ฒฝ๊ณ (conference, analysis ๋ ์์ฑ ์์๋ ๋ด๋ถ๋ก ์ค์ )

3. ๋คํธ์ํฌ ๋งคํ
- VPC ์ค์
- ์์ฒญ ํ ๋นํญ subnet ๊ตฌ์ฑ

4. ๋ณด์ ๊ทธ๋ฃน (inbound)
- [public load balancer] TCP 443 (HTTPS) : 0.0.0.0/0 (์ ์ฒด ๋์ญ)
- [private load balancer] TCP 8080 : private load balancer ๊ฐ ํฌํจ๋ ๋ณด์ ๊ทธ๋ฃน (์ ์ฒด ๋์ญ)
5. ๋ฆฌ์ค๋ ๋ฐ ๋ผ์ฐํ
- protocol : HTTPS / port 443 / ๋์ ๊ทธ๋ฃน ์ ํ

- ๋ก๋ ๋ฐธ๋ฐ์ฑ ์์ฑ ์ดํ path routing ์ค์


๐จ [trouble shooting] /api/members/* vs /api/members* ์ฐจ์ด??
(1) /api/members/* : /api/members mapping (X)
(2) /api/members* : /api/members mapping (O)
6. TLS ์ธ์ฆ์ ์ถ๊ฐ

[3] AutoScalingGroup ์์ฑ
1. ์์ ํ ํ๋ฆฟ ์ ํ
- ์์ ํ ํ๋ฆฟ ๊ตฌ์ฑ
- ๋ฒ์ : Latest

2. ๋คํธ์ํฌ ์ค์
- VPC, subnet ์ค์

3. load balancer ์ค์
- ๊ธฐ์กด ๋ก๋ ๋ฐธ๋ฐ์ ์ค์
- ๋ผ์ฐํ ํ ๋์ ๊ทธ๋ฃน์ผ๋ก ์ถ๊ฐ

4. ๊ทธ๋ฃน ํฌ๊ธฐ ๋ฐ ํฌ๊ธฐ ์กฐ์ ๊ตฌ์ฑ

3. TroubleShooting
front-group ์ ์ถ๊ฐํ๋ ๊ณผ์ ์์์ 502 error ๊ฐ ๋ฐ์ํ ์ด์
- ์๋ฒ๊ฐ ๊ฒ์ดํธ์จ์ด๋ ํ๋ก์ ์๋ฒ ์ญํ ์ ํ๋ฉด์ ์ ์คํธ๋ฆผ ์๋ฒ๋ก๋ถํฐ ์ ํจํ์ง ์์ ์๋ต์ ๋ฐ์๋ค๋ ๊ฒ์ ์๋ฏธ
- ์์ธ : ๋์ ๊ทธ๋ฃน์ ๋ณ๊ฒฝํ๋ฉด์ upstream server ๋ก ๋ถํฐ ์๋ต์ ๋ฐ์ง ๋ชปํ ์ด์ : ์๋ฒ ์ข
๋ฃ๋ก ์ธํ ์ด์
- 404 vs 502 vs 504
- 404(Not Found) : ๋ง์ฝ load balancer ์ mapping url ์ด ์กด์ฌํ์ง ์์ ๊ฒฝ์ฐ 404 ๋ฐํ
- 502(bad gateway) : ๋ง์ฝ ์๋ฒ๊ฐ ์ ์ ์ด์ ์ค์ด์ง๋ง ํํฐ๋ง ์กฐ๊ฑด์ ๋ชจ๋ ํต๊ณผํ์ง ๋ชปํ์ ๊ฒฝ์ฐ ๋ฐํ
- 504(Gateway Time-out) : ๋ณด์ ๊ทธ๋ฃน ์ค์ ์ค๋ฅ๋ก ์ธํ ์ด์๋ก ์ฃผ๋ก ์ถ์
- 404 vs 502 vs 504
/api/members/* vs /api/members* ์ฐจ์ด??
- /api/members/* : /api/members mapping (X)
- /api/members* : /api/members mapping (O)
4. ํ์ฌ ๊ตฌ์กฐ์์ ์ถ๊ฐ ๊ฐ์ ์ฌํญ
- ๋น๋ ํ๋ก์ธ์ค ๊ฐ์
- AS-IS : ์ธ์คํด์ค ์์ฑ ์, ๋น๋ ํ์ผ ๋ค์ด๋ก๋
- ํ๊ณ : scaling out ํ๊ฒฝ์์ ์ฝ๋ ์์ ์ด ์์ ๊ฒฝ์ฐ, ์์์ ์ผ๋ก ๊ฐ๊ฐ ๋น๋ํด์ผ ํ๋ฏ๋ก ์ด๋ฅผ ๊ฐ์ ํ๊ธฐ ์ํ ๋ฐฐํฌ ๋์
- TO-BE : ๋ฐฐํฌ ์๋ํ ๋๊ตฌ ๋์ (code deploy, jenkins)
- cloudwatch ์ ์ฉ
- /api/analysis response time ๊ฒํ ๋ฐ ๊ฐ์
- AS-IS : ์ฝ๋๋ฅผ ์ทจ๋ฏธ๋ก ํ๋ ์ค๋ฌธ ์กฐ์ฌ API response time : 600ms
- TO-BE : 200ms ์ดํ๋ก ๊ฐ์
Reference
'๐ education & lecture > ์ธํ๋ผ ๊ณต๋ฐฉ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| [์ธํ๋ผ ๊ณต๋ฐฉ] ์ปจํผ๋ฐ์ค ์ ์ฒญ - 4. ์๋น์ค ์ฑ๋ฅ ์ง๋จํ๊ธฐ (1) | 2024.03.28 |
|---|---|
| [์ธํ๋ผ ๊ณต๋ฐฉ] ์ปจํผ๋ฐ์ค ์ ์ฒญ - 3. ์๋ฒ ์ง๋จํ๊ธฐ (1) | 2024.03.14 |
| [์ธํ๋ผ๊ณต๋ฐฉ] ์ปจํผ๋ฐ์ค ์ ์ฒญ - 1. github action ์ ํตํ ๋น๋ ์ค์ (1) | 2024.03.05 |
| [์ธํ๋ผ๊ณต๋ฐฉ] ์งํ์ฒ ๋ ธ์ ๋ - 4. ํ๋ฉด ์๋ต ๊ฐ์ ํ๊ธฐ (0) | 2024.02.29 |
| [์ธํ๋ผ๊ณต๋ฐฉ] HTTP Cache (0) | 2024.02.28 |