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

  • Marinbabacic

    well done 🙂

  • Chris Smith

    What if we are monitoring load on our mysql slave servers and want to spin up more slave servers as the need arrises. Would we need to script out the addition of those servers to haproxy and restart the service, or is there a way to have the rackspace tools accomplish this for you?

  • Work Kuldip

    This is a very nice article Please can you suggest how to test haproxy for this