본문 바로가기

Ryu's Tip

HAPROXY 1.7 설치 및 테스트





yum install -y pcre-devel gcc


wget http://www.haproxy.org/download/1.7/src/haproxy-1.7.0.tar.gz

tar xvzf haproxy-1.7.0.tar.gz


cd haproxy-1.7.0

make TARGET=linux2628 ARCH=x86_64 USE_PCRE=1


mv haproxy /usr/sbin/



설치 부분

USE-PCRE 부분 설명


If your system supports PCRE (Perl Compatible Regular Expressions), then you
really should build with libpcre which is between 2 and 10 times faster than
other libc implementations. Regex are used for header processing (deletion,
rewriting, allow, deny). The only inconvenient of libpcre is that it is not
yet widely spread, so if you build for other systems, you might get into
trouble if they don't have the dynamic library. In this situation, you should
statically link libpcre into haproxy so that it will not be necessary to
install it on target systems. Available build options for PCRE are :

  - USE_PCRE=1 to use libpcre, in whatever form is available on your system
    (shared or static)

  - USE_STATIC_PCRE=1 to use a static version of libpcre even if the dynamic
    one is available. This will enhance portability.

  - with no option, use your OS libc's standard regex implementation (default).
    Warning! group references on Solaris seem broken. Use static-pcre whenever
    possible.

If your system doesn't provide PCRE, you are encouraged to download it from
http://www.pcre.org/ and build it yourself, it's fast and easy.




실행부분

설정 내용은 80포트 받아서 아래 두 서버로 round robin으로 로드밸런싱 해주는 설정



[root@lb-gw ~]# cat configuration.haproxy
global
        daemon
        maxconn 4096

defaults
        mode http
        timeout connect 5000ms
        timeout client 50000ms
        timeout server 50000ms

frontend http-in
        bind *:80
        default_backend servers

backend servers
        balance roundrobin
        server server1 172.17.17.188:80 maxconn 2048
        server server2 172.17.17.189:80 maxconn 2048


-c 옵션을 이용해 컨피그 파일 valid 체크 후 이상 없으면 실행



[root@lb-gw ~]# haproxy -f configuration.haproxy -c
Configuration file is valid
[root@lb-gw ~]# haproxy -f configuration.haproxy



실행 후 확인 및 체크



[root@lb-gw ~]#
[root@lb-gw ~]# ps -ef | grep haproxy
root     12011     1  0 17:45 ?        00:00:00 haproxy -f configuration.haproxy
root     12037  2189  0 17:59 pts/0    00:00:00 grep --color=auto haproxy
[root@lb-gw ~]#
[root@lb-gw ~]#
[root@lb-gw ~]# netstat -anp | grep haproxy
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      12011/haproxy      
[root@lb-gw ~]#


실제 로드밸런싱 동작 체크



[root@admin ~]# for i in {1..10}; do curl 172.17.17.198; done
SVR2
SVR1
SVR2
SVR1
SVR2
SVR1
SVR2
SVR1
SVR2
SVR1
[root@admin ~]# curl 172.17.17.198
SVR2
[root@admin ~]# curl 172.17.17.198
SVR1
[root@admin ~]#