Load Balance Webserver + HAProxy On Centos 6.2 / 64 bit

“HAProxy is a free, very fast and reliable solution offering high availability, load balancing, and proxying for TCP and HTTP-based applications. It is particularly suited for web sites crawling under very high loads while needing persistence or Layer7 processing. Supporting tens of thousands of connections is clearly realistic with todays hardware. Its mode of operation makes its integration into existing architectures very easy and riskless, while still offering the possibility not to expose fragile web servers to the Net.” reff http://www.howtoforge.com/setting-up-a-high-availability-load-balancer-with-haproxy-keepalived-on-debian-lenny



Server : berfungsi sebagai load balancer ( server inilah yang akan di akses oleh client)

Server : & sebagai web server, sekaligus tempat aplikasi web yang akan di akses. so pastikan sudah terinstall paket apache.


Install haproxy (sesuaikan dengan versi nya apakah menggunakan 32 or 64 bit)

[root@svrrepo ~]# rpm -ivh http://mirrors.ispros.com.bd/fedora-epel/6/x86_64/epel-release-6-7.noarch.rpm

[root@svrrepo ~]# yum search haproxy
haproxy.x86_64 : HA-Proxy is a TCP/HTTP reverse proxy for high availability environments
[root@svrrepo ~]# yum install haproxy.x86_64
Setelah proses instalasi ini maka akan membentuk satu user haproxy di /etc/passwd
[root@svrrepo haproxy]# cat /etc/passwd
haproxy:x:497:497:HAProxy user:/var/lib/haproxy:/bin/false

[root@svrrepo ~]# cd /etc/haproxy/
Backup config aslinya

[root@svrrepo haproxy]# cp haproxy.cfg haproxy.cfg.def

[root@svrrepo html]# vim /etc/haproxy/haproxy.cfg

#tambahkan baris berikut

listen SVR253 # ip server load balancer
mode http
balance roundrobin
cookie JSESSIONID prefix
option httpchk HEAD /check.txt HTTP/1.0
option httpclose
option forwardfor
stats auth testing1:testing1 #username untuk authentikasi untuk mengakses statistic haproxy
server server7 check cookie A check  # ip server web server1
server server11 check cookie B check # ip server web server 2

save wq!

check configurasi valid or not
[root@svrrepo haproxy]# haproxy -f /etc/haproxy/haproxy.cfg -c
Restart service

[root@svrrepo haproxy]#service haproxy start

Register sebagai service (runlevel) so boot pada saat startup server

[root@svrrepo haproxy]#chkconfig haproxy on

Login ke server &

[root@server11 ~]# vim /var/www/html/index.php
<?php phpinfo();?>
[root@telephony ~]# vim /var/www/html/index.php
<?php phpinfo();?>

harusnya sudah muncul isi dari phpinfo();

Untuk memonitor apakah loadbalancing sudah jalan maka akses dan login dengan username sesuai dengan config yang ada di haproxy.conf (testing1:testing1)

Coba amati log di server & dengan command tail -f /var/log/http/access.log, kemudian matikan salah satu webserver apa yang terjadi??? Juga amati Bytes IN/Out pada monitoring:D


One thought on “Load Balance Webserver + HAProxy On Centos 6.2 / 64 bit

  1. Willy Tarreau May 28, 2012 at 7:04 pm Reply

    You should use “option http-server-close” instead of “option httpclose”, it will enable HTTP keep-alive on the client side which is nicer to users connected behind high latency networks (eg: smartphones).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s


Listens until think alike

moses.spaceku@yahoo.com / voip ipbx


%d bloggers like this: