I have 2 virtual servers on Softlayer, both running HAProxy. I am trying to set up failover with keepalived. Each server has a private IP and public IP, and they are on the same VLAN. I've tried many different settings for keepalived, but stopping HAProxy on master, it does not failover to the BACKUP.
I read that multicast was not supported, so I have since changed my settings to unicast. The settings now, on backup/master are basically this:
vrrp_script chk_haproxy {
script "pidof haproxy"
interval 2
}
vrrp_instance VI_1 {
debug 2
interface eth1
state MASTER
virtual_router_id 51
priority 101
unicast_src_ip 1.2.3.4 # My IP
unicast_peer {
5.6.7.8 # peer IP
}
track_script {
chk_haproxy
}
}
Where MYIP is the public IP address of the server the conf file is on, and PEERIP is the public IP address of the peer. Still it is not working. Stopping HAProxy on the master, it does not failover to the backup.
I am wondering if anyone has set up HAProxy with failover on Softlayer, and how they went about accomplishing it?
Best Answer
I managed to get this set up, and here's how I did it:
I created a global IP address using SoftLayer's control panel.
I have Debian 7 on both HAProxy virtual servers. I added the global IP address to eth1 interface on both servers.
Here's the HAProxy settings used on both servers:
Here's the Keepalived settings on MASTER server:
Here's the Keepalived settings on BACKUP server:
As said above, I am running Debian 7. As can be seen in keepalived settings, I have a notify_master script. Here's everything needed to get the script running:
Now that all the dependencies are in place, the script should work. Here's the script, which I saved as
/usr/bin/reroute_global
:You'd need to change API_USERNAME/KEY to match your API credentials. The script grabs the first global IP from your SoftLayer global IP addresses, and then reroutes the global IP to the system. In the case of a failover, the BACKUP becomes MASTER and runs the script, which routes the global IP address to itself.
Testing
curl http://<global_IP>
service haproxy stop
On backup:
tail -f /var/log/syslog
. You should see something like this:curl http://<global_IP>
(it should work if failover worked)