Operations 4 min read

Step-by-Step Guide to Building a Keepalived + Nginx High‑Availability Setup

This tutorial walks through preparing two servers, configuring Keepalived and Nginx on both master and backup nodes, restarting services, and testing failover to demonstrate a functional high‑availability architecture using VRRP virtual IPs.

Practical DevOps Architecture
Practical DevOps Architecture
Practical DevOps Architecture
Step-by-Step Guide to Building a Keepalived + Nginx High‑Availability Setup

1. Server environment preparation

Define four machines: 192.168.210.85 as the primary Nginx/Keepalived server, 192.168.210.177 as the secondary Nginx/Keepalived server, and 192.168.210.176 and 192.168.210.195 as backend services.

2. Configure the primary server (192.168.210.85)

[root@k8s-master1~]# vim /etc/keepalived/keepalived.conf
[root@k8s-master1~]# more /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
    notification_email {
        [email protected]
    }
}

vrrp_instance VI_1 {
    state MASTER
    interface ens33
    virtual_router_id 51
    priority 200
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.210.11
    }
}

vrrp_instance VI_2 {
    state BACKUP
    interface ens33
    virtual_router_id 52
    priority 150
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 2222
    }
    virtual_ipaddress {
        192.168.210.12
    }
}

Restart Keepalived and verify the virtual IP is active on the master node.

3. Configure the backup server (192.168.210.177)

[root@k8s-node1~]# vim /etc/keepalived/keepalived.conf
[root@k8s-node1~]# more /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
    notification_email {
        [email protected]
    }
}

vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    virtual_router_id 51
    priority 150
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.210.11
    }
}

vrrp_instance VI_2 {
    state MASTER
    interface ens33
    virtual_router_id 52
    priority 200
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 2222
    }
    virtual_ipaddress {
        192.168.210.12
    }
}

Restart Keepalived on the backup node and confirm the virtual IPs are now managed by the backup when the master is down.

4. Testing failover

Stop Keepalived on the master:

[root@k8s-master1~]# systemctl stop keepalived

Observe that the VIPs (192.168.210.11 and 192.168.210.12) are automatically taken over by the backup server, and both can still be accessed via Nginx. Restart the service to restore the original state.

Throughout the process, screenshots illustrate the IP status before and after failover, confirming that the high‑availability configuration works as expected.

High Availabilityload balancinglinuxNginxvrrpKeepalived
Practical DevOps Architecture
Written by

Practical DevOps Architecture

Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.