is a load balancer application that permits you to proxy HTTP and TCP connections to a group of back-end servers;
KeepAlived permit you to create a redundant pair of HAProxy servers by moving an IP address between HAProxy hosts in an active-passive configuration.
LB1 Server: 172.10.10.2 ( eth0 )
LB2 Server: 172.10.10.3 ( eth0 )
Webserver1 172.10.10.4
Webserver2 172.10.10.5
Virtual IP: 172.10.10.1
We are going to start Apache Load Balancing and Failover with Haproxy and KeepAlive.
Edit Keepalived configuration File: /etc/keepalived/keepalived.conf
script “killall -0 haproxy”
interval 2
weight 2
}
vrrp_instance VI_1 {
interface eth0
state MASTER
virtual_router_id 51
priority 101 # 101 on master, 100 on backup
virtual_ipaddress {
172.10.10.1
}
track_script {
chk_haproxy
}
}
Do the same configuration LB2
Start KeepAlived
Start KeepAlived service by following command and also set it to auto start on system boot time.
# chkconfig keepalived on
To start it on LB2 you have to down LB1 first so that the virtual IP moves to LB2 or make the following kernel change:
By default virtual ip will assigned to master server, In case of master server gets down, virtual ip will automatically assigned to slave server. Use following command to show assigned virtual ip on interface.
link/ether 00:0c:29:6f:ed:60 brd ff:ff:ff:ff:ff:ff
inet 172.10.10.2/24 brd 172.10.10.255 scope global eth0
inet 192.168.10.121/32 scope global eth0
inet6 fe80::20c:29ff:fe6f:ed60/64 scope link
valid_lft forever preferred_lft forever
1. Shutdown master server ( LB1 ) and check if ips are automatically assigned to slave server.
1. Now start LB1 and stop slave server ( LB2 ). IPs will automatically assigned to master server.
1. Watch log files to insure its working
May 19 17:30:25 localhost Keepalived_vrrp[6958]: VRRP_Instance(VI_1) Entering MASTER STATE
May 19 17:30:25 localhost Keepalived_vrrp[6958]: VRRP_Instance(VI_1) setting protocol VIPs.
May 19 17:30:25 localhost Keepalived_healthcheckers[6957]: Netlink reflector reports IP 172.10.10.1added
May 19 17:30:25 localhost avahi-daemon[1407]: Registering new address record for 172.10.10.1 on eth0.IPv4.
May 19 17:30:25 localhost Keepalived_vrrp[6958]: VRRP_Instance(VI_1) Sending gratuitous ARPs on
Open and edit haproxy configuration /etc/haproxy/haproxy.cfg
log 127.0.0.1 local7 info
maxconn 4096
user haproxy
group haproxy
daemon
#debug
#quiet
defaults
log global
mode http
option httplog
option dontlognull
retries 3
option redispatch
maxconn 2000
contimeout 5000
clitimeout 50000
srvtimeout 50000
listen webfarm 172.10.10.1:80
mode http
balance roundrobin
cookie JSESSIONID prefix
option httpclose
option forwardfor
option httpchk HEAD /index.html HTTP/1.0
server web01 172.10.10.4:80 cookie A check
server web02 172.10.10.5:80 cookie B check
listen https 172.10.10.1:443
mode http
option tcplog
balance roundrobin
maxconn 10000
server web01 172.10.10.4:443 cookie A check
server web02 172.10.10.5:443 cookie B check
Restart Haproxy Service
Optional
Cookies Insert Method
Cookie SRVNAME insert
server web01 172.10.10.4:80 cookie 01 check
server web02 172.10.10.5:80 cookie 02 check
server web01 172.10.10.4:443 cookie 01 check
server web02 172.10.10.5:443 cookie 02 check