Skip to content

What is Keepalived

homepage-banner

Introduction

In the world of networking, high availability is a critical factor that ensures continuous service delivery. In essence, the goal of high availability is to minimize downtime by ensuring that systems remain operational even in the event of a failure. A key component of high availability is the use of IP failover. IP failover allows for the seamless transfer of network traffic from a failed system to a standby system, ensuring that services remain available to end-users. In this post, we’ll explore how to implement IP failover using Keepalived.

High Availability (HA) is an essential feature that ensures that mission-critical services are always available. It is a requirement for most enterprise environments, where service uptime is crucial. Keepalived is a free, open-source software package that provides high availability by monitoring and managing services between two or more nodes. In this blog post, we will explore Keepalived and its usage example.

What is Keepalived?

Keepalived is a Linux-based software package that provides high availability for IP-based services. It enables multiple nodes to work together to provide a highly available service. Keepalived consists of two main components: the VRRP (Virtual Router Redundancy Protocol) and the health checker. VRRP is a protocol that provides automatic failover for IP services. It allows one node to take over the service if the primary node fails. The health checker monitors the services and checks their status at regular intervals. If a service fails, Keepalived will switch to another node that can provide the service.

Keepalived Overview

Keepalived is a software package that provides IP failover, load balancing, and monitoring capabilities. It is commonly used in high-availability environments to ensure the continuous delivery of services. Keepalived works by monitoring the health of a primary system and automatically transferring the IP address to a standby system in the event of a failure.

In a typical setup with IP failover, there is one primary Instance and one or more secondary Instances:

  • Primary (also called MASTER in keepalived): The primary Compute Instance contains the IP address you’d like to configure for IP failover.
  • Secondary (also called BACKUP in keepalived): The secondary Compute Instances are configured to use that IP address in the event the primary Instance stops responding.

Installing and Configuring Keepalived

This section covers the installation of the Keepalived software from your distribution’s repository. If you prefer to install it from source, refer to the official documentation. After installing Keepalived, the next step is to configure it for your specific IP failover scenario.

  1. Log in to your Compute Instance over SSH. Refer to “Connecting to a Remote Server Over SSH” for assistance.
  2. Install Keepalived by following the instructions for your system’s distribution.

    Ubuntu and Debian:

    sudo apt update && sudo apt upgrade
    sudo apt install keepalived
    

    CentOS 8 Stream, CentOS/RHL 8 (including derivatives such as AlmaLinux 8 and Rocky Linux 8), Fedora:

    sudo dnf upgrade
    sudo dnf install keepalived
    

    CentOS 7:

    sudo yum update
    sudo yum install keepalived
    
  3. Start editing a new Keepalived configuration file.

    sudo nano /etc/keepalived/keepalived.conf
    
  4. Enter the proper settings for your configuration into the file located at /etc/keepalived/keepalived.conf. Use the example below as a starting point, replacing the following items:

  • Replace $password with a secure password to use for this configuration instance. You should use the same password for each Compute Instance you configure.
  • Replace 192.0.2.1 with the IP address for which you’d like to enable failover.
vrrp_instance Instance1 {
    state MASTER
    interface eth0
    virtual_router_id 10
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass $password
    }
    virtual_ipaddress {
        192.0.2.1
    }
}

Note: If configuring IP failover on a VLAN IP, you may need to change the interface value from eth0 to eth1. You can find the Network Interface your VLAN may be using under the interface item in Configuration Options. For more configuration options, see Configuration Options.

To configure IP failover using keepalived, follow these steps:

  1. Enable and start the keepalived service using the following commands:

    sudo systemctl enable keepalived
    sudo systemctl start keepalived
    
  2. Repeat these steps on each secondary Compute Instance that you want to configure. Use the same configuration file as provided above, but make the following adjustments:

    • Set the state value to BACKUP.
    • Set the priority value to 99 or less, depending on the failover order you prefer for the secondary Compute Instances.

Testing the IP Failover Functionality

  1. Power off the primary Compute Instance.
  2. If you have configured IP failover for a public IP address, ping the IP address from your local machine. If you have configured IP failover on a private network, such as a VLAN, ping the IP address from another machine on that network.

    ping 192.0.2.1
    

    If IP failover is configured successfully, the output should be similar to the following (once the primary Compute Instance has fully powered off):

    64 bytes from 192.0.2.1: icmp_seq=3310 ttl=64 time=0.373 ms
    

    If instead, you receive output telling you that the host is unreachable, IP failover has likely not been configured successfully.

    From 192.0.2.1 icmp_seq=3293 Destination Host Unreachable
    

More Information

  • https://keepalived.readthedocs.io/en/latest/index.html
  • https://www.linode.com/docs/products/compute/compute-instances/guides/failover-legacy-keepalived/
Leave a message