HAProxy 설치/설정

rodusik·2022년 7월 26일
0

구축시리즈

목록 보기
1/2
post-thumbnail

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 권한을 가짐)


1. HAProxy 설치

  • 의존성 설치
$ sudo yum install gcc pcre-static pcre-devel -y
  • HAProxy 2.6.2 설치
$ 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
  • 특수권한 지정
    user 계정은 root 권한이 없기 때문에 haproxy 실행 시 root로 실행되도록 설정해야 한다.
$ sudo chown root:user haproxy
$ sudo chmod 6755 hapxory

2. HAProxy 설정 및 실행

  • haproxy.conf
    [backend servers]에 App1과 App2에 roundrobin 방식으로 로드밸런싱되도록 설정한다.
    ssl은 미리 생성해둔 openssl을 적용하였다.
# 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

0개의 댓글