Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/myeonghan-nim/load-balancing

๐Ÿ“– Study: load balancing
https://github.com/myeonghan-nim/load-balancing

django load-balancing nginx python

Last synced: 26 days ago
JSON representation

๐Ÿ“– Study: load balancing

Awesome Lists containing this project

README

        

# load balancing

## ๋กœ๋“œ ๋ฐธ๋Ÿฐ์‹ฑ

์„œ๋ฒ„์— ๋“ค์–ด์˜ค๋Š” ๋„คํŠธ์›Œํฌ ํŠธ๋ž˜ํ”ฝ์„ ์—ฌ๋Ÿฌ ์„œ๋ฒ„์— ๋ถ„์‚ฐ์‹œํ‚ค๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•˜๋ฉฐ **๋กœ๋“œ ๋ฐธ๋Ÿฐ์„œ**๋Š” ์ด๋ฅผ ์ˆ˜ํ–‰ํ•˜๋Š” ์žฅ์น˜ ํ˜น์€ ์†Œํ”„ํŠธ์›จ์–ด๋ฅผ ์˜๋ฏธ.
๋กœ๋“œ ๋ฐธ๋Ÿฐ์‹ฑ์„ ํ†ตํ•ด ํŠธ๋ž˜ํ”ฝ ๊ณผ๋ถ€ํ•˜๋กœ ์ธํ•œ ์„œ๋ฒ„ ๋‹ค์šด์„ ๋ฐฉ์ง€ํ•˜๊ณ  ์„œ๋ฒ„ ์ž์›์„ ํšจ์œจ์ ์œผ๋กœ ์‚ฌ์šฉ.
๋กœ๋“œ ๋ฐธ๋Ÿฐ์‹ฑ์€ ์ˆ˜ํ‰์  ํ™•์žฅ๊ณผ ๋ฐ€์ ‘ํ•œ ๊ด€๋ จ์ด ์žˆ์œผ๋ฉฐ ํฌ๊ฒŒ ๋‘ ๊ฐ€์ง€ ๋ฐฉ์‹์ด ์กด์žฌ

1. L4 ๋กœ๋“œ ๋ฐธ๋Ÿฐ์‹ฑ: ์ „์†ก ๊ณ„์ธต(Transport Layer, TCP/UDP)์—์„œ ๋กœ๋“œ ๋ฐธ๋Ÿฐ์‹ฑ
2. L7 ๋กœ๋“œ ๋ฐธ๋Ÿฐ์‹ฑ: ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ณ„์ธต(Application Layer, HTTP)์—์„œ ๋กœ๋“œ ๋ฐธ๋Ÿฐ์‹ฑ

### ๋กœ๋“œ ๋ฐธ๋Ÿฐ์‹ฑ ์•Œ๊ณ ๋ฆฌ์ฆ˜

1. Round Robin: ์„œ๋ฒ„๋“ค์— ์ฐจ๋ก€๋Œ€๋กœ ์š”์ฒญ์„ ๋ถ„์‚ฐ
2. Least Connections: ํ˜„์žฌ ์—ฐ๊ฒฐ ์ˆ˜๊ฐ€ ๊ฐ€์žฅ ์ ์€ ์„œ๋ฒ„์— ์š”์ฒญ์„ ๋ถ„์‚ฐ
3. IP Hash: ํด๋ผ์ด์–ธํŠธ์˜ IP ์ฃผ์†Œ๋ฅผ ํ•ด์‹ฑํ•˜์—ฌ ํŠน์ • ์„œ๋ฒ„์— ์—ฐ๊ฒฐ
4. Weighted Round Robin: ์„œ๋ฒ„์˜ ์„ฑ๋Šฅ์— ๋”ฐ๋ผ ๊ฐ€์ค‘์น˜๋ฅผ ๋ถ€์—ฌํ•˜์—ฌ ํŠธ๋ž˜ํ”ฝ ๋ถ„์‚ฐ

## TIPs

### nginx

1. nginx๋ฅผ ํŠน์ • ์œ„์น˜์— ์กด์žฌํ•˜๋Š” `nginx.conf` ํŒŒ์ผ์„ ์‚ฌ์šฉํ•ด ์‹คํ–‰ํ•˜๋ ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ช…๋ น์–ด ์‚ฌ์šฉ

```bash
$ sudo nginx -c /your/custom/path/nginx.conf

# ์ข…๋ฃŒ
$ sudo nginx -s stop
```

### AWS์˜ ELB

