Implementing High Availability with Keepalived and VRRP
Keepalived Overview
Keepalived is a routing software written in C that provides load balancing and high availability capabilities for Linux systems and Linux-based infrastructures. The software achieves two primary functions:
- Load Balancing - Distributes network traffic across multiple servers
- High Availability - Uses VRRP (Virtual Router Redundancy Protocol) to ensure continuous service availability
VRRP allows multiple servers to share a virtual IP address (VIP), with automatic failover when the primary server becomes unavailable.
Installing Keepalived
Install Keepalived ussing the package manager:
yum install keepalived -y
Configuring Keepalived for High Availability
Primary Server Configuration
Edit the Keepalived configuration file:
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
admin@domain.local
failover@domain.local
ops@domain.local
}
notification_email_from Keepalived@domain.local
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 88
priority 150
advert_int 1
authentication {
auth_type PASS
auth_pass securepass123
}
virtual_ipaddress {
192.168.178.188
}
}
Secondary Server Configuration
Configure the backup server with a lower priority value:
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
admin@domain.local
failover@domain.local
ops@domain.local
}
notification_email_from Keepalived@domain.local
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 88
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass securepass123
}
virtual_ipaddress {
192.168.178.188
}
}
Starting the Service
Start Keepalived on both servers and enable automatic startup:
systemctl start keepalived
systemctl enable keepalived
Verify the VIP assignment using:
ip addr show
The virtuall IP address should appear on the MASTER server. Configure your clients to connect using the VIP (192.168.178.188) rather than any individual server's IP.
Understanding VIP Failover
VIP failover is the mechanism that enables high availability. When the MASTER server experiences a failure—whether due to service interruption, network issues, or system downtime—the BACKUP server automatically assumes ownership of the virtual IP address and continues serving client requests.
This failover process is transparent to users, who continue accessing the service through the same VIP without needing to know which physical server is currently active. This approach eliminates single points of failure and ensures service continuity.
VIP failover is particularly valuable for environments requiring high availability, including web servers, database servers, and other critical infrastructure components.