Configuring HAProxy with memcache with failover

failoverhaproxyhigh-availabilitymemcache

I'm configuring a new set of servers for an existing WordPress site, and it's been requested that memcache be available and made more resilient. The idea proposed is to have HAProxy send requests to one of the two servers; if that memcache instance is inaccessible, then it should switch to the second, but should not switch back to the first if it comes back up unless the second is then unavailable.

This doesn't appear to be a particularly common use case and I've not found much along these lines except to possibly set up the first node with an enormous rise value, such as:

server server1 10.112.58.16:11211  check inter 5s fall 3 rise 99999999
server server2 10.112.58.19:11211  check backup

which falls over as expected when server1 is unavailable. It won't ever fall back to server1, though, even if server2 goes offline. Can this be made to work?

Best Answer

Keepalived or pacemaker sounds like a more appropriate solution for your use case. Using just haproxy leaves you with a single point of failure and no way to prevent automatic failback in the manner you want, whereas Keepalived or pacemaker will do exactly you need without a single point of failure.