Install HA-Proxy for load-balansing on Centos

For load balasing my weebtraffic im setting up HA-proxy. The proxy recives reqest on one ip and then even loads the reqest between my web server nodes.

First install and enable Epel repo

yum install haproxy

open the configfile /etc/haproxy/haproxt.cfg and ad to the buttom of the file

listen http_web
 mode http
 balance roundrobin # Load Balancing algorithm
 option httpchk
 option forwardfor
 server server1 weight 1 maxconn 512 check
 server server2 weight 1 maxconn 512 check is my virtual if that i config in my heartbeat. And that ip will move beetween my two nodes if my first node goes down(You cant start haproxy if thet ip is not config on the server)

The server config says with two server i will use as load based webserver and the traffic will goes to does web nodes.

Restart haproxy now

/etc/init.d/haproxy restart

Now the problem i have the loadbalanser and my webnodes on the same host. And when i start haproxy it will recive connections on port 80. But my apache server would also like to use port 80.

for letting both haproxy and apache use port 80 i will lock them to there ip. So Hproxy will use ip and port 80. and apache vill use port 80. and they will both be on the same server node.


open up httpd config /etc/httpd/cond/httpd.conf and change Listen to


and now you can restart you apache

/etc/init.d/httpd restart

and we can see with netstat that it works

tcp 0 0* LISTEN 20101/httpd 
tcp 0 0* LISTEN 19857/haproxy

And now we have an load balasing webb server cluster. And if you use my previus post and HA and load balansing web system.