반응형
CentOS에서 HAProxy를 설치하는 방법
haproxy(로드밸런싱) : TCP/HTTP proxy and load balancer for high availability environments
구성 환경
서버 | 운영체제 | 아이피 | 패키지 | 비고 |
master | CentOS 7.9 | 192.168.0.8 | haproxy |
Kernel Paramater 설정
- /etc/sysctl.conf 설정
echo "###HAPorxy Kernel Paramater" >> /etc/sysctl.conf
echo 'net.ipv4.ip_nonlocal_bind=1' >> /etc/sysctl.conf
echo 'net.ipv4.ip_forward=1' >> /etc/sysctl.conf
재부팅 또는 sysctl -p
sysctl -p
설정한 커널 파라미터 값 확인
sysctl -a | grep net.ipv4.ip_nonlocal_bind
$ sysctl -a | grep net.ipv4.ip_nonlocal_bind
net.ipv4.ip_nonlocal_bind = 1
cat /proc/sys/net/ipv4/ip_nonlocal_bind
$ cat /proc/sys/net/ipv4/ip_nonlocal_bind
1
haproxy 설치
yum install -y haproxy
haproxy -v
$ haproxy -v
HA-Proxy version 1.5.18 2016/05/10
Copyright 2000-2016 Willy Tarreau <willy@haproxy.org>
systemctl --now enable haproxy
$ systemctl --now enable haproxy
Created symlink from /etc/systemd/system/multi-user.target.wants/haproxy.service to /usr/lib/systemd/system/haproxy.service.
728x90
haproxy 설정
haproxy.cfg 파일 편집(/etc/haproxy/haproxy.cfg)
vim /etc/haproxy/haproxy.cfg
$ vim /etc/haproxy/haproxy.cfg
global
log 127.0.0.1 local2
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon
# turn on stats unix socket
stats socket /var/lib/haproxy/stats
#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000
#---------------------------------------------------------------------
# frontend which proxys to the backends
#---------------------------------------------------------------------
frontend load-balancer
bind *:80
mode http
default_backend webserver
#---------------------------------------------------------------------
# frontend which proxys to the backends
#---------------------------------------------------------------------
frontend webserver81
bind *:81
mode tcp
option tcplog
default_backend webserver81
#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend webserver
mode http
option httpchk GET /
http-check expect status 200
default-server inter 10s downinter 5s rise 2 fall 2 slowstart 60s maxconn 250 maxqueue 256 weight 100
balance roundrobin
server app1 192.168.0.7:80 check inter 3000 rise 2 fall 5
server app2 192.168.0.7:81 check inter 3000 rise 2 fall 5
server app3 192.168.0.7:82 check inter 3000 rise 2 fall 5
#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend webserver81
mode tcp
option tcplog
option tcp-check
balance roundrobin
server app1 192.168.0.7:80 weight 1 maxconn 512 check fall 3 rise 2
server app2 192.168.0.7:81 weight 1 maxconn 512 check fall 3 rise 2
server app2 192.168.0.7:82 weight 1 maxconn 512 check fall 3 rise 2
#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
listen stats *:9000
mode http
stats enable
stats hide-version
stats refresh 30s
stats show-node
stats realm HAProxy Statistics
stats uri /
stats auth admin:admin
설정값이 유효한지 확인
haproxy -f /etc/haproxy/haproxy.cfg -c
$ haproxy -f /etc/haproxy/haproxy.cfg -c
Configuration file is valid
통계 보고서 페이지
- URL : http://192.168.0.8:9000/
- ID/PW : admin/admin
728x90
반응형
'리눅스' 카테고리의 다른 글
CentOS 7에서 keepalived를 설치하고 설정하여 A 서버와 B 서버 간에 VIP (Master와 Backup) 구성하는 방법 (0) | 2021.08.13 |
---|---|
iperf3를 설치하고 사용하는 방법 (0) | 2021.08.13 |
CentOS 8 미러 서버용 repo(CentOS-Base.repo) 파일 (0) | 2021.08.10 |
yum(dnf) 설치 및 업데이트 시 에러 (0) | 2021.08.09 |
CentOS 8에서 Yum Repository 서버를 구축하는 방법 (0) | 2021.08.09 |