Ever had that heart-stopping moment when your website goes down? Or that frantic call from users who can’t access your application?
High availability doesn’t have to be complicated or expensive. Enter Keepalived: your friendly neighbourhood service guardian!
What is Keepalived? 
Keepalived is like that reliable friend who always has your back. It’s an open-source tool designed to provide high availability for Linux systems by automatically failing over to backup servers when your primary server gets into trouble.
At its core, Keepalived implements the Virtual Router Redundancy Protocol (VRRP), which allows multiple servers to share a virtual IP address. When one server fails, another takes over seamlessly—like a superhero swooping in to save the day!
Why You’ll Love Keepalived 
- Simple yet powerful: Does one thing and does it well
- Lightweight: Minimal resource usage
- Battle-tested: Used in production environments worldwide
- Free and open-source: No licensing headaches!
Installing Keepalived 
Let’s get Keepalived up and running on your Linux system:
Ubuntu/Debian
sudo apt update
sudo apt install keepalived
CentOS/RHEL
sudo yum install keepalived
Verification
Check if Keepalived is installed correctly:
keepalived --version
You should see version information displayed. Success!
Setting Up Your First High-Availability Pair 
Let’s say you have two web servers that you want to configure for high availability. Here’s how to do it:
Create the Configuration File 
Primary Server Configuration /etc/keepalived/keepalived.conf
vrrp_instance WEB_HA {
state MASTER
interface eth0 # Your network interface
virtual_router_id 51
priority 101 # Higher number = higher priority
advert_int 1
authentication {
auth_type PASS
auth_pass yourpassword # Same on both servers
}
virtual_ipaddress {
192.168.1.100 # Your virtual IP address
}
}
Secondary Server Configuration /etc/keepalived/keepalived.conf
vrrp_instance WEB_HA {
state BACKUP
interface eth0 # Your network interface
virtual_router_id 51
priority 100 # Lower priority than the MASTER
advert_int 1
authentication {
auth_type PASS
auth_pass yourpassword # Same password as primary
}
virtual_ipaddress {
192.168.1.100 # Same virtual IP as primary
}
}
The main differences are:
state
is set to BACKUP instead of MASTERpriority
is lower (100 instead of 101)
Start the Service 
On both primary and backup servers:
sudo systemctl enable keepalived
sudo systemctl start keepalived
Test Your Setup 
On your primary server, check if the virtual IP is assigned:
ip addr show eth0 #modify accordingly
You should see your virtual IP (192.168.1.100) listed.
Now for the fun part: simulate a failure by stopping Keepalived on your primary server:
sudo systemctl stop keepalived
Check your secondary server—it should now have the virtual IP! Your services remain accessible without any downtime.
Beyond Basic Failover: Getting Creative with Keepalived 
Keepalived isn’t just about IP failover. You can use it to:
Monitor Specific Services 
Add health checks to ensure your web server is actually running:
vrrp_script check_web {
script "curl -f http://localhost/ >/dev/null"
interval 2
weight 2
}
vrrp_instance WEB_HA {
# ... other settings ...
track_script {
check_web
}
}
Load Balancing 
Combine Keepalived with LVS (Linux Virtual Server) for load balancing:
virtual_server 192.168.1.100 80 {
delay_loop 6
lb_algo rr
lb_kind NAT
protocol TCP
real_server 192.168.1.101 80 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.1.102 80 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
Troubleshooting Tips 
If things aren’t working as expected:
- Check logs:
sudo journalctl -u keepalived
- Verify network: Ensure your servers can communicate
- Firewall rules: Make sure VRRP traffic (protocol 112) is allowed
- Interface names: Double-check your network interface names
The Bottom Line 
Keepalived gives you enterprise-level high availability with minimal setup. It’s like insurance for your services—you hope you never need it, but you’ll be incredibly grateful when you do!
Whether you’re running a small blog or a mission-critical application, Keepalived helps ensure your services stay accessible when hardware or software decides to take an unexpected vacation.
Give it a try—your future self (and your users) will thank you when that inevitable server hiccup happens!