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:

to:

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

Have a project or a problem?

Talk with a senior engineer for practical recommendations—no obligation.

Leave a comment

3 Responses

  1. 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?

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Categories

Get a free consultation from Reliable Penguin

Submit the form—or for immediate service call 866-649-7984.