Billing and payments
Cloud server volumes
Data centers and network
Data privacy and data portability
How it works
VPN to GPN
Embargoed and Sanctioned Countries
How to setup floating IP using keepalived
Services that require high availability typically use floating IPs. Floating IP address can be transferred between multiple servers allowing for failover or upgrading of production software.
This article will guide you through basic setup of floating IP using the keepalived software on CentOS 7. The keepalived software uses VRRP protocol and IP multicasting for communication between servers.
Dedicated servers. Floating IP address setup is possible only with dedicated servers, but not cloud servers.
Layer 2 segment. Servers have to be joined into the same layer 2 segment (i.e. VLAN). Please note, that creation of custom L2 segments is available in selected locations, so the servers must be in an eligible location. You can view eligible locations in the L2 segment creation dialog in the Customer Portal.
Creating L2 segment and leasing IP alias
Let's say we have two dedicated servers in the DFW1 location, named "master-keepalived" and "slave-keepalived".
Now we need to create a new L2 segment in "Networks > L2 segments" section of the Customer Portal. The type of VLAN is "Native" as we only use one VLAN, and the type is "External" because we will be using public address space. Name is irrelevant, and we need to add both of our servers to the hosts subsection.
It takes 3-5 minutes for new segment to be created. Use the "Refresh" button next to the segment status to check if the status has changed from "pending" to "active".
After the segment became active, we need to add an IP alias, which will be the floating IP. Add one, click "Save".
Setting up keepalived
Install and enable keepalived daemon on both servers:
In our demo configuration we have two servers: MASTER and BACKUP. The floating IP address is assigned to the MASTER in normal course of action. Responsibility of the BACKUP server is to take over the floating IP and the load from the MASTER server in case of its failure, and vice versa.
MASTER's config (/etc/keepalived/keepalived.conf) looks like following:
BACKUP's config (/etc/keepalived/keepalived.conf) looks like following:
Some notes on configuration file:
Now we are ready to start keepalived on both servers:
You can see in the ifconfig output, that the floating IP is assigned to the MASTER server by default:
To test failover, start pinging the floating IP, then stop keepalived on the MASTER:
You will see short timed packet loss in the ping output, which takes place while the BACKUP server takes floating IP over: