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 192.168.1.150:3306. 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: 192.168.1.150
First of all we need to enable the Epel repo.
Next lets install HeatBeat on the servers:
yum install heartbeat
/etc/hosts file with the following:
db1 192.168.1.130 db2 192.168.1.140
In my case db1 and db2 are the results of the following command on both servers:
On DB1 server.
/etc/ha.d/ha.cf 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
/etc/ha.d/haresources with the following data in it:
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
255.255.255.0 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:
New you can run
ifconfig and see the virtual interface on the DB1 server:
Reboot DB1 server and watch ifconfig on the DB2 server to test if everything works.