Before you start learning to troubleshoot cluster resource related topics in cluster, you must be familiar with Cluster Architecture. In my last article I had shared the steps to configure High Availability Cluster and create a cluster resource. Now next comes creating resource group and constraints in a cluster. I will also share some examples on the way to explain the resource group and constraints.
Working with constraints
A resource group is a convenient way of keeping resources together. If you have a complex dependency, however, a group is not the best possible way to define that. If the dependencies are becoming more complex, you’re better off using constraints. A constraint is a set of rules that defines how resources should be loaded.
Constraint Types
Over time, some less common constraint types have been added, but the most important constraint types are the following:
- Location: A location constraint defines on which server a resource should be loaded. You can also use it to define locations where the resource may never be loaded.
- Colocation: A colocation constraint is used to define what specific resources should be loaded together or, alternatively, that they should never be loaded together.
- Order: An order constraint is used to define a specific order. Order constraints are implicit in resource groups, but using order constraints may be more convenient, as you can define these between different types of resources. You could, for example, define that a resource group can only be loaded after some specific primitive has been loaded first.
Understanding Scores
When working with constraints, you can define priorities. To define priorities, scores are used. On every constraint, you can use a score from -1,000,000 (-INFINITY)
up to INFINITY (1,000,000)
, and you can use every value in between.
- INFINITY: must happen
- -INFINITY: may never happen
- Immediate value: expresses a stronger or weaker desire to have it happen or not happen
pcs resource move
will enforce constraints on the resource. These constraint are the type of INFINITY
so that means after the resource migration the resource will stay they are, even if something bad happens. You may have to use pcs resource clear
to remove the constraintTo express that you never want a certain action to be performed, you can use a negative score. Any score smaller than 0 will ban the resource from a node.
Understanding Resource Groups
Resources in a group are always kept together on the same node, and they will also be started in the order in which they are listed in the group.
Group benefits
- Combines resource primitives in a single entity that can be managed which means that instead of starting a resource individually you can start the group and it will start all the resources in that group
- Provides specific ordering
- Provides specific dependencies
- If using constraints, they should point at the entire group and not it's members
- Stickiness score is the sum of all member stickiness scores
Examples to create a group with a resource
Here we are creating a group ipgroup
and along with it we create two different resource which are part of ipgroup
[root@node1 ~]# pcs resource create ip1 ocf:heartbeat:IPaddr2 ip=10.0.2.50 cidr_netmask=24 --group ipgroup [root@node1 ~]# pcs resource create ip2 ocf:heartbeat:IPaddr2 ip=10.0.2.51 cidr_netmask=24 --group ipgroup
Next validate the pacemaker status, as you see our resource and group are successfully created and started
[root@node1 ~]# pcs status Cluster name: mycluster Stack: corosync Current DC: node2.example.com (version 1.1.18-11.el7_5.3-2b07d5c5a9) - partition with quorum Last updated: Sat Oct 27 12:19:36 2018 Last change: Sat Oct 27 12:19:21 2018 by root via cibadmin on node1.example.com 3 nodes configured 3 resources configured Online: [ node1.example.com node2.example.com node3.example.com ] Full list of resources: Resource Group: ipgroup ip1 (ocf::heartbeat:IPaddr2): Started node2.example.com ip2 (ocf::heartbeat:IPaddr2): Started node2.example.com Daemon Status: corosync: active/enabled pacemaker: active/enabled pcsd: active/enabled
Add exiting resource to the group
Let us clear our existing resources which we do not need for this example
[root@node1 ~]# pcs resource delete ip1 ip2 apache-ip Attempting to stop: ip1... Stopped [root@node1 ~]# pcs resource delete ip2 Attempting to stop: ip2... Stopped
So now we have two resources that we created "earlier"
[root@node1 ~]# pcs resource show apache-ip (ocf::heartbeat:IPaddr2): Started node1.example.com apache-service (ocf::heartbeat:apache): Started node2.example.com
Now let us add both these service inside apache-group
[root@node1 ~]# pcs resource group add apache-group apache-ip [root@node1 ~]# pcs resource group add apache-group apache-service
Validate the group list
[root@node1 ~]# pcs resource group list apache-group: apache-ip apache-service
Next let us create a group for our ftp server
[root@node1 ~]# pcs resource create ftp-ip ocf:heartbeat:IPaddr2 ip=10.0.2.60 cidr_netmask=24 --group ftp-group
Let us get the existing list of resource agents for ftp
[root@node1 ~]# pcs resource list | grep -i ftp service:vsftpd - systemd unit file for vsftpd systemd:vsftpd - systemd unit file for vsftpd systemd:vsftpd@ - systemd unit file for vsftpd@
vsftpd
is running properly on all the nodes of the cluster or else the resource will fail to start[root@node1 ~]# yum -y install vsftpd
Also start the service on all the nodes of the cluster
[root@node1 ~]# systemctl enable vsftpd --now Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.
vsftpd
then the service and resource both will fail to start[root@node1 ~]# pcs resource create ftp-service systemd:vsftpd --group ftp-group
Let us validate the new group list for resources
[root@node1 ~]# pcs resource group list apache-group: apache-ip apache-service ftp-group: ftp-ip ftp-service
Check the cluster status
[root@node1 ~]# pcs status Cluster name: mycluster Stack: corosync Current DC: node2.example.com (version 1.1.18-11.el7_5.3-2b07d5c5a9) - partition with quorum Last updated: Sat Oct 27 13:14:23 2018 Last change: Sat Oct 27 13:13:47 2018 by root via cibadmin on node1.example.com 3 nodes configured 4 resources configured Online: [ node1.example.com node2.example.com node3.example.com ] Full list of resources: Resource Group: apache-group apache-ip (ocf::heartbeat:IPaddr2): Started node1.example.com apache-service (ocf::heartbeat:apache): Started node1.example.com Resource Group: ftp-group ftp-ip (ocf::heartbeat:IPaddr2): Started node2.example.com ftp-service (systemd:vsftpd): Started node2.example.com Daemon Status: corosync: active/enabled pacemaker: active/enabled pcsd: active/enabled
Add constraint
Here we are giving a score of -10000
to make sure that the resources cannot be started together. -10000
expresses a strong preferences for the resources for not being together but if there is no other choice this constraint will allow the resources to be grouped together.
[root@node1 ~]# pcs constraint colocation add apache-group with ftp-group -10000
Let us add the Ordical strength
[root@node1 ~]# pcs constraint order apache-group then ftp-group Adding apache-group ftp-group (kind: Mandatory) (Options: first-action=start then-action=start)
Lastly I hope the steps from the article to understand Resource Group and Constraint in Cluster was helpful. So, let me know your suggestions and feedback using the comment section.
Hello.
In https://clusterlabs.org/pacemaker/doc/en-US/Pacemaker/1.1/html/Pacemaker_Explained/ch10.html, section 10.1 there is this comment: “Another (typical) example of a group is a DRBD volume, the filesystem mount, an IP address, and an application that uses them.”
Do you know how to add the following to a resource group??
“pcs resource create web_drbd ocf:linbit:drbd drbd_resource=drbd1 promotable promoted-max=1 promoted-node-max=1 clone-max=3 clone-node-max=1 notify=true”
I am struggling to understand the options… I get,
“Error: you can specify only one of clone, promotable, bundle or –group”
The command seems to be correct although there is some conflict. can you share your existing resource list and environment details
I have written another article with the steps to configure DRBD cluster with Pacemaker 2.0, please also check that if it helps
Really apreciate youre explanation, one question one group start on srv1 and other group on srv2 how i make to start in the same server??
You can try
and to list available constraints rule
pcs constraint all
For more details check Red Hat’s Page for Resource Constraints