1. HAProxy 소개

- HAProxy는 TCP 및 HTTP 기반 애플리케이션에 대한 고가용성 및 로드 밸런싱을 제공하는 오픈 소스 소프트웨어 솔루션
- Reverse Proxy 기반으로 동작하고, Reverse Proxy, Load Balancer 기능 제공하며, Health Check 기능 제공
- HAProxy에는 관리자가 응용 프로그램의 성능을 실시간으로 추적할 수 있는 강력한 모니터링 도구가 제공됨

2. binary(tar.gz) 기반으로 HAProxy build 및 설정 파일 작성

테스트 수행한 환경

- 인터넷가능한 환경, rockylinux 8.6

1) haproxy build 하기

## 빌드를 위해 필요한 패키지 설치
[root@rocky8: /APP/binary_haproxy]# yum -y install make gcc perl pcre-devel zlib-devel openssl-devel
Rocky Linux 8 - AppStream                                                                                                           5.8 kB/s | 4.8 kB     00:00
Rocky Linux 8 - BaseOS                                                                                                              4.3 kB/s | 4.3 kB     00:01
Rocky Linux 8 - Extras                                                                                                              3.2 kB/s | 3.1 kB     00:00
Docker CE Stable - x86_64                                                                                                            26 kB/s | 3.5 kB     00:00
Extra Packages for Enterprise Linux 8 - x86_64                                                                                      4.4 kB/s | 6.8 kB     00:01
Extra Packages for Enterprise Linux 8 - x86_64                                                                                      7.2 MB/s |  14 MB     00:01
Dependencies resolved.

중간 생략..

Complete!

## haproxy-2.6.1 binary 파일 다운로드
[root@rocky8: /APP/binary_haproxy]# curl -O https://www.haproxy.org/download/2.6/src/haproxy-2.6.1.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 3882k  100 3882k    0     0   586k      0  0:00:06  0:00:06 --:--:--  894k

## 압축풀고 풀더로 이동
[root@rocky8: /APP/binary_haproxy]# tar -zxvf haproxy-2.6.1.tar.gz
중간 생략..
[root@rocky8: /APP/binary_haproxy]# cd haproxy-2.6.1
[root@rocky8: /APP/binary_haproxy/haproxy-2.6.1]# ls
addons  BRANCHES   CONTRIBUTING  doc       include  LICENSE      Makefile  reg-tests  src      tests    VERSION
admin   CHANGELOG  dev           examples  INSTALL  MAINTAINERS  README    scripts    SUBVERS  VERDATE

## make 하기
[root@rocky8: /APP/binary_haproxy/haproxy-2.6.1]# make -j$(nproc) TARGET=linux-glibc USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1
  CC      src/ev_poll.o
  CC      src/ev_epoll.o
  CC      src/cpuset.o
  중간 생략...
  CC      src/hash.o
  CC      src/dgram.o
  CC      src/version.o
  CC      dev/flags/flags.o
  LD      haproxy
  LD      dev/flags/flags

## 경로를 지정하여 install하기
[root@rocky8: /APP/binary_haproxy/haproxy-2.6.1]# make install PREFIX=/APP/binary_haproxy
install: creating directory '/APP/binary_haproxy/sbin'
'haproxy' -> '/APP/binary_haproxy/sbin/haproxy'
install: creating directory '/APP/binary_haproxy/share'
install: creating directory '/APP/binary_haproxy/share/man'
install: creating directory '/APP/binary_haproxy/share/man/man1'
'doc/haproxy.1' -> '/APP/binary_haproxy/share/man/man1/haproxy.1'
install: creating directory '/APP/binary_haproxy/doc'
install: creating directory '/APP/binary_haproxy/doc/haproxy'
'doc/configuration.txt' -> '/APP/binary_haproxy/doc/haproxy/configuration.txt'
'doc/management.txt' -> '/APP/binary_haproxy/doc/haproxy/management.txt'
'doc/seamless_reload.txt' -> '/APP/binary_haproxy/doc/haproxy/seamless_reload.txt'
'doc/architecture.txt' -> '/APP/binary_haproxy/doc/haproxy/architecture.txt'
'doc/peers-v2.0.txt' -> '/APP/binary_haproxy/doc/haproxy/peers-v2.0.txt'
'doc/regression-testing.txt' -> '/APP/binary_haproxy/doc/haproxy/regression-testing.txt'
'doc/cookie-options.txt' -> '/APP/binary_haproxy/doc/haproxy/cookie-options.txt'
'doc/lua.txt' -> '/APP/binary_haproxy/doc/haproxy/lua.txt'
'doc/WURFL-device-detection.txt' -> '/APP/binary_haproxy/doc/haproxy/WURFL-device-detection.txt'
'doc/proxy-protocol.txt' -> '/APP/binary_haproxy/doc/haproxy/proxy-protocol.txt'
'doc/linux-syn-cookies.txt' -> '/APP/binary_haproxy/doc/haproxy/linux-syn-cookies.txt'
'doc/SOCKS4.protocol.txt' -> '/APP/binary_haproxy/doc/haproxy/SOCKS4.protocol.txt'
'doc/network-namespaces.txt' -> '/APP/binary_haproxy/doc/haproxy/network-namespaces.txt'
'doc/DeviceAtlas-device-detection.txt' -> '/APP/binary_haproxy/doc/haproxy/DeviceAtlas-device-detection.txt'
'doc/51Degrees-device-detection.txt' -> '/APP/binary_haproxy/doc/haproxy/51Degrees-device-detection.txt'
'doc/netscaler-client-ip-insertion-protocol.txt' -> '/APP/binary_haproxy/doc/haproxy/netscaler-client-ip-insertion-protocol.txt'
'doc/peers.txt' -> '/APP/binary_haproxy/doc/haproxy/peers.txt'
'doc/close-options.txt' -> '/APP/binary_haproxy/doc/haproxy/close-options.txt'
'doc/SPOE.txt' -> '/APP/binary_haproxy/doc/haproxy/SPOE.txt'
'doc/intro.txt' -> '/APP/binary_haproxy/doc/haproxy/intro.txt'

