Chapter 11. Configuring cluster resources
A cluster resource is an instance of a program, an application, or data to be managed by the cluster service. These resources are abstracted by agents that provide a standard interface for managing the resource in a cluster environment.
To ensure that resources remain healthy, you can add a monitoring operation to a resource’s definition. If you do not specify a monitoring operation for a resource, one is added by default. You can determine the behavior of a resource in a cluster by configuring constraints for that resource. You can configure the following categories of constraints:
-
locationconstraints - A location constraint determines which nodes a resource can run on. Determining which nodes a resource can run on. -
orderconstraints - An ordering constraint determines the order in which the resources run. -
colocationconstraints - A colocation constraint determines where resources will be placed relative to other resources.
As a shorthand for configuring a set of constraints that will locate a set of resources together and ensure that the resources start sequentially and stop in reverse order, Pacemaker supports the concept of resource groups. After you have created a resource group, you can configure constraints on the group itself just as you configure constraints for individual resources.
The format for the command to create a cluster resource is as follows:
# pcs resource create resource_id [standard:[provider:]]type [resource_options] [op operation_action operation_options [operation_action operation options]...] [meta meta_options...] [clone [clone_id] [clone_options] | promotable [clone_id] [clone_options] [--wait[=n]]
Key cluster resource creation options include the following:
-
The
--beforeand--afteroptions specify the position of the added resource relative to a resource that already exists in a resource group. -
Specifying the
--disabledoption indicates that the resource is not started automatically.
There is no limit to the number of resources you can create in a cluster.
11.1. Resource creation examples Copy linkLink copied to clipboard!
The following command creates a resource with the name VirtualIP of standard ocf, provider heartbeat, and type IPaddr2. The floating address of this resource is 192.168.0.120, and the system checks whether the resource is running every 30 seconds.
# pcs resource create VirtualIP ocf:heartbeat:IPaddr2 ip=192.168.0.120 cidr_netmask=24 op monitor interval=30s
Alternately, you can omit the standard and provider fields and use the following command. This will default to a standard of ocf and a provider of heartbeat.
# pcs resource create VirtualIP IPaddr2 ip=192.168.0.120 cidr_netmask=24 op monitor interval=30s
11.2. Deleting a configured resource Copy linkLink copied to clipboard!
Delete a configured resource with the following command.
# pcs resource delete resource_id
For example, the following command deletes an existing resource with a resource ID of VirtualIP.
# pcs resource delete VirtualIP
You can delete multiple resources with a single command. The following command deletes an existing resource with a resource ID of resource1 and an existing resource with a resource ID of resource2.
# pcs resource delete resource1 resource2
11.3. Resource agent identifiers Copy linkLink copied to clipboard!
The identifiers that you define for a resource tell the cluster which agent to use for the resource, where to find that agent and what standards it conforms to.
The following table describes these properties of a resource agent.
| Field | Description |
|---|---|
| standard | The standard the agent conforms to. Allowed values and their meaning:
*
*
*
*
* |
| type |
The name of the resource agent you want to use, for example |
| provider |
The OCF spec allows multiple vendors to supply the same resource agent. Most of the agents shipped by Red Hat use |
11.4. Displaying resources and resource parameters Copy linkLink copied to clipboard!
Inspect and monitor cluster resources using pcs display commands. You can verify resource status, review configuration parameters, and list available resource agents, providers, and standards to ensure your cluster is configured correctly.
| pcs Display Command | Output |
|---|---|
|
|
Displays a description of an individual resource, the parameters you can set for that resource, and the default values for the resource. For example, |
|
| Displays a list of all configured resources. |
|
| Displays the configured parameters for a resource. |
|
| Displays the status of an individual resource. |
|
| Displays the status of the resources running on a specific node, use the following command. You can use this command to display the status of resources on both cluster and remote nodes. |
|
| Displays a list of all available resources. |
|
| Displays a list of available resource agent standards. |
|
| Displays a list of available resource agent providers. |
|
| Displays a list of available resources filtered by the specified string. You can use this command to display resources filtered by the name of a standard, a provider, or a type. |
11.5. Adding descriptions to cluster resources and elements Copy linkLink copied to clipboard!
You can add brief text descriptions to cluster resources and other Cluster Information Base (CIB) elements. Supplemental text documents your cluster configuration, provides context for specific elements, and aids administrators during troubleshooting.
Elements that support the description attribute include primitive resources, groups, clones, bundles, Access Control List (ACL) permissions, ACL roles, alerts, alert recipients, and nodes.
Procedure
To add a description to a general CIB element, use the
pcs cib element descriptioncommand:# pcs cib element description <element_id> "<description_text>"For convenience, you can also use the
pcs resource descriptionandpcs stonith descriptionaliases.
Verification
Verify that the description was applied by viewing the configuration of the modified element:
# pcs resource config <resource_id>
11.6. Configuring resource meta options Copy linkLink copied to clipboard!
In addition to the resource-specific parameters, you can configure additional resource options for any resource. These options are used by the cluster to decide how your resource should behave.
The following table describes the resource meta options.
| Field | Default | Description |
|---|---|---|
|
|
| If not all resources can be active, the cluster will stop lower priority resources in order to keep higher priority ones active. |
|
|
| Indicates what state the cluster should attempt to keep this resource in. Allowed values:
*
*
*
* |
|
|
|
Indicates whether the cluster is allowed to start and stop the resource. Allowed values: |
|
| 1 | Value to indicate how much the resource prefers to stay where it is. |
|
| Calculated | Indicates under what conditions the resource can be started.
Possible values of defaults to
*
*
*
* |
|
|
|
How many failures may occur for this resource on a node before this node is marked ineligible to host this resource. A value of 0 indicates that this feature is disabled (the node will never be marked ineligible); by contrast, the cluster treats |
|
|
|
Used in conjunction with the |
|
|
| Indicates what the cluster should do if it ever finds the resource active on more than one node. Allowed values:
*
*
*
* |
|
|
|
Sets the default value for the |
|
|
|
When set to |
11.7. Setting meta options Copy linkLink copied to clipboard!
You can set a resource option for a particular resource to a value other than the default when you create the resource. You can also set the value of a resource meta option for an existing resource, group, or cloned resource.
The following procedure provides example commands that set the value of resource meta options both on resource creation and on an existing resource.
Procedure
Create a resource with a
resource-stickinessvalue of 50.# pcs resource create VirtualIP ocf:heartbeat:IPaddr2 ip=192.168.0.120 meta resource-stickiness=50For the existing resource named
dummy_resource, set thefailure-timeoutmeta option to 20 seconds, so that the resource can attempt to restart on the same node in 20 seconds.# pcs resource meta dummy_resource failure-timeout=20sDisplay the values for the resource to verify that
failure-timeout=20sis set.# pcs resource config dummy_resourceResource: dummy_resource (class=ocf provider=heartbeat type=Dummy) Meta Attrs: failure-timeout=20s ...
11.8. Changing the default value of a resource option Copy linkLink copied to clipboard!
You can change the default value of a resource option for all resources with the pcs resource defaults update command.
Procedure
The following command resets the default value of
resource-stickinessto 100:# pcs resource defaults update resource-stickiness=100The original
pcs resource defaults name=valuecommand, which set defaults for all resources in previous releases, remains supported unless there is more than one set of defaults configured. However,pcs resource defaults updateis now the preferred version of the command.
11.9. Changing the default value of a resource option for sets of resources Copy linkLink copied to clipboard!
You can create multiple sets of resource defaults with the pcs resource defaults set create command, which allows you to specify a rule that contains resource expressions. Only resource and date expressions, including and, or and parentheses, are allowed in rules that you specify with this command.
With the pcs resource defaults set create command, you can configure a default resource value for all resources of a particular type. If, for example, you are running databases which take a long time to stop, you can increase the resource-stickiness default value for all resources of the database type to prevent those resources from moving to other nodes more often than you want.
Procedure
The following command sets the default value of
resource-stickinessto 100 for all resources of typepqsql:# pcs resource defaults set create id=pgsql-stickiness meta resource-stickiness=100 rule resource ::pgsqlIn this example,
::pgsqlmeans a resource of any class, any provider, of typepgsql.-
Specifying
ocf:heartbeat:pgsqlwould indicate classocf, providerheartbeat, typepgsql, -
Specifying
ocf:pacemaker:would indicate all resources of classocf, providerpacemaker, of any type.
-
Specifying
The
idoption, which names the set of resource defaults, is not mandatory. If you do not set this optionpcswill generate an ID automatically. Setting this value allows you to provide a more descriptive name.To change the default values in an existing set, use the
pcs resource defaults set updatecommand.
11.10. Displaying currently configured resource defaults Copy linkLink copied to clipboard!
The pcs resource defaults [config] command displays currently configured default values for resource options, including specified rules. Output can be displayed in text, JSON, or command format.
The pcs resource defaults [config] command supports the following output formats:
-
Specifying
--output-format=textdisplays the configured resource defaults in plain text format, which is the default format for this option. -
Specifying
--output-format=cmddisplays thepcs resource defaultscommands created from the current cluster defaults configuration. Use these commands to re-create configured resource defaults on another system. -
Specifying
--output-format=jsondisplays the configured resource defaults in JSON format, which is suitable for machine parsing.
The following example procedure demonstrates the output formats of the pcs resource defaults config command after configuring default values for a resource.
Procedure
Set default values for an
ocf:pacemaker:pgsqlresource:# pcs resource defaults set create id=set-1 score=100 meta resource-stickiness=10 rule resource ocf:pacemaker:pgsqlDisplay the configured resource default values in plain text:
# pcs resource defaults config Meta Attrs: build-resource-defaults resource-stickiness=1 Meta Attrs: set-1 score=100 resource-stickiness=10 Rule: boolean-op=and score=INFINITY Expression: resource ocf:pacemaker:pgsqlDisplay the
pcs resource defaultscommands created from the current cluster defaults configuration:# pcs resource defaults config --output-format=cmdpcs -- resource defaults set create id=build-resource-defaults \ meta resource-stickiness=1; pcs -- resource defaults set create id=set-1 score=100 \ meta resource-stickiness=10 \ rule 'resource ocf:pacemaker:pgsql'Display the configured resource default values in JSON format:
# pcs resource defaults config --output-format=json{"instance_attributes": [], "meta_attributes": [{"id": "build-resource-defaults", "options": {}, "rule": null, "nvpairs": [{"id": "build-resource-stickiness", "name": "resource-stickiness", "value": "1"}]}, {"id": "set-1", "options": {"score": "100"}, "rule": {"id": "set-1-rule", "type": "RULE", "in_effect": "UNKNOWN", "options": {"boolean-op": "and", "score": "INFINITY"}, "date_spec": null, "duration": null, "expressions": [{"id": "set-1-rule-rsc-ocf-pacemaker-pgsql", "type": "RSC_EXPRESSION", "in_effect": "UNKNOWN", "options": {"class": "ocf", "provider": "pacemaker", "type": "pgsql"}, "date_spec": null, "duration": null, "expressions": [], "as_string": "resource ocf:pacemaker:pgsql"}], "as_string": "resource ocf:pacemaker:pgsql"}, "nvpairs": [{"id": "set-1-resource-stickiness", "name": "resource-stickiness", "value": "10"}]}]}
11.11. Configuring resource groups Copy linkLink copied to clipboard!
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 resource groups.
Creating a resource group
You can create a resource group with the following command, specifying the resources to include in the group. If the group does not exist, this command creates the group. If the group exists, this command adds additional resources to the group. The resources will start in the order you specify them with this command, and will stop in the reverse order of their starting order.
# pcs resource group add group_name resource_id [resource_id] ... [resource_id] [--before resource_id | --after resource_id]
You can use the --before and --after options of this command to specify the position of the added resources relative to a resource that already exists in the group.
You can also add a new resource to an existing group when you create the resource, using the following command. The resource you create is added to the group named group_name. If the group group_name does not exist, it will be created.
# pcs resource create resource_id [standard:[provider:]]type [resource_options] [op operation_action operation_options] --group group_name
There is no limit to the number of resources a group can contain. The fundamental properties of a group are as follows.
- Resources are colocated within a group.
- Resources are started in the order in which you specify them. If a resource in the group cannot run anywhere, then no resource specified after that resource is allowed to run.
- Resources are stopped in the reverse order in which you specify them.
Additional properties of a group are as follows:
-
You can set the following options for a resource group, and they maintain the same meaning as when they are set for a single resource:
priority,target-role,is-managed. For information about resource meta options, see Configuring resource meta options. -
Stickiness, the measure of how much a resource wants to stay where it is, is additive in groups. Every active resource of the group will contribute its stickiness value to the group’s total. So if the default
resource-stickinessis 100, and a group has seven members, five of which are active, then the group as a whole will prefer its current location with a score of 500.
The following example creates a resource group named shortcut that contains the existing resources IPaddr and Email.
# pcs resource group add shortcut IPaddr Email
In this example:
-
The
IPaddris started first, thenEmail. -
The
Emailresource is stopped first, thenIPAddr. -
If
IPaddrcannot run anywhere, neither canEmail. -
If
Emailcannot run anywhere, however, this does not affectIPaddr.
Removing a resource group
You remove a resource from a group with the following command. If there are no remaining resources in the group, this command removes the group itself.
# pcs resource group remove group_name resource_id...
Displaying resource groups
The following command lists all currently configured resource groups.
# pcs resource group list
11.12. Displaying resource dependencies Copy linkLink copied to clipboard!
You can display the relations between cluster resources in a tree structure.
# pcs resource relations resource [--full]
If the --full option is used, the command displays additional information, including the constraint IDs and the resource types.
In the following example, there are 3 configured resources: C, D, and E.
# pcs constraint order start C then start D
Adding C D (kind: Mandatory) (Options: first-action=start then-action=start)
# pcs constraint order start D then start E
Adding D E (kind: Mandatory) (Options: first-action=start then-action=start)
# pcs resource relations C
C
`- order
| start C then start D
`- D
`- order
| start D then start E
`- E
# *pcs resource relations D*
D
|- order
| | start C then start D
| `- C
`- order
| start D then start E
`- E
# pcs *resource relations E*
E
`- order
| start D then start E
`- D
`- order
| start C then start D
`- C
In the following example, there are 2 configured resources: A and B. Resources A and B are part of resource group G.
# pcs resource relations A
A
`- outer resource
`- G
`- inner resource(s)
| members: A B
`- B
# *pcs resource relations B*
B
`- outer resource
`- G
`- inner resource(s)
| members: A B
`- A
# *pcs resource relations G*
G
`- inner resource(s)
| members: A B
|- A
`- B