Load Balancing & Failover using HAProxy for RHEL | Cent Os | Ubuntu | Debian

HAProxy is open source proxy that can be used to enable high availability and load balancing for web applications. it was designed especially for high load projects so it is very fast and predictable, HAProxy is based on single-process model.

The following diagram summarizes the architecture:

This Package available on epel repository :

1.Install HAproxy and enable it's service on boot:
#yum install haproxy -y
#chkconfig haproxy on

If you’re Ubuntu, Debian or Linux Mint user use this one instead:
#apt-get install haproxy

2.It's time to edit our configuration file:

# vim /etc/haproxy/haproxy.cfg 
user daemon
group daemon
log daemon

listen http
bind # this is public external external.
mode http
option tcplog

log global
option dontlognull

balance roundrobin
clitimeout 60000
srvtimeout 60000
contimeout 5000
retries 3
server web1 web1.example.com:80 check # webserver-1
server web2 web2.example.com:80 check # webserver-2
cookie web1 insert nocache
cookie web2 insert nocache

3.Save the file and restart HAproxy:

#/etc/init.d/haproxy restart

4. Check that HAproxy, which is listen public ip on port 80 via:

#lsof -i :80
haproxy 32607 haproxy 4u IPv4 134165 0t0 TCP server01:http (LISTEN)

Test on your web browser & refresh more time;

Post a Comment

Mới hơn Cũ hơn