Chapter 6. Resource Constraints
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:
location
constraints — A location constraint determines which nodes a resource can run on. Location constraints are described in Section 6.1, “Location Constraints”.order
constraints — An order constraint determines the order in which the resources run. Order constraints are described in Section 6.2, “Order Constraints”.colocation
constraints — A colocation constraint determines where resources will be placed relative to other resources. Colocation constraints are described in Section 6.3, “Colocation of 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. For information on resource groups, see Section 5.5, “Resource Groups”.
6.1. Location Constraints
Location constraints determine which nodes a resource can run on. You can configure location constraints to determine whether a resource will prefer or avoid a specified node.
Table 6.1, “Location Constraint Options”. summarizes the options for configuring location constraints.
Field | Description | ||||||
---|---|---|---|---|---|---|---|
id
|
A unique name for the constraint. This is set by the system when you configure a location constraint with
pcs .
| ||||||
rsc
|
A resource name
| ||||||
node
|
A node’s name
| ||||||
score
|
Value to indicate the preference for whether a resource should run on or avoid a node.
A Value of
INFINITY changes "should" to "must"; INFINITY is the default score value for a resource location constraint.
| ||||||
resource-discovery
|
|
The following command creates a location constraint for a resource to prefer the specified node or nodes.
pcs constraint location rsc prefers node[=score] ...
The following command creates a location constraint for a resource to avoid the specified node or nodes.
pcs constraint location rsc avoids node[=score] ...
There are two alternative strategies for specifying which nodes a resources can run on:
- Opt-In Clusters — Configure a cluster in which, by default, no resource can run anywhere and then selectively enable allowed nodes for specific resources. The procedure for configuring an opt-in cluster is described in Section 6.1.1, “Configuring an "Opt-In" Cluster”.
- Opt-Out Clusters — Configure a cluster in which, by default, all resources an run anywhere and then create location constraints for resources that are not allowed to run on specific nodes. The procedure for configuring an opt-out cluster is described in Section 6.1.2, “Configuring an "Opt-Out" Cluster”.
Whether you should choose to configure an opt-in or opt-out cluster depends both on your personal preference and the make-up of your cluster. If most of your resources can run on most of the nodes, then an opt-out arrangement is likely to result in a simpler configuration. On the other-hand, if most resources can only run on a small subset of nodes an opt-in configuration might be simpler.
6.1.1. Configuring an "Opt-In" Cluster
To create an opt-in cluster, set the
symmetric-cluster
cluster property to false
to prevent resources from running anywhere by default.
# pcs property set symmetric-cluster=false
Enable nodes for individual resources. The following commands configure location constraints so that the resource
Webserver
prefers node example-1
, the resource Database
prefers node example-2
, and both resources can fail over to node example-3
if their preferred node fails.
#pcs constraint location Webserver prefers example-1=200
#pcs constraint location Webserver prefers example-3=0
#pcs constraint location Database prefers example-2=200
#pcs constraint location Database prefers example-3=0
6.1.2. Configuring an "Opt-Out" Cluster
To create an opt-out cluster, set the
symmetric-cluster
cluster property to true
to allow resources to run everywhere by default.
# pcs property set symmetric-cluster=true
The following commands will then yield a configuration that is equivalent to the example in Section 6.1.1, “Configuring an "Opt-In" Cluster”. Both resources can fail over to node
example-3
if their preferred node fails, since every node has an implicit score of 0.
#pcs constraint location Webserver prefers example-1=200
#pcs constraint location Webserver avoids example-2=INFINITY
#pcs constraint location Database avoids example-1=INFINITY
#pcs constraint location Database prefers example-2=200
Note that it is not necessary to specify a score of INFINITY in these commands, since that is the default value for the score.