To Gain Knowledge and to become a one, who all wants to become

Dreams are not those which are seen during sleep ,but Dreams are those which do not let you sleep,so see the dreams
and work hard to make them true.

Haproxy Load Balancer


Download the haproxy package and extract it
the cd haproxy-version
./configure
make
make install
cp the haproxy.cfg file from install-dir/examples/haproxy.cfg and edit it as below-

# this config needs haproxy-1.1.28 or haproxy-1.2.1

global
log 127.0.0.1 local0 //For logging
log 127.0.0.1 local1 notice
#log loghost local0 info
maxconn 4096
daemon
user haproxy
defaults
log global
mode http
option httplog
option dontlognull
retries 3
option redispatch
maxconn 2000
contimeout 5000
clitimeout 50000
srvtimeout 50000
stats enable //This enables the statstics of haproxy server and you can view it in browser by http://ipaddress/haproxy-status
stats uri /haproxy-status
stats auth user:passwd

listen appli1-rewrite 0.0.0.0:80
cookie SERVERID rewrite
mode http
balance source
server app1_2 192.168.1.8:80 cookie app1inst2 check inter 2000 rise 2 fall 5
server app1_1 192.168.1.7:80 cookie app1inst1 check inter 2000 rise 2 fall 5

option httpchk

Configuring logging

Edit /etc/sysconfig/syslog

SYSLOGD_OPTIONS=”-m 0 -r”

Edit /etc/syslog.conf. Add the following:

local0.* /var/log/haproxy.log

local1.* /var/log/haproxy-1.log

Restart Syslog

service syslog restart


Keep Alived Daemon

yum install keepalived
Keepalived Configuration File /etc/keepalived/keepalived.conf

vrrp_script chk_haproxy { # Requires keepalived-1.1.13
script "killall -0 haproxy" # cheaper than pidof
interval 0 # check every 2 seconds
weight 2 # add 2 points of prio if OK
}

vrrp_instance VI_1 {
interface eth0
state MASTER
virtual_router_id 51
priority 101 # 101 on master, 100 on backup
virtual_ipaddress {
192.168.1.9
}
track_script {
chk_haproxy
}
}