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:
The last part of the process is to add load balancing.
1. Start by installing HAProxy on both servers:
1 |
yum install haproxy |
Unfortunately yum will provide an outdated version so we need to upgrade from source as follows:
1 2 3 4 5 6 |
cd /root/archive/ wget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.14.tar.gz tar -xvzf haproxy-1.4.14.tar.gz cd haproxy-1.4.14 make TARGET=linux26 make install |
Now edit /etc/init.d/haproxy and change this line:
1 |
exec="/usr/sbin/haproxy" |
to:
1 |
exec="/usr/local/sbin/haproxy" |
2. Now edit /etc/haproxy/haproxy.cfg
a. Remove all existing “listen”, “frontend” and “backend” sections.
b. Find this line if it exists:
1 |
option httplog |
and change it to:
1 |
option tcplog |
c. Add this listen section:
1 2 3 4 5 6 7 |
listen mysql-cluster 0.0.0.0:3307 mode tcp balance roundrobin option mysql-check user root server db01 [HOST1_IP]:3306 check server db02 [HOST2_IP]:3306 check |
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:
1 |
/sbin/chkconfig --level 345 haproxy on |
4. Finally start the haproxy service.
/sbin/service haproxy restart