Back to articles
DevOps & Systems

Configure VPS High Availability with Keepalived and Floating IP: Comprehensive Guide for Enterprises

Detailed guide to setting up VPS high availability using Keepalived and Floating IP to ensure high system uptime for businesses. Includes setup, testing, and troubleshooting.

DPTCloud Engineering4 min read
Configure VPS High Availability with Keepalived and Floating IP: Comprehensive Guide for Enterprises

Image credit: cegoh · Pixabay Content License

Configure VPS High Availability with Keepalived and Floating IP

To ensure high system availability and prevent service disruptions, businesses need to build a high availability (HA) system for their VPS servers. One popular solution is using Keepalived combined with a Floating IP to automatically switch services when the primary server fails. This guide provides a comprehensive walkthrough for setting up an HA system for enterprises on a VPS platform.

1. Introduction to Keepalived and Floating IP

Keepalived is an open-source tool used to manage the status of servers in a cluster. It uses the VRRP (Virtual Router Redundancy Protocol) to create a virtual IP address (Floating IP) shared among all servers in the cluster. When the primary server (master) fails, Keepalived automatically transfers the Floating IP to the backup server.

Floating IP is a virtual IP address assigned to one of the servers in the cluster. When the primary server goes down, the Floating IP is transferred to the backup server, ensuring continuous service without interruption.

2. Requirements and Preparation

To implement this configuration, you will need:

  • At least 2 VPS servers (one primary and one backup).
  • A Floating IP provided by your VPS provider.
  • SSH access to both servers.
  • Ubuntu 20.04+ operating system running on both servers.

3. Configure Keepalived on Both Servers

Follow these steps on both servers (master and backup).

3.1. Install Keepalived

Run the following commands on both servers:

sudo apt update
sudo apt install keepalived -y

3.2. Configure Keepalived

Modify the configuration file:

sudo nano /etc/keepalived/keepalived.conf

Replace the content with the following configuration (adjust IP and server names as needed):

global_defs {
    router_id VPS_MASTER
}

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

On the backup server, make the following changes:

  • Change state MASTER to state BACKUP
  • Change priority 100 to priority 90
  • Change router_id VPS_MASTER to router_id VPS_BACKUP

4. Test and Verify

After configuration, restart the Keepalived service:

sudo systemctl restart keepalived
sudo systemctl enable keepalived

Check the status:

sudo keepalived -v

Test the failover by stopping the service on the primary server and verifying that the Floating IP switches to the backup server.

5. Troubleshooting

  • IP not switching: Check Keepalived logs: sudo journalctl -u keepalived.
  • No connectivity: Verify firewall and routing rules on both servers.
  • Not working after reboot: Ensure Keepalived is enabled at boot: sudo systemctl enable keepalived.

6. References

For more information about Keepalived and VRRP, refer to:

To further enhance availability, integrate with backup and disaster recovery solutions as described in the referenced articles.

Related infrastructure & engineering guides: NVMe Cloud VPS for Docker, Nginx & Databases

DPTCloud Tier III Infrastructure

Recommended NVMe Cloud VPS Plans to Deploy This Setup

Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.

View 22 VPS Plans
ECO · vn-02

VPS-2E

94.600 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 2 GB
  • SSD: 30 GB NVMe
ECO · vn-02Recommended

VPS-3E

170.500 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 4 GB
  • SSD: 50 GB NVMe
BASIC · vn-01Recommended

VPS-05

457.600 ₫ / mo

10% VAT included

  • CPU: 4 vCPU
  • RAM: 8 GB
  • SSD: 50 GB NVMe

Related Articles

View all
ZaloZalo SupportDiscord0384 753 478