Configuring a failover cluster with heartbeat + pacemaker

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:

192.168.1.11 ns1192.168.1.12 ns2

2.- Install heartbeat and pacemaker:

apt-get install heartbeat pacemaker

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:

chmod 600 authkeys

6.- restart heartbeat:

service heartbeat restart

Configuration of pacemaker

1.- Verify the status of cluster:

crm status

[email protected]:/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:

crm configure property stonith-enabled=false

3.- Number of nodes for the quorum:

crm configure property expected-quorum-votes=”2″

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:

crm configure property no-quorum-policy=ignore

5.- To prevent failback of a resource:

crm configure rsc_defaults resource-stickiness=100

6.- List of scripts for the class ocf:

crm ra list ocf

7.- Information for a script:

crm ra info ocf:IPaddr2

8.- Add an VIP to our cluster:

crm configure primitive havip1 ocf:IPaddr2 params ip=192.168.1.45 cidr_netmask=32 nic=eth1 op monitor interval=30s

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:

crm ra info ocf:anything

2.- Adding apache daemon to our cluster:

crm configure primitive apacheha lsb::apache2 op monitor interval=15s

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

crm configure colocation apacheha-havip1 INFINITY: havip1 apacheha

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

crm configure order ip-apache mandatory: havip1 apacheha

Migrate a resource to another node

havip1 (ocf::heartbeat:IPaddr2): Started ns1

apacheha (lsb:apache2): Started ns2

See cluster configuration:

crm configure show

Leave a Reply

Your email address will not be published.