How to configure MySQL Cluster with Heartbeat

In this post we'll discuss how to set up a MySQL cluster with two serves, storage and Heartbeat.
I'm using CentOS 5 distribution on both machines, MySQL 5.1 and a mounted directory on both servers to /var/lib/mysql

You need to install MySQL on both machines.
Assign hostname dbserver01, dbserver02.
dbserver01 is the primary node with IP address to eth0.
and dbserver02 is the slave one with ip address is the virtual IP that will be used for MySQL.

Configuration (do those steps on both servers)
install the Heartbeat package:
# yum install heartbeat

copy the next configuration files to the /etc/ha.d directory:
# cp /usr/share/doc/heartbeat-version/authkeys /etc/ha.d
# cp /usr/share/doc/heartbeat-version/ /etc/ha.d
# cp /usr/share/doc/heartbeat-version/haresources /etc/ha.d

First we will edit the authkeys file,
# vi /etc/ha.d/authkeys
copy from here:
auth 2
2 sha1 test-HA
change the permission of the authkeys file:
# chmod 600 /etc/ha.d/authkeys

Now let's edit the most important file (
# vi /etc/ha.d/ha/cf
add the following lines into the file:
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
initdead 120
bcast eth0
udpport 694
auto_failback on
node dbserver01
node dbserver02 

The last file we need to edit is haresources:
# vi /etc/ha.d/haresources
add the following line:
dbserver01 netfs mysqld 

Now all we need to do is to start the hearbeat service on both machines:
# /etc/init.d/heartbeat start
the virtual IP address is now on dbserver01 and MySQL is up and running.
if dbserver01 will crashed from any reason the IP address will jump to dbserver02 the the MySQL service will start automatic.

And please comment (-;

1 comment:

  1. works perfectly.

    I wonder if you know how to setup a load balance between the servers on the cluster. This setup has the dataserver2 as slave waiting for server1 to fail. A good idea will be to loadbalance with the virtual ip, however I can't find any specific to mysql.