Creating a two-node CentOS 6 cluster with floating IP using CMAN and Pacemaker

Originally I was using Heartbeat to create two-node Linux clusters with floating IPs, but when Heartbeat stopped being developed I needed to figure out how to use Corosync and Pacemaker for this instead. Somewhat annoyingly, Linux HA stuff has changed yet again in CentOS 6.4, so now it’s necessary to use CMAN and Pacemaker instead.

This is quite a lot more in-depth than the simple configuration that was originally required for Heartbeat. Anyway, based on my recent experiences, here’s a very quick guide for if you find yourself in a similar situation. This works for me on CentOS 6.4 and higher, but it won’t work on earlier versions of CentOS.

If you’re looking for the old instructions for creating a cluster with Pacemaker and Corosync, they’re here.

Installation and initial configuration

Install the required packages on both machines:

yum install pacemaker
cp /etc/corosync/corosync.conf.example /etc/corosync/corosync.conf

Set up and configure the cluster on the primary machine, changing newcluster , server1.example.com and server2.example.com as needed:

ccs -f /etc/cluster/cluster.conf --createcluster newcluster
ccs -f /etc/cluster/cluster.conf --addnode server1.example.com
ccs -f /etc/cluster/cluster.conf --addnode server2.example.com
ccs -f /etc/cluster/cluster.conf --addfencedev pcmk agent=fence_pcmk
ccs -f /etc/cluster/cluster.conf --addmethod pcmk-redirect server1.example.com
ccs -f /etc/cluster/cluster.conf --addmethod pcmk-redirect server2.example.com
ccs -f /etc/cluster/cluster.conf --addfenceinst pcmk server1.example.com pcmk-redirect port=server1.example.com
ccs -f /etc/cluster/cluster.conf --addfenceinst pcmk server2.example.com pcmk-redirect port=server2.example.com

Copy /etc/cluster/cluster.conf from the primary machine to the secondary machine in the cluster.

It’s necessary to turn off quorum checking, so do this on both machines:

echo "CMAN_QUORUM_TIMEOUT=0" >> /etc/sysconfig/cman

Start the services

Start up the services on both machines:

service cman start
service pacemaker start

Make sure both services start on reboot:

chkconfig cman on
chkconfig pacemaker on

Configure and create floating IP

Configure the cluster on the primary machine:

pcs property set stonith-enabled=false
pcs property set no-quorum-policy=ignore

Create the floating IP on the primary machine, changing the IP address and server name as needed:

pcs resource create livefrontendIP0 ocf:heartbeat:IPaddr2 ip=192.168.100.100 cidr_netmask=32 op monitor interval=30s
pcs constraint location livefrontendIP0 prefers server1.example.com=INFINITY

Cluster administration

To monitor the status of the cluster:

pcs status

To show the full cluster configuration:

pcs config
  • Thurein aung

    Hi Matt,

    I am just curious why you don’t use RHCS that comes free with CentOS. Is there any reason or just personnel preference?

    Thanks,

    • RHCS is a complex set of tools so it’s quite a bulky and complicated thing to install and administer. I prefer to understand the individual tools and keep things simple so I fully understand what they were doing, so this is a more effective and simple solution for this particular requirement. I also don’t like installing GUIs on servers as they take up resources and make things more complicated to administer.

  • paul skaria

    great post! is it possible to failover the interactive sshd sessions without state loss. basically i want to retain the ssh user login sessions while failover to the other node. thanks

    • It’s hard to imagine how that would be possible really, or why it would be desirable. Why not simply SSH into both nodes?

  • Benjamin Piraro

    I found this article somewhat useful… Being that I have never setup a cluster before. I had a new “minimal” install on CentOS 6.5. pkgs like pcs, ccs, cman had to be installed…. also, I had to create /etc/cluster before I could perform the ccs commands.

    another tidbit… is the “resource” name you used… “livefrontendIP0” to be referred to as the hostname for the floating IP ??

    • Benjamin Piraro

      I might also recommend this site for additional info, which follows everything where and then some “http://clusterlabs.org/quickstart-redhat.html” Shows more.
      .

      • Thanks for the feedback. It took a while for your second comment to appear as Disqus spammed it because it contained a link. I’m not aware of a need for there to be a relationship between the resource name and the hostname.

  • Lieven De Puysseleir

    Hi Matt, this was very usefull for me, for me the advantage is I was not burdened with previous cluster knowledge except heartbeat+drbd.

    I’m building some 2node cluster for KVM based on 6.5 and grapping bits here and there to get everything I need in that and this resource was excellent.

    There’s a lot of outdated stuff nowadays as you state in the article due to the changes in rhel 6.4, 6.5.