WAS
haproxy 기본 설정 방법
Lawmin
2025. 4. 3. 10:19
192.168.0.1 (80 또는 443) 접속 시, 192.168.0.2 ~ 3으로 분기해주는 설정 예시입니다.
https(443)는 SSL 종단(termination) 처리하지 않고, backend 서버에게 맡깁니다.
이를 위해 http mode가 아닌 tcp mode 로 설정합니다.
필요 시, 인증서 설정을 추가하여 http mode 로 설정하면, 보다 세부적인 설정 및 모니터링이 가능합니다만,
여기서는 다루지 않습니다. (원래 사용자의 IP 확인, 접속 통계 확인 등)
# vi /etc/haproxy/haproxy.cfg
global
log /dev/log local0
pidfile /run/haproxy.pid
chroot /var/lib/haproxy
maxconn 20000
user haproxy
group haproxy
daemon
stats socket /var/run/haproxy.sock mode 600 level admin
defaults
log global
option dontlognull
timeout connect 5s
timeout client 50s
timeout server 50s
# Reverse proxy sample
frontend http_front
bind 192.168.0.1:80
option tcplog
mode tcp
default_backend http_back
backend http_back
mode tcp
balance source
server web01 192.168.0.2:80 check
server web02 192.168.0.3:80 check
frontend https_front
bind 192.168.0.1:443
option tcplog
mode tcp
default_backend https_back
backend https_back
mode tcp
balance source
option ssl-hello-chk
server web01 192.168.0.2:443 check
server web02 192.168.0.3:443 check
커널 설정
# vi /etc/sysctl.conf
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.core.rmem_default = 253952
net.core.wmem_default = 253952
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 253952 253952 16777216
net.ipv4.tcp_wmem = 253952 253952 16777216
net.core.netdev_max_backlog = 30000
net.core.somaxconn = 1024
net.ipv4.tcp_max_tw_buckets = 1800000
net.ipv4.tcp_timestamps = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.ip_local_port_range = 1024 65535
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_max_syn_backlog = 8192
fs.file-max = 1573400
vm.swappiness = 10
#Keepalived
net.ipv4.ip_nonlocal_bind = 1
net.ipv4.conf.default.arp_ignore=1
net.ipv4.conf.default.arp_announce=2
net.ipv4.conf.lo.arp_ignore=0
net.ipv4.conf.lo.arp_announce=0
#Haproxy
net.ipv4.ip_forward = 1
kernel.printk = 3 4 1 7
# vi /etc/security/limits.conf
* soft core unlimited
* hard core unlimited
* soft nofile 396950
* hard nofile 793900
* soft nproc 131072
* hard nproc 262144