I am interested in using HA proxy as a failover/load balancer in our MySQL environment. We have a master-master + 2 slaves setup.
I would like for the master/master setup, even though they are setup for it, to only write to one master. This is to avoid issues with split-brain.
I do plan on having a separate port on HA proxy for reads and for that to be load balanaced.
Is it possible use HA proxy as a fail over only and if so, how would you set it?
Is it something like balance with roundrobin, but give one of the servers a weight of 1 and the other a weight of 0? With the idea being if the first server goes offline, the second will be used no matter its weight?
Yes, it is possible by adding the
backup
option to the end ofserver
line, something like this:Port 9199 is used to monitor MySQL status:
/etc/services
/etc/xinetd.d/mysqlchk
/opt/mysqlchk
Source: http://sysbible.org/2008/12/04/having-haproxy-check-mysql-status-through-a-xinetd-script/
But wait, when a master fails, how do you point the slaves to the new master? You had better use HAProxy to load balancing the read operations and let the write operation (includes the failover) to the Percona Pacemaker Resource Agents handle.
Note that some client implementations of mysql (such as the official JDBC connector) supports this without using load balancer software. If you happen to be so lucky (or unlucky) that you have such a connector and control over it's config, there are a few benefits, namely:
Client side failover. One less instance where something can go wrong.
Increased read performance by using the failover nodes for reads.
Lower latency (which is mostly nitpicking, but very important in some setups)
See examples for JDBC.
And there is mysqlproxy which solves it more or less the same way as ha-proxy.