Active/Passive Cluster With Pacemaker, Corosync and DRBD on CentOS 7: Part 2 – Add and Configure Resources

The following is part 2 of a 4 part series that will go over an installation and configuration of Pacemaker, Corosync, Apache, DRBD and a VMware STONITH agent.


The convention followed in the series is that [ALL] # denotes a command that needs to be run on all cluster machines.

Configure Cluster Resources

The first resource that we are going to add is an IP address that the cluster can bring up on either node. This will be used as a VIP for Apache frontend.

Add a Virtual IP Resource

The name of the resource is my_VIP. The cluster is told to check whether the address is running every 10 seconds.

[pcmk01]# pcs resource create my_VIP ocf:heartbeat:IPaddr2 \
 ip= cidr_netmask=32 op monitor interval=10s

To test the resource failover, we can put the active node into standby mode:

[pcmk01]# pcs status
[pcmk01]# pcs cluster standby pcmk01-cr
[pcmk01]# pcs status
[pcmk01]# ssh pcmk02 ip ad show
[pcmk01]# pcs cluster unstandby pcmk01-cr

The VIP should float from the first node to the second. We also want to prevent the resources from moving after recovery as it usually increases downtime:

[pcmk01]# pcs resource defaults resource-stickiness=100

If need be, after recovery, we can move the resource manually:

[pcmk01]# pcs resource move my_VIP pcmk01-cr
[pcmk01]# pcs resource clear my_VIP

Note that when we execute the pcs resource move command, this adds constraints to the resource to prevent it from running on the indicated node. When we execute the pcs resource clear command, this removes the constraints. This does not necessarily move the resources back to the indicated node.

Add Apache as a Cluster Service

We need to have Apache installed first:

[ALL]# yum install -y httpd wget

Create a temp index document:

[ALL]# cat <<EOL >/var/www/html/index.html
Apache test on $(hostname)

Enable the Apache status URL:

[ALL]# cat <<-END >/etc/httpd/conf.d/status.conf
 <Location /server-status>
    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from

Add Apache to the cluster:

[pcmk01]# pcs resource create my_website ocf:heartbeat:apache  \
  configfile=/etc/httpd/conf/httpd.conf \
  statusurl="http://localhost/server-status" \
  op monitor interval=10s

The name of the Apache resource is my_website. The cluster is told to check whether the Apache is running every 10 seconds.

Create a Resource Group

One of the most common elements of a cluster is a set of resources that need to be located together, start sequentially, and stop in the reverse order. To simplify this configuration, Pacemaker supports the concept of groups.

If we don’t use a resource group, then we have to ensure that resources run on the same host.

There is no limit to the number of resources a group can contain. The fundamental properties of a group are as follows.

  1. Resources are started in the order in which we specify them (in our example, my_VIP first, then my_website),
  2. Resources are stopped in the reverse order in which we specify them. (my_website first, then my_VIP).

Let us check the resources that we’ve configured so far:

[pcmk01]# pcs resource show
 my_VIP 	(ocf::heartbeat:IPaddr2):       Started pcmk01-cr
 my_website     (ocf::heartbeat:apache):        Started pcmk02-cr

Create a resource group called my_webresource and specify that the VIP resource should be started before the Apache:

[pcmk01]# pcs resource group add my_webresource my_VIP my_website


[pcmk01]#  pcs resource show
 Resource Group: my_webresource
     my_VIP     (ocf::heartbeat:IPaddr2):       Started pcmk01-cr
     my_website (ocf::heartbeat:apache):        Started pcmk01-cr
[pcmk01]# pcs resource group list
my_webresource: my_VIP my_website

We now have an Apache cluster service which is accessible via (pcmk-vip).


Leave a Reply

Your e-mail address will not be published. Required fields are marked *