High Availability (HA) on Linux Cloud Servers Using Keepalived & VRRP

  • Last Created On Sep 26, 2025
  • 23
0 0




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


🔹 Step 1: Install Keepalived

Ubuntu / Debian:

sudo apt update
sudo apt install keepalived -y

RHEL / AlmaLinux / Fedora:

sudo dnf install keepalived -y

🔹 Step 2: Configure the Master Node 💻

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


🔹 Step 3: Configure the Backup Node 💾

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


🔹 Step 4: Enable and Start Keepalived 🚀

Ubuntu / Debian:

sudo systemctl enable keepalived --now
sudo systemctl status keepalived

RHEL / AlmaLinux / Fedora:

sudo systemctl enable keepalived --now
sudo systemctl status keepalived

✅ Confirm the floating IP appears on the master server:

ip addr show eth0

🔹 Step 5: Test Failover 🔄

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.


🔹 Step 6: Monitor Logs & Status 📊

  • 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

🌐 Best Practices

  • 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


✅ Conclusion

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.



Views: 23

Recent Articles

  • Detecting Rootkits on Linux: Using rkhun...
    21
  • Load Balancing on Linux Cloud Servers Us...
    21
  • High Availability (HA) on Linux Cloud Se...
    23
  • How to Set Up a Firewall on Linux Cloud...
    22
  • How to Attach and Mount Volumes on Linux...
    36

Popular Articles

  • How to Fix “Error Establishing Database...
    238
  • How to Create a Linux Swap File (Step-by...
    46
  • How to Secure SSH Access on Linux Server...
    42
  • How to Attach and Mount Volumes on Linux...
    36
  • Timeshift Installation and Configuration...
    36
!-- Floating WhatsApp Button --> WhatsApp Chat