네트워크 및 서버/서버
Web Server 로드밸런싱 구현 (2)
잉여토끼
2024. 12. 3. 15:15
ha-proxy
L4, L7 계층에서 Reverce Proxy를 이용한 로드밸런서
Mode : http, tcp
log 127.0.0.1 lacal2
local2 : indice/shard
log level : debug(7) info(6) notice(5) warning(4) err(3) crit(2) alert(1) critical(0)
1. 설치
dnf install haproxy
apt install haproxy
2. haproxy 설정 삽입
vim /etc/haproxy/haproxy.cfg
frontend tired_fr
bind *:80
mode http
default_backend tired_bac
backend tired_bac
balance roundrobin
mode http
server s1 w1.tired.com check
server s2 w2.tired.com check
server s3 w3.tired.com check
server s4 w4.tired.com check
errorfile 503 /etc/haproxy/errors/503.http
3. haproxy 로깅
vim /etc/rsyslog.d/haproxy.conf
local2.* /var/log/haproxy_http.log
# 만약 local2 Index를 사용중일경우 /etc/haproxy/haproxy.cfg에서 수정
systemctl restart rsyslog haproxy
로그 정보 :
Dec 3 12:19:29 localhost haproxy[886911]: 172.16.13.19:33708 [03/Dec/2024:12:19:29.697] tired_fr tired_bac/s1 0/0/0/1/1 404 363 - - ---- 2/2/0/0/0 0/0 "GET /CSS/index.css HTTP/1.1"
Dec 3 12:19:29 localhost haproxy[886911]: 172.16.13.19:33702 [03/Dec/2024:12:19:29.755] tired_fr tired_bac/s2 0/0/1/0/1 200 211 - - ---- 2/2/0/0/0 0/0 "GET / HTTP/1.1"
Dec 3 12:19:29 localhost haproxy[886911]: 172.16.13.19:33702 [03/Dec/2024:12:19:29.896] tired_fr tired_bac/s3 0/0/0/1/1 200 1172 - - ---- 2/2/0/0/0 0/0 "GET / HTTP/1.1"
Dec 3 12:19:29 localhost haproxy[886911]: 172.16.13.19:33702 [03/Dec/2024:12:19:29.931] tired_fr tired_bac/s4 0/0/0/1/1 404 361 - - ---- 2/2/1/0/0 0/0 "GET /font_fi.css HTTP/1.1"
Dec 3 12:19:29 localhost haproxy[886911]: 172.16.13.19:33708 [03/Dec/2024:12:19:29.931] tired_fr tired_bac/s1 0/0/1/0/1 404 363 - - ---- 2/2/0/0/0 0/0 "GET /CSS/index.css HTTP/1.1"
Docs:
https://www.haproxy.com/documentation/haproxy-configuration-manual/latest/
HAProxy Enterprise Documentation version 3.0r1 (1.0.0-337.394) - Configuration Manual
This document covers the configuration language as implemented in the version specified above. It does not provide any hints, examples, or advice. For such documentation, please refer to the Reference Manual or the Architecture Manual. The summary below is
www.haproxy.com
4. Loadbalancing 트래픽 분석
listen status
bind :9997
stats enable
stats uri /
stats hide-version
stats refresh 5s
stats auth root:asd123!@