Step 1 – Install Required Packages
Use the following command to install required packages to configure Keepalived on the server.
# yum install gcc kernel-headers kernel-devel
Step 2 – Install Keepalived
Keepalived is available in centos base repository. Install it using yum command line tool.
# yum install keepalived
Keepalived configuration File: /etc/keepalived/keepalived.conf
Server One
! Configuration File for keepalived
global_defs {
notification_email {
chouck@binghamton.edu
}
notification_email_from root@hanfs1.cc.binghamton.edu
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id hanfs1.cc.binghamton.edu
}
vrrp_instance VI_1 {
state MASTER
interface ens160
virtual_router_id 51
priority 101
advert_int 1
smtp_alert
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
128.226.136.106
}
}
Server Two
! Configuration File for keepalived
global_defs {
notification_email {
chouck@binghamton.edu
}
notification_email_from root@hanfs1.cc.binghamton.edu
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id hanfs1.cc.binghamton.edu
}
vrrp_instance VI_1 {
state BACKUP
interface ens160
virtual_router_id 51
priority 100
advert_int 1
smtp_alert
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
128.226.136.106
}
}
Step 5 – Start KeepAlived
Start KeepAlived service using the following command and also configure to autostart on system boot.
# service keepalived start
# chkconfig keepalived on
Step 6 – Check Virtual IPs
By default virtual IP will be assigned to master server, In case of master gets down, it will automatically assign to the slave server. Use the following command to show assigned virtual IP on the interface.
# ip addr show ens160
Step 7 - Servers must talk to each other
Enable IP forwarding:
# echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
# sysctl -p
net.ipv4.ip_forward = 1
Enable and start the keepalived service on each server:
# systemctl enable keepalived
# systemctl start keepalived
# systemctl status keepalived
Manual of sorts:
https://buildmedia.readthedocs.org/media/pdf/keepalived/stable/keepalived.pdf