## Example Configuration for keepalived You can use _keepalived_ to implement automatic failover of a Floating IP between multiple servers. The following example has been tested using two Ubuntu 16.04 cloud servers at cloudscale.ch. For this example, install `keepalived`, `nginx` and `curl` and create the following two files on each server. Make sure to adjust the servers' IP addresses and UUIDs, the Floating IPs as well as the API token. /etc/keepalived/keepalived.conf: # Define a shell command to check whether the service is running or not. vrrp_script service_check { script "systemctl is-active nginx" interval 2 } # Define a group of servers sharing a set of Floating IPs. vrrp_instance floating_ip { # VID of the VRRP group. virtual_router_id 23 # Interface and local IP address used by this VRRP instance. interface ens3 native_ipv6 unicast_src_ip 2001:db8::2 # Peer IP address of each server in the same VRRP group. unicast_peer { 2001:db8::3 } # Service check script used by this VRRP instance. track_script { service_check } # Script to assign the Floating IPs to this server when becoming master. notify_master "/etc/keepalived/master.sh" # VRRP priority of this server. # The server with the highest priority will become master. Use a different # priority for each server within the same VRRP group. priority 100 } /etc/keepalived/master.sh: #!/bin/sh set -e # API token (with write permission) to access the cloudscale.ch API. api_token='XXXXXXXXXXXXXXXX' # Set of Floating IPs shared between the servers within the same VRRP group. floating_ipv4='192.0.2.1' floating_ipv6='2001:db8::1' # UUID of the server that this script is running on. # The UUID of the server can be retrieved using the API. server_uuid='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' # Call the cloudscale.ch API to assign a specific Floating IP to this server. set_master() { curl \ -f \ -H "Authorization: Bearer $api_token" \ -F server="$server_uuid" \ "https://api.cloudscale.ch/v1/floating-ips/$1" } # Assign the Floating IPs to this server. # Use linear back-off when unable to access API temporarily. ipv4_set=0 ipv6_set=0 i=1 while [ "$ipv4_set" -lt 1 -o "$ipv6_set" -lt 1 ] ; do if [ "$ipv4_set" -lt 1 ] ; then set_master $floating_ipv4 && ipv4_set=1 fi if [ "$ipv6_set" -lt 1 ] ; then set_master $floating_ipv6 && ipv6_set=1 fi sleep $i i=$(expr $i + 1) done Make this script executable (`chmod a+x`). Once you have created the two files as described above on each server you need to restart the `keepalived` service. The server with the highest priority will assign the Floating IPs to itself. If the service monitored by the check script fails or the server itself becomes unresponsive, another server will automatically take over.