Top Nav

MySQL Load Balancing With HAProxy

The goal of this series of articles has been to construct a high availability and load balanced MySQL cluster with CentOS on the RackSpace Cloud.

You should begin with this article to setup the HA Linux cluster:

HA Linux Cluster On RackSpace Cloud Servers

Then follow this article to add the multi-master MySQL replication:

MySQL Multi Master HA Cluster

The last part of the process is to add load balancing.

1. Start by installing HAProxy on both servers:

Unfortunately yum will provide an outdated version so we need to upgrade from source as follows:

Now edit /etc/init.d/haproxy and change this line:


2. Now edit /etc/haproxy/haproxy.cfg

a. Remove all existing “listen”, “frontend” and “backend” sections.

b. Find this line if it exists:

and change it to:

c. Add this listen section:

The [PASSWORD] controls access to the HAProxy web interface. And [HOST1_IP] and [HOST2_IP] are the private addresses of the servers.

d. Repeat on the other server.

3. Set haproxy service to start on boot:

4. Finally start the haproxy service.

/sbin/service haproxy restart