How To install Load Balancer with HAProxy on Debian

Hi, today I want to discuss on how to install a LB for web servers base on http (linux or windows) on debian.

First we need to add the source of the installation to sources.list
# vi /etc/apt/sources.list

and add the following lines:
deb etch main
deb-src etch main

deb lenny main

deb etch/updates main contrib
deb-src etch/updates main contrib

Next we need to update the sources and install the HAproxy

# apt-get update
# apt-get install haproxy

First we backup the original configuration
# cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.orig
# cat /dav/null > /etc/haproxy/haproxy.cfg

and new we create a new configuration for our Round Robin LB.
edit the haproxy.cfg file and add the following lines:
# vi /etc/haproxy/haproxy.cfg
        log   local0
        log   local1 notice
        maxconn 4096
        user haproxy
        group haproxy

        log     global
        mode    http
        option  httplog
        option  dontlognull
        retries 3
        maxconn 2000
        contimeout      5000
        clitimeout      50000
        srvtimeout      50000

listen webfarm LB-IPAddress:80
       mode http
       stats enable
       stats auth someuser:somepassword
       balance roundrobin
       cookie JSESSIONID prefix
       option httpclose
       option forwardfor
       server webA serverA-IP:80 cookie A check
       server webB serverB-IP:80 cookie B check

make sure you change the RED lines to your settings.
and now we need to ENABLE the haproxy in /etc/default/haproxy
# vi /etc/default/haproxy
and set ENABLE=1

to start haproxy just run:
# /etc/init.d/haproxy start

that's it you have a Load Balancer Installed and work.

HAproxy Statistics:
In this configuration we enable the statistics of haproxy, you can acsses from you browser by enter http://LB-IPAddress/haproxy?stats

The user and the password is like you type in the configuration in "stats auth someuser:somepassword"

Enjoy and please comment !!!

1 comment:

  1. Thanks a lot. Just an error :

    cat /dav/null > /etc/haproxy/haproxy.cfg
    cat /dev/null > /etc/haproxy/haproxy.cfg

    dav => dev