Friday, October 4, 2013

Setup HAProxy Load Balancer on Ubuntu

Today I need to setup HAProxy Load Balance on Ubuntu. I think this month most of my task is on the clustering, load balance and HA. Last 2 weeks, I just finish my cluster for hyper-v. Luckily it's working very well.

Ok let go to the point...

1. Install HAProxy into Ubuntu Server.

# apt-get install haproxy

2. Change the HAProxy configuration. 

# nano etc/haproxy/haproxy.cfg

3. Add following text to file and save it

global
        log 127.0.0.1   daemon debug
        #log 127.0.0.1  local0
        #log 127.0.0.1  local1 notice
        #log loghost    local0 info
        stats socket /tmp/stats
        maxconn 4096
        pidfile /var/run/haproxy.pid
        #chroot /usr/share/haproxy
        #user haproxy
        #group haproxy
        daemon
        #debug
        #quiet

defaults
        log     global
        mode    http
        option  httplog
        option  dontlognull
        retries 3
        option redispatch
        maxconn 3000
        contimeout      5000
        clitimeout      50000
        srvtimeout      50000


listen  webcluster *:80
        mode http
        stats enable
        stats uri /stats           //default using http://web.domain.com/haproxy?stats
        stats auth admin:p@ssw0rd
        balance roundrobin
        option httpchk HEAD / HTTP/1.0
        option forwardfor
        cookie LSW_WEB insert
        option httpclose
        server  192.18.250.22 192.18.250.22:80 check inter 5000 fastinter 1000 fall 1 weight 1
        #server web1 192.18.250.22:80 weight 1 fastinter 5000 rise 2 fall 3
        server  192.18.250.23 192.18.250.23:80 check inter 5000 fastinter 1000 fall 1 weight 1
        #server web2 192.18.250.23:80 weight 1 fastinter 5000 rise 2 fall 3
        option  httpclose               # disable keep-alive
        option  checkcache              # block response if set-cookie & cacheable

        rspidel ^Set-cookie:\ IP=       # do not let this cookie tell our internal IP address

        #errorloc       502     http://192.168.114.58/error502.html
        #errorfile      503     /etc/haproxy/errors/503.http
        errorfile       400     /etc/haproxy/errors/400.http
        errorfile       403     /etc/haproxy/errors/403.http
        errorfile       408     /etc/haproxy/errors/408.http
        errorfile       500     /etc/haproxy/errors/500.http
        errorfile       502     /etc/haproxy/errors/502.http
        errorfile       503     /etc/haproxy/errors/503.http
        errorfile       504     /etc/haproxy/errors/504.http


3. Setting startup parameter for HAProxy set enabled as 1 to start HAproxy

# nano /etc/default/haproxy

4. Start HAProxy form command line

# /etc/init.d/haproxy start

5. Access Web user interface from browser

http://web.domain.com/stats




No comments:

Post a Comment