Configure failover with Heartbeat on Centos

In this not I’d like to describe the usage of HeatBeat for the failover of the two servers. In this example I have 2 servers with MySQL on board. Websites establish mysql connection to the I’m going to configure heartbeat to bring up the floating ip address on 2 servers. In this case if the first server goes down, the second server will spin-up the network interface with the floating ip address and continue accepting MySQL connection.

Heartbeat is a cool tool, that allows you to perform various actions on the servers in the cluster depending on the state of other servers and phases of moon in November.

I have the following:
    floating ip:

First of all we need to enable the Epel repo.

Next lets install HeatBeat on the servers:

yum install heartbeat

Update /etc/hosts file with the following:


In my case db1 and db2 are the results of the following command on both servers:

uname -n

On DB1 server.

Create file /etc/ha.d/ with the following data in it:

logfile /var/log/ha.log
keepalive 500ms
deadtime 10
warntime 5
initdead 30
auto_failback off
node db1
node db2
ping db1
deadping 2

Create file /etc/ha.d/haresources with the following data in it:

db1 IPaddr::

This will cause the DB1 server to run the /etc/ha.d/resource.d/IPaddr script and create virtual network interface eth0:0 with ip address and subnet mask.

DB2 server should bring up the same interface if DB1 goes down.

Next create the auth file:

echo -ne “# Automatically generated authkeys file \n auth 1 \n 1 sha1 $(dd if=/dev/urandom count=4 2>/dev/null | md5sum | cut -c1-32) \n” >> /etc/ha.d/authkeys

Update access policies for it:

chmod 600 /etc/ha.d/authkeys

Now we can simply copy everything to the DB2 server:

rsync -Hogva /etc/ha.d root@db2:/etc/

Restart HeartBeat on both servers to apply changes:

/etc/init.d/heartbeat restart

New you can run ifconfig and see the virtual interface on the DB1 server:

Screenshot from 2014-09-22 12:42:07

Reboot DB1 server and watch ifconfig on the DB2 server to test if everything works.

Share Button

Leave a Reply

You must be logged in to post a comment.