The cart is empty

Continuous operation of IT services is a necessity for most businesses and organizations today. High Availability (HA) and automatic failover are key concepts that help minimize downtime and ensure smooth operation of critical systems. Keepalived is one of the tools enabling the implementation of these concepts on the Debian operating system. This article provides a detailed insight into configuring Keepalived for high availability and failover.

What is Keepalived and How Does it Work?

Keepalived is software that utilizes the standard Linux virtual server (LVS) to manage failover and provide high availability through the Virtual Router Redundancy Protocol (VRRP). Keepalived detects failures on the primary server and automatically redirects traffic to the backup server, ensuring uninterrupted service availability.

Environment Preparation

Before initiating configuration, it's crucial to have at least two servers running the Debian operating system, connected to the network and capable of communicating with each other. Each server should have a statically assigned IP address and sufficient privileges for installing packages and modifying configuration files.

Installing Keepalived

To install Keepalived on Debian, use the package manager apt. Open a terminal and execute the following command:

sudo apt-get update && sudo apt-get install keepalived

This command will install Keepalived along with all necessary dependencies.

Configuring Keepalived for High Availability

The configuration file for Keepalived is typically located at /etc/keepalived/keepalived.conf. To ensure HA, this file needs to be modified to include definitions for VRRP instances and virtual IP addresses used for accessing services.

Creating a VRRP Instance

A VRRP instance allows defining a group of servers for failover. The instance configuration may look like this:

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.1.10
    }
}

In this example, the server is configured as MASTER with a priority of 100. The IP address 192.168.1.10 is a virtual address assigned to the active server.

Configuring the Backup Server

The configuration on the backup server is similar but with a lower priority to ensure the primary server always takes precedence:

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 50
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.1.10
    }
}

Testing and Debugging Configuration

After configuring both servers, it's essential to test the configuration. This includes verifying that the virtual IP address is correctly assigned to the active server and simulating server failure to ensure automatic failover to the backup server.

Keepalived offers logging to syslog, which can aid in diagnosing issues. Logging can be enabled by modifying the configuration file and setting the logging level.

Implementing high availability and failover using Keepalived on Debian is an effective way to secure critical services against unplanned outages. With its flexibility and straightforward configuration, Keepalived is a suitable solution for a wide range of applications.