# Configuring a failover cluster with heartbeat + pacemaker

URL: https://sohaib.com/blog/configuring-a-failover-cluster-with-heartbeat-pacemaker
Author: Sohaib Khan
Published: Jun 26, 2013
Updated: Sep 8, 2026
Category: Cloud & Infrastructure

> I am going to show of how you configure heartbeat with pacemaker Active / Passive Cluster in easy word if one server goes offline second one kicks right back up. We are using Apache2 to monitor and using Ubuntu 12.04…

I am going to show of how you configure heartbeat with pacemaker Active / Passive Cluster in easy word if one server goes offline second one kicks right back up. We are using Apache2 to monitor and using Ubuntu 12.04 precise edition Our Configuration :- ns1 192.168.1.11 ns2 192.168.1.12 Virtual IP 192.168.1.45  ( this is our virtual IP and this is where we will point our A record in DNS ) **Configuring heartbeat** 1.- Edit /etc/hosts:

<table cellspacing="0" cellpadding="0"><tbody><tr><td valign="middle"></td><td valign="middle">192.168.1.11 ns1<span style="line-height:19px;">192.168.1.12 ns2</span></td></tr></tbody></table>

2.- Install heartbeat and pacemaker:

<table cellspacing="0" cellpadding="0"><tbody><tr><td valign="middle"></td><td valign="middle"><span style="color:#ff0000;"><strong>apt-get install heartbeat pacemaker</strong></span></td></tr></tbody></table>

3.- Edit /etc/ha.d/ha.cf : Please note ha.cf file in second node must have IP of your first node so .3 IP must change. **debugfile /var/log/ha-debug** **logfile /var/log/ha-log** **logfacility local0** **keepalive 2** **deadtime 30** **warntime 10** **initdead 120** **udpport 694** **ucast eth0 192.168.1.4** **node ns1 ns2** **ping 192.168.1.1 crm respawn** On Second Node **debugfile /var/log/ha-debug** **logfile /var/log/ha-log** **logfacility local0** **keepalive 2** **deadtime 30** **warntime 10** **initdead 120** **udpport 694** **ucast eth0 192.168.1.3** **node ns1 ns2** **ping 192.168.1.1 crm respawn** 4.- Edit /etc/ha.d/authkeys: **auth 1** **1 crc** **#2 sha1 HI!** **#3 md5 Hello!** 5.- Set correct file permissions to autkeys:

<table cellspacing="0" cellpadding="0"><tbody><tr><td valign="middle"></td><td valign="middle"><span style="color:#339966;"><strong>chmod 600 authkeys</strong></span></td></tr></tbody></table>

6.- restart heartbeat:

<table cellspacing="0" cellpadding="0"><tbody><tr><td valign="middle"></td><td valign="middle"><span style="color:#ff0000;"><strong>service heartbeat restart</strong></span></td></tr></tbody></table>

**Configuration of pacemaker** 1.- Verify the status of cluster: **crm status** root@ns1:/etc/ha.d# crm status \============ Last updated: Wed Jun 26 07:34:16 2013 Last change: Wed Jun 26 07:33:58 2013 via crmd on ns2 Stack: Heartbeat Current DC: ns2 (784f096b-d035-4ef3-9b28-4d258ae52f2f) - partition with quorum Version: 1.1.6-9971ebba4494012a93c03b40a2c58ec0eb60f50c 2 Nodes configured, unknown expected votes 0 Resources configured. \============ Online: \[ ns1 ns2 \] **Once you have above status - its a green light to run the following commands**  crm configure property stonith-enabled=false crm configure property expected-quorum-votes="2" crm configure property no-quorum-policy=ignore crm configure rsc\_defaults resource-stickiness=100 **I will explain what each commands are :-** 2.- Disable stonith:

<table cellspacing="0" cellpadding="0"><tbody><tr><td valign="middle"></td><td valign="middle"><span style="color:#ff0000;"><strong>crm configure property stonith-enabled=false</strong></span></td></tr></tbody></table>

3.- Number of nodes for the quorum:

<table cellspacing="0" cellpadding="0"><tbody><tr><td valign="middle"></td><td valign="middle"><span style="color:#ff0000;"><strong>crm configure property expected-quorum-votes="2"</strong></span></td></tr></tbody></table>

4.- To have quorum, more than half of the total number of cluster nodes need to be online (number of nodes / 2)+1. Is not the case when a node failure occurs in a 2-node cluster. If you want to allow the remaining node to provide all the cluster services, you need to set the no-quorum-policy to ignore:

<table cellspacing="0" cellpadding="0"><tbody><tr><td valign="middle"></td><td valign="middle"><span style="color:#ff0000;"><strong>crm configure property no-quorum-policy=ignore</strong></span></td></tr></tbody></table>

5.- To prevent failback of a resource:

<table cellspacing="0" cellpadding="0"><tbody><tr><td valign="middle"></td><td valign="middle"><span style="color:#ff0000;"><strong>crm configure rsc_defaults resource-stickiness=100</strong></span></td></tr></tbody></table>

6.- List of scripts for the class ocf:

<table cellspacing="0" cellpadding="0"><tbody><tr><td valign="middle"></td><td valign="middle"><span style="color:#ff0000;"><strong>crm ra list ocf</strong></span></td></tr></tbody></table>

7.- Information for a script:

<table cellspacing="0" cellpadding="0"><tbody><tr><td valign="middle"></td><td valign="middle"><span style="color:#ff0000;"><strong>crm ra info ocf:IPaddr2</strong></span></td></tr></tbody></table>

8.- Add an VIP to our cluster:

<table cellspacing="0" cellpadding="0"><tbody><tr><td valign="middle"></td><td valign="middle"><span style="color:#ff0000;"><strong>crm configure primitive havip1 ocf:IPaddr2 params ip=192.168.1.45 cidr_netmask=32 nic=eth1 op monitor interval=30s</strong></span></td></tr></tbody></table>

9.- Check status and see that the resource havip1 is started in the first node **crm status** **Adding a daemon to our cluster** 1.- See the script details:

<table cellspacing="0" cellpadding="0"><tbody><tr><td valign="middle"></td><td valign="middle"><span style="color:#ff0000;"><strong>crm ra info ocf:anything</strong></span></td></tr></tbody></table>

2.- Adding apache daemon to our cluster:

<table cellspacing="0" cellpadding="0"><tbody><tr><td valign="middle"></td><td valign="middle"><span style="color:#ff0000;"><strong>crm configure primitive apacheha lsb::apache2 op monitor interval=15s</strong></span></td></tr></tbody></table>

3.- Setting up the resource VIP and apache are in the same node:

<table cellspacing="0" cellpadding="0"><tbody><tr><td valign="middle"></td><td valign="middle"><span style="color:#ff0000;"><strong>crm configure colocation apacheha-havip1 INFINITY: havip1 apacheha</strong></span></td></tr></tbody></table>

4.- See the status of our cluster: **crm status** havip1 (ocf::heartbeat:IPaddr2): Started ns2 apacheha (lsb:apache2): Started penguin-ha2 **Configuring the order of boot of the services**

<table cellspacing="0" cellpadding="0"><tbody><tr><td valign="middle"></td><td valign="middle"><span style="color:#ff0000;"><strong>crm configure order ip-apache mandatory: havip1 apacheha</strong></span></td></tr></tbody></table>

**Migrate a resource to another node** havip1 (ocf::heartbeat:IPaddr2): Started ns1 apacheha (lsb:apache2): Started ns2 See cluster configuration: crm configure show
