yum install keepalived
vi /etc/keepalived/keepalived.conf
<code>
vrrp_script chk_haproxy {
script "pidof haproxy"
interval 2
}
vrrp_instance VI_1 {
debug 2
interface eth0 # interface to monitor
state MASTER
virtual_router_id 51 # Assign one ID for this route
priority 101 # 101 on master, 100 on backup
unicast_src_ip x.x.x.x # My IP
unicast_peer {x.x.x.x # Peer IP}
track_script {chk_haproxy}
virtual_ipaddress {x.x.x.x dev eth0}
}
</code>
Backup
vi /etc/keepalived/keepalived.conf
<code>
vrrp_script chk_haproxy {
script "pidof haproxy"
interval 2
}
vrrp_instance VI_1 {
debug 2
interface eth0 # interface to monitor
state BACKUP
virtual_router_id 51 # Assign one ID for this route
priority 100 # 101 on master, 100 on backup
unicast_src_ip x.x.x.x # My IP
unicast_peer {x.x.x.x # Peer IP}
track_script {chk_haproxy}
virtual_ipaddress {x.x.x.x dev eth0}
}
</code>
ip a