Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Implementing High Availability with Keepalived and VRRP

Tech 1

Keepalived Overview

Keepalived is a routing software written in C that provides load balancing and high availability capabilities for Linux systems and Linux-based infrastructures. The software achieves two primary functions:

  1. Load Balancing - Distributes network traffic across multiple servers
  2. High Availability - Uses VRRP (Virtual Router Redundancy Protocol) to ensure continuous service availability

VRRP allows multiple servers to share a virtual IP address (VIP), with automatic failover when the primary server becomes unavailable.

Installing Keepalived

Install Keepalived ussing the package manager:

yum install keepalived -y

Configuring Keepalived for High Availability

Primary Server Configuration

Edit the Keepalived configuration file:

vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
   notification_email {
     admin@domain.local
     failover@domain.local
     ops@domain.local
   }
   notification_email_from Keepalived@domain.local
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
   vrrp_skip_check_adv_addr
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}

vrrp_instance VI_1 {
    state MASTER
    interface ens33
    virtual_router_id 88
    priority 150
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass securepass123
    }
    virtual_ipaddress {
        192.168.178.188
    }
}

Secondary Server Configuration

Configure the backup server with a lower priority value:

vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
   notification_email {
     admin@domain.local
     failover@domain.local
     ops@domain.local
   }
   notification_email_from Keepalived@domain.local
   smtp_server 192.168.200.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
   vrrp_skip_check_adv_addr
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}

vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    virtual_router_id 88
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass securepass123
    }
    virtual_ipaddress {
        192.168.178.188
    }
}

Starting the Service

Start Keepalived on both servers and enable automatic startup:

systemctl start keepalived
systemctl enable keepalived

Verify the VIP assignment using:

ip addr show

The virtuall IP address should appear on the MASTER server. Configure your clients to connect using the VIP (192.168.178.188) rather than any individual server's IP.

Understanding VIP Failover

VIP failover is the mechanism that enables high availability. When the MASTER server experiences a failure—whether due to service interruption, network issues, or system downtime—the BACKUP server automatically assumes ownership of the virtual IP address and continues serving client requests.

This failover process is transparent to users, who continue accessing the service through the same VIP without needing to know which physical server is currently active. This approach eliminates single points of failure and ensures service continuity.

VIP failover is particularly valuable for environments requiring high availability, including web servers, database servers, and other critical infrastructure components.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.