The basic setup of failover or high availability requires two servers.
Consider the below setup for example
Master1 - 192.168.0.101
Slave1 - 192.168.0.103
Floating or Live ip address 192.168.0.105
Install keepalived on both the servers
# apt-get install keepalived
or
# yum install keepalived
Edit keepalived.conf on both the servers
# vim /etc/keepalived/keepalived.conf
######################################
Add below text on Master1 server
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 10
priority 200
virtual_ipaddress {
192.168.0.105
}
}
######################################
Add below text on Slave1 server
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 10
priority 100
virtual_ipaddress {
192.168.0.105
}
}
######################################
Start keepalived daemon on both the servers
# /etc/init.d/keepalived start
or
# service keepalived start
######################################
Check /var/log/syslog or /var/log/messages on both the servers you may find below lines
On Master Server
Keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE
Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE
On Slave Server
Keepalived_vrrp: VRRP_Instance(VI_1) Entering BACKUP STATE
######################################
Time to test
Shutdown the Master server and check /var/log/syslog on Slave server you will see below lines which states that the virtual or floating IP has been assigned to Slave server.
Keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE
Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE
Check the ip using ifconfig or ip addr command
# ifconfig
or
# ip addr
######################################
Now start the master server and check that the IP 192.168.0.105 has been assigned back to Master Server.
Check logs on both master and server, you may find below logs
On Master
Keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE
Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE
On Slave
Keepalived_vrrp: VRRP_Instance(VI_1) Received higher prio advert
Keepalived_vrrp: VRRP_Instance(VI_1) Entering BACKUP STATE
######################################
We have successfully implemented Keepalived with Failover setup
Consider the below setup for example
Master1 - 192.168.0.101
Slave1 - 192.168.0.103
Floating or Live ip address 192.168.0.105
Install keepalived on both the servers
# apt-get install keepalived
or
# yum install keepalived
Edit keepalived.conf on both the servers
# vim /etc/keepalived/keepalived.conf
######################################
Add below text on Master1 server
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 10
priority 200
virtual_ipaddress {
192.168.0.105
}
}
######################################
Add below text on Slave1 server
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 10
priority 100
virtual_ipaddress {
192.168.0.105
}
}
######################################
Start keepalived daemon on both the servers
# /etc/init.d/keepalived start
or
# service keepalived start
######################################
Check /var/log/syslog or /var/log/messages on both the servers you may find below lines
On Master Server
Keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE
Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE
On Slave Server
Keepalived_vrrp: VRRP_Instance(VI_1) Entering BACKUP STATE
######################################
Time to test
Shutdown the Master server and check /var/log/syslog on Slave server you will see below lines which states that the virtual or floating IP has been assigned to Slave server.
Keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE
Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE
Check the ip using ifconfig or ip addr command
# ifconfig
or
# ip addr
######################################
Now start the master server and check that the IP 192.168.0.105 has been assigned back to Master Server.
Check logs on both master and server, you may find below logs
On Master
Keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE
Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE
On Slave
Keepalived_vrrp: VRRP_Instance(VI_1) Received higher prio advert
Keepalived_vrrp: VRRP_Instance(VI_1) Entering BACKUP STATE
######################################
We have successfully implemented Keepalived with Failover setup