[root@rocky8: /APP/binary_haproxy/haproxy-2.6.1]# cd ..

## /APP/binary_haproxy 경로에 컴파일된 파일이 생성됨
[root@rocky8: /APP/binary_haproxy]# ll
total 3888
drwxr-xr-x  3 root root      21 Apr 23 23:40 doc
drwxrwxr-x 13 root root    4096 Apr 23 23:40 haproxy-2.6.1
-rw-r--r--  1 root root 3976025 Apr 23 23:37 haproxy-2.6.1.tar.gz
drwxr-xr-x  2 root root      21 Apr 23 23:40 sbin
drwxr-xr-x  3 root root      17 Apr 23 23:40 share

2) haproxy 버전 정보 확인

[root@rocky8: /APP/binary_haproxy/sbin]# ./haproxy -version
HAProxy version 2.6.1-f6ca66d 2022/06/21 - https://haproxy.org/
Status: long-term supported branch - will stop receiving fixes around Q2 2027.
Known bugs: http://www.haproxy.org/bugs/bugs-2.6.1.html
Running on: Linux 4.18.0-425.19.2.el8_7.x86_64 #1 SMP Tue Apr 4 22:38:11 UTC 2023 x86_64

3) haproxy.cfg 설정파일 구성

- 8088포트로 apache 웹서버 구성후 8000포트로 들어온것을 8088, 8089포트로 보내는 설정으로 구성

[root@rocky8: /APP/binary_haproxy/sbin]# vi haproxy.cfg
global
  log /dev/log    local0
  log /dev/log    local1 notice
  maxconn 4096

defaults
  log global
  mode http
  option httplog
  option dontlognull
  timeout connect 5000
  timeout client 50000
  timeout server 50000

listen stats
  bind 0.0.0.0:7000
  mode http
  stats enable
  stats hide-version
  # stats scope .
  stats realm Haproxy\ Statistics
  stats uri /
  # stats page id/pwd, skip
  # stats auth user:pass

frontend web_balancer
  bind 0.0.0.0:8000
  mode http
  default_backend web_backends

backend web_backends
  mode http
  balance roundrobin  # roundrobin 알고리즘으로
  option forwardfor

  option httpchk GET /   # default health cheak
  server weba 10.0.2.131:8088 check inter 1s fastinter 500ms rise 1 fall 1 weight 1
  server webb 10.0.2.131:8089 check inter 1s fastinter 500ms rise 1 fall 1 weight 1

4) haproxy 가동 및 중지 스크립트 제작(백그라운드 데몬으로 구동되는 설정)

[root@rocky8: /APP/binary_haproxy/sbin]# vi start.sh
#!/bin/sh
/APP/binary_haproxy/sbin/haproxy -f /APP/binary_haproxy/sbin/haproxy.cfg -D -p /APP/binary_haproxy/sbin/haproxy.pid

[root@rocky8: /APP/binary_haproxy/sbin]# vi stop.sh
#!/bin/sh
kill -9 $(cat /APP/binary_haproxy/sbin/haproxy.pid)

3. HAProxy 구동 및 서비스 확인

1) haproxy 구동하기

## 구동하기
[root@rocky8: /APP/binary_haproxy/sbin]# ./start.sh


## 구동여부 체크
[root@rocky8: /APP/binary_haproxy/sbin]# ps -auxf | grep haproxy | grep -v grep
root       10022  0.0  0.0 257112  4060 ?        Ssl  00:11   0:00 /APP/binary_haproxy/sbin/haproxy -f /APP/binary_haproxy/sbin/haproxy.cfg -D -p /APP/binary_haproxy/sbin/haproxy.pid

[root@rocky8: /APP/binary_haproxy/sbin]# netstat -plnt | grep haproxy
tcp        0      0 0.0.0.0:7000            0.0.0.0:*               LISTEN      10022/haproxy
tcp        0      0 0.0.0.0:8000            0.0.0.0:*               LISTEN      10022/haproxy

2) 웹페이지 테스트결과

  • Health Check 와 웹페이지 접속이 roundrobin 방식으로 접속됨(로그로 확인)

3) HAProxy 통계 화면 조회내역

  • IP:7000 포트로 접속시 통계화면이 표기되어 로그를 보지 않더라도 실시간으로 통계 확인이 용이함

태그: ,

카테고리:

업데이트:

댓글남기기