Configuring resource groups
In most cases, having the cluster run individual resources is not an ideal situation. Mounting a file system with web content on one node, starting an httpd instance on a second, and assigning a floating IP address to a third node does not create a service that consumers can use.
Resources can be combined into resource groups that will force all resources in a group to start and stop at the same time, on the same node, creating clustered services for consumers.
Creating a clustered Apache service
For a clustered Apache web server, a minimum of three different resources are required:
- A (floating) IP address resource with an IP address from the public network to access the content served by the Apache web server.
- A filesystem resource that provides the content to be served by the Apache web server. (In theory, it is also possible to have all web content on all nodes, but this requires a mechanism to sync the content.)
- An apache resource controlling the httpd system service.
The first step toward a clustered web service is to define an IP address resource. In order to create the cluster resource called webip, using the resource agent IPaddr2 with the floating IP address 172. 25. 99. 80/24 as part of the myweb resource group, execute:
# pcs resource create webip IPaddr2 ip=172.25.99.88 cidr_netmask=24 --group myweb
The web server will also need access to shared storage hosting the content for the web server. In order to create a Filesystem resource for a NFS mount workstation.storage1.example.com: /exports/www on /var/www, execute:
# pcs resource create webfs Filesystem \ > device=workstation.storage1.example.com:/exports/www \ > directory=/var/www \ > fstype=nfs \ > options=ro \ > --group myweb
The myweb resource group requires an Apache resource for sharing the document root content. For that, the httpd package needs to be installed and firewalld needs to allow access to the relevant ports on each cluster node the service can migrate to.
The cluster script can monitor the availability of the web server by periodically monitoring a status URL. For the monitoring to operate, the wget package must be installed on all cluster nodes that will serve the monitored Apache web server. The status URL must only be available from 127.0.0.1. To create the required status URL, the following section must be present in the httpd configuration. Using a separate file in /etc/httpd/conf.d is recommended.
<Location /server-status> SetHandler server-status Require ip 127.0.0.1 Require all denied </Location>
Other URLs can also be specified; for example, a main page or internal status page of the web application being hosted can be used to verify availability.
The resource called webserver using the apache resource agent can then be created and added to the myweb resource group with the httpd configuration file /etc/httpd/conf/httpd.conf and the status URL http://127.0.0.1/server-status, which adds monitoring to the resource.
# pcs resource create webserver apache \ > configfile="/etc/httpd/conf/httpd.conf" \ > statusurl="http://127.8.8.1/server-status" --group myweb
Tune resource operations
Every cluster resource has three operations: start, stop, and monitor.
pcs resource show webserver Resource: webserver (class=ocf provider=heartbeat type=apache) Attributes: configfile=/etc/httpd/conf/httpd.conf statusurl=http://127.0.0.1/server-status Operations: start interval=0s timeout=60 (apachefs-start-timeout-60) stop interval=0s timeout=60 (apachefs-stop-timeout-60) monitor interval=20 timeout=40 (apachefs-monitor-interval-20)
Operation parameters can be tuned by a system administrator when creating a resource by adding op operation, followed by one or more operation options:
interval=value
Defines the time between the monitoring checks. The default value is taken from the resource agent. If the resource agent does not provide a default, the value is set to 60s.
timeout=value
Defines the amount of time to wait before an operation is declared as failed if it did not complete until a timeout is reached.
on-fail=action
The action to take if the operation failed:
- ignore ignores any failure of the operation.
- block stops performing any operations. This is the default action for a failed stop operation if the cluster does not have fencing configured.
- stop stops the resource from being active in the cluster. This is the default action for a failure of the start and monitor operations.
- restart stops and starts the resource.
- fence fences the node on which the resource failed. This is the default action for a failed stop operation for a cluster with fencing configured.
- standby moves all resources away from the cluster node the resource was running on.
To create the webserver resource with a monitoring interval of 20 seconds with a timeout of 30 seconds.execute:
# pcs resource create webserver apache \ > configfile="/etc/httpd/conf/httpd.conf" \ > statusurl=0http://127.8.8.1/server-status" --group myweb \ > op monitor interval=28s timeout=30s
Resource operations can be added and removed with the pcs resource op add and pcs resource op remove commands, respectively. To remove the existing monitoring operation from the webserver resource, execute:
# pcs resource op remove webserver monitor
For setting new parameters for the monitoring operation of the webserver resource with an monitoring interval of 10 seconds and a monitoring timeout of 15 seconds, resulting in a fenced node if the monitoring operation fails, execute:
# pcs resource op add webserver monitor interval=10s timeout=15s onfail=fence
Add and remove resources from a resource group
An existing resource can be added to a resource group. For that. the cluster administrator has to execute pcs resource group add groupname name. If the resource is already a member of a group, it will be removed from the group and then added to the group specified on the command line. If the target resource group does not exist, it gets automatically created. To add the resource myresource to the mygroup resource group, execute:
# pcs resource group add mygroup myresource
A resource that is part of a resource group may be removed from the resource group with pcs resource group remove groupname name. The resource then still exists in the cluster, but is not part of the resource group any more. If the last resource is removed from the resource group, the resource group is removed as well. To remove the myresource resource from the mygroup resource group, execute:
# pcs resource group remove mygroup myresource
Resource ordering
In some cases, there might be a dependency between resources added to a group. For example, a web server configured to listen on a specific IP address won’t be able to start until that IP address is configured on a node. Normally resources will be started in the order that they are added to a group, and stopped in reverse order.
To influence the ordering, the options –before resourceid and –after resourceid can be added to pcs resource create and pcs resource group add to influence the ordering in which resources will be started.
How to Create and Configure Resources in a Pacemaker Cluster