0. ์ „์ œ ์กฐ๊ฑด
- AWS์— ๋‘ ๋Œ€์˜ EC2 ์ธ์Šคํ„ด์Šค๋ฅผ ์‹คํ–‰ ์ค‘
- ๊ฐ EC2 ์ธ์Šคํ„ด์Šค์—๋Š” nginx๋กœ ์‹คํ–‰ ์ค‘์ธ ์›น ์„œ๋ฒ„๊ฐ€ ์กด์žฌ
- `/var/www/html/index.html`์— `"This is Server ${server_name}`์ด๋ผ๊ณ  ๊ธฐ๋ก๋œ ์ƒํƒœ
- ๊ฐ EC2 ์ธ์Šคํ„ด์Šค๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์„ค์ •๋œ ์ƒํƒœ
- Security Group์˜ Inbound Rules์— HTTP ํŠธ๋ž˜ํ”ฝ(0.0.0.0/0) ํ—ˆ์šฉ
1. ELB ์ƒ์„ฑ
1. EC2 ์„œ๋น„์Šค์˜ ์ขŒ์ธก ๋ฉ”๋‰ด์—์„œ Load Balancers๋ฅผ ์„ ํƒํ•˜๊ณ  Create Load Balancer ์„ ํƒ
2. HTTP/HTTPS ๊ธฐ๋ฐ˜ ํŠธ๋ž˜ํ”ฝ ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•ด Application Load Balancer ์„ ํƒ
1. Name ์ž…๋ ฅ
2. Scheme์— Internet-facing ์„ ํƒ
3. IP Address Type์— IPv4 ์„ ํƒ
3. ๋„คํŠธ์›Œํฌ ์„ค์ •
1. EC2 ์ธ์Šคํ„ด์Šค์™€ ๋™์ผํ•œ VPC ์„ ํƒ
2. Availability Zones์—์„œ EC2 ์ธ์Šคํ„ด์Šค๊ฐ€ ์žˆ๋Š” ๋ชจ๋“  ์˜์—ญ์„ ์„ ํƒ
3. Security Groups์—์„œ ๊ธฐ์กด ๋ณด์•ˆ ๊ทธ๋ฃน์„ ์„ ํƒํ•˜๊ฑฐ๋‚˜ ์ƒˆ๋กœ ์ƒ์„ฑํ•˜์—ฌ HTTP(80๋ฒˆ ํฌํŠธ) ์ ‘๊ทผ์„ ํ—ˆ์šฉ
4. ๋ฆฌ์Šค๋„ˆ ์„ค์ •
1. ๊ธฐ๋ณธ์ ์œผ๋กœ HTTP(80๋ฒˆ ํฌํŠธ) ๋ฆฌ์Šค๋„ˆ๊ฐ€ ์„ค์ •๋˜์–ด ์žˆ์œผ๋‚˜ ๋‹ค๋ฅธ ํฌํŠธ์—์„œ ์ˆ˜์‹ ์„ ์›ํ•˜๋ฉด ์ถ”๊ฐ€ ๋ฆฌ์Šค๋„ˆ๋ฅผ ์„ค์ •
5. ๋Œ€์ƒ ๊ทธ๋ฃน ์ƒ์„ฑ
1. Name์— ์ด๋ฆ„ ์ž…๋ ฅ
2. Target Type์„ Instance๋กœ ์„ ํƒ
3. Protocol์„ HTTP๋กœ, Port๋ฅผ 80์œผ๋กœ ์„ ํƒ
4. VPC๋ฅผ EC2 ์ธ์Šคํ„ด์Šค์™€ ๋™์ผํ•œ VPC๋กœ ์„ค์ •
5. Health Check ์„ค์ •
1. Protocol์„ HTTP๋กœ, Path๋ฅผ / (๊ธฐ๋ณธ ๊ฒฝ๋กœ)๋กœ ์„ค์ •
2. Health check๊ฐ€ ์‹คํŒจํ•  ๊ฒฝ์šฐ ๋Œ€์ƒ์„ ์ž๋™์œผ๋กœ ์ œ์™ธํ•˜๋„๋ก ์„ค์ •
6. ๋Œ€์ƒ ์ธ์Šคํ„ด์Šค ๋“ฑ๋ก
1. Register targets์—์„œ ๋‘ ๊ฐœ์˜ EC2 ์ธ์Šคํ„ด์Šค๋ฅผ ์„ ํƒ
2. Add to registered ํด๋ฆญํ•˜์—ฌ ๋Œ€์ƒ ๊ทธ๋ฃน์— EC2 ์ธ์Šคํ„ด์Šค ๋“ฑ๋ก
3. ์„ค์ • ์™„๋ฃŒ ํ›„ Create ๋ฒ„ํŠผ ํด๋ฆญ
2. ๋กœ๋“œ ๋ฐธ๋Ÿฐ์„œ ํ™•์ธ
1. ELB ์ƒํƒœ ํ™•์ธ: ์•ฝ๊ฐ„ ์‹œ๊ฐ„์ด ๊ฑธ๋ฆฌ์ง€๋งŒ ์ƒํƒœ๊ฐ€ ํ™œ์„ฑํ™”์ธ์ง€ ํ™•์ธ
2. ELB DNS ํ™•์ธ: ํ™œ์„ฑํ™”๋œ ํ›„ Load Balancer ๋ชฉ๋ก์—์„œ ํ•ด๋‹น ALB์˜ DNS ์ด๋ฆ„์„ ํ™•์ธ
3. ํ…Œ์ŠคํŠธ: ๋ธŒ๋ผ์šฐ์ €์—์„œ ALB์˜ DNS ์ด๋ฆ„์„ ํ†ตํ•ด ์ ‘์†