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.

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

and add the following lines:
deb http://ftp2.de.debian.org/debian/ etch main
deb-src http://ftp2.de.debian.org/debian/ etch main

deb http://ftp2.de.debian.org/debian/ lenny main

deb http://security.debian.org/ etch/updates main contrib
deb-src http://security.debian.org/ etch/updates main contrib

Next we need to update the sources and install the HAproxy

# apt-get update
# apt-get install haproxy

Configuration:
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
global
        log 127.0.0.1   local0
        log 127.0.0.1   local1 notice
        maxconn 4096
        user haproxy
        group haproxy

defaults
        log     global
        mode    http
        option  httplog
        option  dontlognull
        retries 3
        redispatch
        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 !!!



2 comments:

  1. Thanks a lot. Just an error :

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

    dav => dev

    ReplyDelete
  2. What's up, after reading this amazing article i am too glad to share my know-how here with colleagues.

    ReplyDelete