Maintaining uptime for cloud servers is critical. Keepalived combined with VRRP (Virtual Router Redundancy Protocol) allows you to set up automatic failover between two or more Linux servers.
This guide walks through:
✅ Installing Keepalived
✅ Configuring master and backup nodes
✅ Assigning a floating IP
✅ Testing failover
sudo apt update
sudo apt install keepalived -y
sudo dnf install keepalived -y
Edit Keepalived configuration:
sudo nano /etc/keepalived/keepalived.conf
Add the following for the Master:
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 101
advert_int 1
authentication {
auth_type PASS
auth_pass cloud123
}
virtual_ipaddress {
192.168.1.100
}
}
Explanation:
state MASTER
→ Primary node
priority 101
→ Higher than backup
virtual_ipaddress
→ Floating IP shared between servers
interface
→ Use your server’s network interface
On the backup server, edit /etc/keepalived/keepalived.conf
:
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass cloud123
}
virtual_ipaddress {
192.168.1.100
}
}
Notes:
state BACKUP
→ Secondary node
priority 100
→ Lower than master
VRRP ensures floating IP moves to backup if master fails
sudo systemctl enable keepalived --now
sudo systemctl status keepalived
sudo systemctl enable keepalived --now
sudo systemctl status keepalived
✅ Confirm the floating IP appears on the master server:
ip addr show eth0
1️⃣ Stop Keepalived on master node:
sudo systemctl stop keepalived
2️⃣ Check the floating IP on the backup node:
ip addr show eth0
✅ The IP 192.168.1.100
should now be assigned to backup.
3️⃣ Restart master node:
sudo systemctl start keepalived
✅ Floating IP returns to master automatically.
View logs for Keepalived events:
sudo tail -f /var/log/syslog # Ubuntu/Debian
sudo tail -f /var/log/messages # RHEL/AlmaLinux
Check VRRP instance status:
sudo systemctl status keepalived
Use strong authentication passwords (auth_pass
)
Ensure same Keepalived version on all nodes
Test failover regularly
Combine with firewall rules and cloud security groups
Use private IPs for VRRP traffic to reduce latency
By implementing Keepalived with VRRP:
Master and backup nodes share a floating IP
Services remain online even if one server fails
Automated failover ensures high availability for cloud applications
🚀 Perfect for production-grade cloud deployments where uptime is critical.