Back to articles
AI & Cloud

High Availability Solution: Manual Failover IP Configuration with Keepalived Between 2 Different VPS Providers

Detailed guide on configuring manual failover IP using Keepalived between two VPS instances from different providers to ensure high availability for applications and services.

DPTCloud Engineering4 min read
High Availability Solution: Manual Failover IP Configuration with Keepalived Between 2 Different VPS Providers

Introduction

In online system operations, high availability (HA) is a critical factor to ensure services remain uninterrupted. One common solution to achieve this is configuring a failover IP—an IP address that can automatically switch from the primary server to the backup server when the primary fails. In this guide, we will provide a detailed walkthrough of setting up a manual failover IP using Keepalived between two VPS instances from different providers, enhancing system stability and reliability.

Solution: Manual Failover IP Between 2 VPS from Different Providers

Using Keepalived to create a failover IP solution between two VPS instances from different providers not only reduces the risk of dependency on a single provider but also optimizes costs and increases flexibility. Keepalived operates based on the VRRP (Virtual Router Redundancy Protocol), allowing two servers to share a virtual IP address (VIP) and monitor each other’s status to switch the VIP when necessary.

Requirements and Preparation

Before starting, ensure you have:

  • Two VPS instances from different providers (e.g., VPS1 from Provider A, VPS2 from Provider B).
  • A virtual IP (VIP) assigned by one or both providers.
  • SSH access to both VPS instances.
  • Network and firewall configuration capabilities on both VPS instances.

Configuration Steps

We will install and configure Keepalived on both servers. Below are the detailed steps:

1. Install Keepalived

On both VPS1 and VPS2, run the following command to install Keepalived:

sudo apt update
sudo apt install keepalived -y

2. Configure Keepalived

Modify the Keepalived configuration file at `/etc/keepalived/keepalived.conf` on both servers.

On VPS1 (Primary):

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 VPS2 (Backup):

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

Explanation:

  • state: VPS1 is MASTER, VPS2 is BACKUP.
  • priority: VPS1 has a higher priority to ensure it remains the primary server.
  • virtual_ipaddress: This is the virtual IP address (VIP) that will be switched.

3. Start and Check the Service

Start Keepalived on both servers:

sudo systemctl start keepalived
sudo systemctl enable keepalived

Check the status:

sudo systemctl status keepalived

Testing and Verification

To verify failover functionality, you can:

  1. Temporarily stop Keepalived service on VPS1:
  2. sudo systemctl stop keepalived
  3. Observe whether the VIP (192.168.1.100) switches to VPS2.
  4. Restart the service on VPS1 and verify the switch back.

Troubleshooting

  • No virtual IP: Check the `virtual_ipaddress` configuration and ensure the IP is not already in use.
  • Keepalived not running: Check logs at `/var/log/syslog` or `/var/log/messages` for errors.
  • No IP switch: Ensure both servers can communicate over the network and are not blocked by firewalls.

References

Related infrastructure & engineering guides: High-RAM Cloud VPS for Self-Hosted LLMs & API Gateways

DPTCloud Tier III Infrastructure

High-RAM Cloud VPS Plans Optimized for AI, Databases & Cache

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

View 22 VPS Plans
ECO · vn-02Recommended

VPS-4E

297.000 ₫ / mo

10% VAT included

  • CPU: 4 vCPU
  • RAM: 8 GB
  • SSD: 50 GB NVMe
ECO · vn-02

VPS-5E

614.900 ₫ / mo

10% VAT included

  • CPU: 8 vCPU
  • RAM: 16 GB
  • SSD: 100 GB NVMe
ADVANCED · vn-03Recommended

VPS-4T

548.900 ₫ / mo

10% VAT included

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

Related Articles

View all
ZaloZalo SupportDiscord0384 753 478