HAProxy in a fail-over pair
I quite often come across people looking for advice on setting up HAProxy on a pair of servers, so achieving highly-available load balancing.
A lot of people use heartbeat, which monitors the neighbouring server’s state, and stops and starts any given services accordingly. However heartbeat, isn’t quite the right job for the tool, as Willy Tarreau, HAProxy’s author explains the merits of keepalived.
It is not the best tool for this job, it was designed to build clusters, which is a lot different from having two redundant stateless network equipments. Network oriented tools such as keepalived or ucarp are the best suited for that task.[…]
a cluster-oriented product such as heartbeat will ensure that a shared resource will be present at *at most* one place. This is very important for shared filesystems, disks, etc… It is designed to take a service down on one node and up on another one during a switchover. That way, the shared resource may never be concurrently accessed. This is a very hard task to accomplish and it does it well.
a network-oriented product such as keepalived will ensure that a shared IP address will be present at *at least* one place. Please note that I’m not talking about a service or resource anymore, it just plays with IP addresses. It will not try to down or up any service, it will just consider a certain number of criteria to decide which node is the most suited to offer the service. But the service must already be up on both nodes. As such, it is very well suited for redundant routers, firewalls and proxies, but not at all for disk arrays nor filesystems.
I’ve been using HAProxy with keepalived for some time now, and it’s actually refreshingly simple and neat compared to heartbeat. Willy’s full post is avaliable on the HAProxy mailing list.