HAProxy를 APP서버들의 LB로 사용하기 위해 Linux (centOS7) 환경에 설치/설정 진행.
설치는 https://linuxscriptshub.com/install-haproxy-centos-7/를 참고한다.
구조
|--- APP1 | HAProxy (LB) --- | [Round Robin] | |--- APP2
설치 버전 : 2.6.2 (latest release)
설치 디렉터리 : /home1/user/apps/ 이하
설치 계정 : user, usersu(sudo 권한을 가짐)
$ sudo yum install gcc pcre-static pcre-devel -y
$ cd ~/apps
$ curl http://www.haproxy.org/download/2.6/src/haproxy-2.6.2.tar.gz | tar -xz
$ cd haproxy-2.6.2
$ make TARGET=gglibc USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1
$ make PREFIX=/home1/user/apps/haproxy DESTDIR= install
$ cd ~/apps
$ sudo chown root:user haproxy
$ sudo chmod 6755 hapxory
# haproxy.cfg
#--------------------------------------------------------------------------
global
log 127.0.0.1 local0
daemon
maxconn 4096
uid 500
gid 500
# stats socket /run/haproxy/admin.sock uid hatop gid hatop mode 660
pidfile /home1/user/apps/haproxy/haproxy.pid
tune.ssl.default-dh-param 2048
ssl-default-bind-options no-sslv3 no-tls-tickets
#-------------------------------------------------------------------------
defaults
mode http
log global
option httplog
option dontlognull
option dontlog-normal
option http-server-close
option forwardfor
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
#------------------------------------------------------------------------
# http 80/ https 443 ssl setting
frontend http-in
bind *:80
bind *:443 ssl crt /home1/user/apps/ssl/all_cert.pem
default_backend servers
http-request set-header X-Forwarded-Proto https if { ssl_fc }
#------------------------------------------------------------------------
backend servers
balance roundrobin
server app1 <app1-ip>:80 check
server app2 <app2-ip>:80 check
$ haproxy -f haproxy.conf