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 192.168.44.20:80 mode http balance roundrobin # Load Balancing algorithm option httpchk option forwardfor server server1 192.168.44.21:80 weight 1 maxconn 512 check server server2 192.168.44.22:80 weight 1 maxconn 512 check
192.168.44.20 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 192.168.44.20 and port 80. and apache vill use 192.168.44.21 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
Listen 192.168.44.21:80
and now you can restart you apache
/etc/init.d/httpd restart
and we can see with netstat that it works
tcp 0 0 192.168.44.21:80 0.0.0.0:* LISTEN 20101/httpd tcp 0 0 192.168.44.20:80 0.0.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.