The cart is empty

In today's digital era, uninterrupted operation of critical services is essential for most businesses. Any downtime can have serious financial and reputational consequences. In this context, technologies for ensuring high availability (HA) and automatic failover play a crucial role. Keepalived is one such solution that provides both of these functions, allowing for the continuous operation of services. This article provides an overview of configuring Keepalived on Debian systems to achieve these goals.

What is Keepalived and How Does it Work

Keepalived is a software package that utilizes Linux virtual server (LVS) for providing high availability (HA) and failover solutions for Linux servers. The primary goal of Keepalived is to ensure service continuity by automatically switching to a backup server in case of primary server failure. Keepalived achieves this using the Virtual Router Redundancy Protocol (VRRP), which allows multiple servers to share a single virtual IP address. This ensures high service availability because users and systems can continue accessing the service even if one server fails.

Installing Keepalived on Debian

Before configuring Keepalived, it is necessary to install it on all servers that will be part of the HA cluster. Installation on Debian (or its derivatives) is done using the APT package manager:

sudo apt update
sudo apt install keepalived

Configuring Keepalived for HA and Failover

Configuring Keepalived involves several steps to ensure that your services are highly available with automatic failover.

  1. Basic Keepalived Configuration

The Keepalived configuration file is typically located at /etc/keepalived/keepalived.conf. This file needs to be edited on all servers in your cluster.

Primary Server:

In the configuration file, set the primary server as master. This means that this server will normally handle all traffic as long as it operates without issues.

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

Backup Server:

On the backup server, configure the configuration file to set the server as BACKUP with lower priority than the primary server.

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

 

After configuring Keepalived on both servers, it's important to perform tests to verify failover functionality. You can simulate a primary server failure and observe whether automatic switching to the backup server occurs.

Maintenance and Monitoring

To ensure the best possible operation, it's crucial not only to configure Keepalived correctly but also to regularly monitor the cluster's status and perform preventive maintenance. There are various tools and procedures for monitoring and diagnostics that can help identify and address potential issues before a service outage occurs.

By incorporating Keepalived into your infrastructure for critical services, you can significantly reduce the risk of downtime and ensure that your services are always available to users and customers.