4 Configuring Pacemaker Resources and Resource Groups
Pacemaker enables you to create groups of resources, such as database and file system services, so that they start in the order you specify and stop in the reverse of that order. Adding resources to the same resource group also ensures that they run on the same node.
About Pacemaker Resources and Resource Groups
A Pacemaker resource, at its most basic, is a service managed by Pacemaker. Example of resources include services for the following:
-
IP address
-
File system
-
Website
-
Database
The resources in the preceding list are known as primitive resources. Primitive resources can be grouped and cloned into more complex resources called groups and clones.
Resource Agents
Each primitive resource is managed by a resource agent script that provides Pacemaker with access to the resource through a standardized interface. Some of the standards compatible with Pacemaker are shown in the following list:
-
Open Cluster Framework (OCF)
-
Systemd
-
System Services
-
STONITH
-
Linux Standard Base (LSB)
WARNING:
LSB scripts do not always comply with the standard. See https://clusterlabs.org/ for more information.
To see the resource agents on your system, you can run the pcs resource
agents
command as shown in the following example (lots of lines have been omitted
from the sample output for brevity):
pcs resource agents
.
.
.
apache
.
.
.
IPaddr
IPaddr2
.
.
.
oracle
oralsnr
pacemaker
pacemaker
.
.
.
pcsd
pcsd
.
.
.
To see the interface standards on your system you can run the pcs resource
standards
command as shown in the following example:
pcs resource standards
lsb
ocf
service
systemd
Resource Properties
Resource properties determine which resource agent manages the resource, where to find that resource agent and which standards it conforms to. The following list describes the properties of a primitive resource:
- id
-
This is the resource name of your choice.
- class
-
The standard the resource agent conforms to.
For example:
ocf
,stonith
, orsystemd
. - description
-
Description of the resource agent.
- type
-
The type of the resource agent you need to use.
For example,
IPaddr2
,Filesystem
, orWebsite
. - provider
-
With OCF agents you can specify the provider to use for a resource (the OCF spec allows multiple vendors to supply the same resource agent).
Example values:
heartbeat
,pacemaker
.
Creating Resources
You can create a resource by using the pcs resource create
command as
shown in the following example that creates a resource for a virtual IP address:
sudo pcs resource create MyVirtualIP ocf:heartbeat:IPaddr2 ip=192.0.2.3 \
cidr_netmask=24 nic=eth1 \
op monitor interval=1s --group myapachegroup
In the preceding example:
-
MyVirtualIP is the id, or name of the resource.
-
ocf
is the class, or the standard, the resource agent conforms to. -
heartbeat
is the provider of the resource. -
IPaddr2
is the type of resource that is to be created.The following options are specified for the
IPaddr2
resource:-
ip=
192.0.2.3 specifies IP address to use for the Virtual IP Address. -
cidr_netmask=
24 specifies the netmask for the interface in CIDR format. -
nic=
eth1 The base network interface on which the IP address will be brought online.
The following operation is specified for the
IPaddr2
resource:-
op monitor interval=1s
specifies that the system checks every second whether the resource is running.
-
-
--group
myapachegroup specifies the resource group to which the resource is to be added. If the group does not exist, it is created.
Following on from the preceding example, you can create and add a second resource, this
time of type apache
, as shown in the following example:
sudo pcs resource create MyApacheWebsite ocf:heartbeat:apache \
configfile="/etc/httpd/conf/httpd.conf" \
statusurl="http://192.0.2.3/server-status" --group myapachegroup
You can confirm the status of your resources by running the pcs status
command. Depending upon your configuration, you r command output will be similar to the
following sample code block:
sudo pcs status
Cluster name: my_cluster
Cluster Summary:
* Stack: corosync (Pacemaker is running)
* Current DC: node1 (version 2.1.6-9.1.0.1.el8_9-
6fdc9deea29) - partition with quorum
* Last updated: Sat Feb 3 22:35:58 2024 on node1
* Last change: Sat Feb 3 22:33:37 2024 by root via
cibadmin on node1
* 2 nodes configured
* 4 resource instances configured
Node List:
* Online: [ node1 ]
* OFFLINE: [ node2 ]
Full List of Resources:
* Resource Group: myapachegroup:
* MyVirtualIP (ocf::heartbeat:IPaddr2): Started node1
* MyApacheWebsite (ocf::heartbeat:apache): Started node1
...
...
Daemon Status:
corosync: active/disabled
pacemaker: active/enabled
pcsd: active/enabled
Resource Start and Stop Order in a Resource Group
If the resource group in the preceding examples, myapachegroup, is started from a stopped status, the resources will be started in the order they were added to the group:
-
MyVirtualIP , the first resource to be added to the resource group, will be started first.
-
MyApacheWebsite, the second resource to be added to the resource group, will be started second.
Conversely, when the resource group is stopped, the resources will be stopped in the opposite order of that in which they were added to the group:
-
MyApacheWebsite, the last resource added to the resource group in the preceding examples, will be stopped first.
-
MyVirtualIP , the first resource added to the resource group in the preceding examples, will be stopped last.
You can also explicitly set the start order by using options --before
or
--after
when creating a resource with the pcs resource
create
command to specify the position of the resource being created
relative to a resource that already exists in the group.
The pcs resource group add
command also enables you to specify resource
sequence. See Creating a Resource Group for more
information.
Creating a Resource Group
As documented in the preceding sections, using the pcs resource create
command will create the group specified with the --group
option if it
does not already exist. A second way of creating a resource group is by using the
pcs resource group add
command, as shown in the following
example:
sudo pcs resource group add mygroup MyVirtualIP MyApacheWebsite
The preceding command creates group mygroup If it does not already exist, and adds existing resources MyVirtualIP and MyApacheWebsite to the group. If the resources specified in the command are in another group, they will be moved to the new group mygroup.
You can also use options --before
or --after
with the
pcs resource group add
command to specify the position of the
resource being created relative to a resource that already exists in the group.
See pcs(8)
and https://clusterlabs.org/ for more information on configuring resources and resource
groups.