CentOS / Redhat Linux: Install Keepalived To Provide IP Failover For Web Cluster

Keepalived is a daemon that provides simple and robust facilities for load balancing and high-availability to Linux based infrastructures. It uses the VRRP (Virtual Router Redundancy Protocol) protocol to provide a highly available IP address to be used as a default gateway by clients. If the primary node goes down, Keepalived will automatically transfer the IP address to the secondary node. In this way, clients can still access the service while the primary node is down.

Here’s how to install and configure Keepalived on CentOS/RHEL to provide IP failover for a web cluster:

  1. Install Keepalived:
yum install keepalived
  1. Configure Keepalived: Edit the Keepalived configuration file, usually located at /etc/keepalived/keepalived.conf. Here is an example configuration that uses VRRP to provide IP failover for a web cluster:
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 101
advert_int 1
authentication {
auth_type PASS
auth_pass mypassword
}
virtual_ipaddress {
192.168.1.100/24 dev eth0
}
}

This configuration sets up a VRRP instance with ID 51, using the eth0 interface for communication. The virtual IP address that will be used for the web service is 192.168.1.100, with a netmask of 24 bits (or 255.255.255.0). The priority of this node is set to 101, which is higher than the default priority of 100, making it the primary node. The authentication section is optional and is used to provide a shared secret between the nodes to prevent unauthorized nodes from taking over the IP address.

  1. Start Keepalived:
systemctl start keepalived

That’s it! Keepalived will now provide IP failover for your web cluster. You can test this by shutting down the primary node and making sure that the secondary node takes over the IP address. You can also monitor the status of the VRRP instance using the ip command:

ip addr show

This should show the virtual IP address assigned to the active node in the VRRP instance.

Leave a Comment