1. 개요
HAProxy 1.8.19를 기준으로 함.
2. 다운로드
# wget http://www.haproxy.org/download/1.8/src/haproxy-1.8.19.tar.gz --2019-04-17 01:12:57-- http://www.haproxy.org/download/1.8/src/haproxy-1.8.19.tar.gz Resolving www.haproxy.org (www.haproxy.org)... 51.15.8.218 Connecting to www.haproxy.org (www.haproxy.org)|51.15.8.218|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 2080757 (2.0M) [application/x-tar] Saving to: ‘haproxy-1.8.19.tar.gz’ 100%[===================================================================================================>] 2,080,757 1.22MB/s in 1.6s 2019-04-17 01:12:59 (1.22 MB/s) - ‘haproxy-1.8.19.tar.gz’ saved [2080757/2080757]
# tar -xvzf haproxy-1.8.19.tar.gz
3. 설치
# make TARGET=linux2628 USE_PCRE=1 gcc -Iinclude -Iebtree -Wall -O2 -g -fno-strict-aliasing -Wdeclaration-after-statement -fwrapv -Wno-format-truncation -Wno-null-dereference -Wno-unused-label -DCONFIG_HAP_LINUX_SPLICE -DTPROXY -DCONFIG_HAP_LINUX_TPROXY -DCONFIG_HAP_CRYPT -DENABLE_POLL -DENABLE_EPOLL -DUSE_CPU_AFFINITY -DASSUME_SPLICE_WORKS -DUSE_ACCEPT4 -DNETFILTER -DUSE_THREAD -DUSE_SYSCALL_FUTEX -DUSE_PCRE -I/usr/local/include -DCONFIG_HAPROXY_VERSION=\"1.8.19\" -DCONFIG_HAPROXY_DATE=\"2019/02/11\" -c -o src/ev_poll.o src/ev_poll.c In file included from include/types/proxy.h:33:0, from include/types/global.h:33, from src/ev_poll.c:26: include/common/regex.h:31:10: fatal error: pcre.h: No such file or directory #include ^~~~~~~~ compilation terminated. make: *** [src/ev_poll.o] Error 1
PCRE 없어서 에러 발생했으므로 pcre 설치.
# yum install pcre-devel Loaded plugins: extras_suggestions, langpacks, priorities, update-motd amzn2-core | 2.4 kB 00:00:00 Resolving Dependencies --> Running transaction check ---> Package pcre-devel.x86_64 0:8.32-17.amzn2.0.2 will be installed --> Finished Dependency Resolution Dependencies Resolved ============================================================================================================================================= Package Arch Version Repository Size ============================================================================================================================================= Installing: pcre-devel x86_64 8.32-17.amzn2.0.2 amzn2-core 480 k Transaction Summary ============================================================================================================================================= Install 1 Package Total download size: 480 k Installed size: 1.4 M Is this ok [y/d/N]:
# make TARGET=linux2628 USE_PCRE=1
# make install install -d "/usr/local/sbin" install haproxy "/usr/local/sbin" install -d "/usr/local/share/man"/man1 install -m 644 doc/haproxy.1 "/usr/local/share/man"/man1 install -d "/usr/local/doc/haproxy" for x in configuration management architecture peers-v2.0 cookie-options lua WURFL-device-detection proxy-protocol linux-syn-cookies network-namespaces DeviceAtlas-device-detection 51Degrees-device-detection netscaler-client-ip-insertion-protocol peers close-options SPOE intro; do \ install -m 644 doc/$x.txt "/usr/local/doc/haproxy" ; \ done
* SSL 해야하면 추가 옵션 줘야함.
# make TARGET=linux2628 USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 USE_CRYPT_H=1 USE_LIBCRYPT=1
4. haproxy.cfg
cfg 파일은 기본 제공되지 않는다. 설치파일 내의 examples에서 가져오거나 혹은 인터넷 어딘가에서 적절한 샘플을 구해볼 것.
본인은 /etc/haproxy/haproxy,cfg로 만들었다. 실행할 때 cfg 파일 위치 지정하면 됨.
global daemon log 127.0.0.1 local0 log 127.0.0.1 local1 notice maxconn 4096 defaults log global retries 3 maxconn 2000 timeout connect 5s timeout client 50s timeout server 50s listen stats bind 127.0.0.1:9999 balance mode http stats enable frontend haproxy_front bind *:9000 mode http default_backend haproxy_back backend haproxy_back balance roundrobin mode http option forwardfor http-request set-header X-Forwarded-Port %[dst_port] server back1 127.0.0.1:80
option forwardfor 설정에 대해서는 여기를 확인하자.
5. 실행
# pwd /usr/local/sbin # ls -l total 6812 -rwxr-xr-x 1 root root 6975152 Apr 17 01:20 haproxy
# ./haproxy
HA-Proxy version 1.8.19 2019/02/11
Copyright 2000-2019 Willy Tarreau <이 이메일 주소가 스팸봇으로부터 보호됩니다. 확인하려면 자바스크립트 활성화가 필요합니다.>
Usage : haproxy [-f <cfgfile|cfgdir>]* [ -vdVD ] [ -n <maxconn> ] [ -N <maxpconn> ]
[ -p <pidfile> ] [ -m <max megs> ] [ -C <dir> ] [-- <cfgfile>*]
-v displays version ; -vv shows known build options.
-d enters debug mode ; -db only disables background mode.
-dM[<byte>] poisons memory with <byte> (defaults to 0x50)
-V enters verbose mode (disables quiet mode)
-D goes daemon ; -C changes to <dir> before loading files.
-W master-worker mode.
-q quiet mode : don't display messages
-c check mode : only check config files and exit
-n sets the maximum total # of connections (2000)
-m limits the usable amount of memory (in MB)
-N sets the default, per-proxy maximum # of connections (2000)
-L set local peer name (default to hostname)
-p writes pids of all children to this file
-de disables epoll() usage even when available
-dp disables poll() usage even when available
-dS disables splice usage (broken on old kernels)
-dR disables SO_REUSEPORT usage
-dr ignores server address resolution failures
-dV disables SSL verify on servers side
-sf/-st [pid ]* finishes/terminates old pids.
-x <unix_socket> get listening sockets from a unix socket
# ./haproxy -f /etc/haproxy/haproxy.cfg # ps -ef | grep haproxy root 30497 1 0 01:28 ? 00:00:00 ./haproxy -f /etc/haproxy/haproxy.cfg root 30503 28276 0 01:28 pts/0 00:00:00 grep --color=auto haproxy