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. Table 6.1. Location Constraint Options 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 Value to indicate the preference for whether Pacemaker should perform resource discovery on this node for the specified resource. Limiting resource discovery to a subset of nodes the resource is physically capable of running on can significantly boost performance when a large set of nodes is present. When pacemaker_remote is in use to expand the node count into the hundreds of nodes range, this option should be considered. Possible values include: always : Always perform resource discovery for the specified resource on this node. never : Never perform resource discovery for the specified resource on this node. exclusive : Perform resource discovery for the specified resource only on this node (and other nodes similarly marked as exclusive ). Multiple location constraints using exclusive discovery for the same resource across different nodes creates a subset of nodes resource-discovery is exclusive to. If a resource is marked for exclusive discovery on one or more nodes, that resource is only allowed to be placed within that subset of nodes. Note that setting this option to never or exclusive allows the possibility for the resource to be active in those locations without the cluster's knowledge. This can lead to the resource being active in more than one location if the service is started outside the cluster's control (for example, by systemd or by an administrator). This can also occur if the resource-discovery property is changed while part of the cluster is down or suffering split-brain, or if the resource-discovery property is changed for a resource and node while the resource is active on that node. For this reason, using this option is appropriate only when you have more than eight nodes and there is a way to guarantee that the resource can run only in a particular location (for example, when the required software is not installed anywhere else). always is the default resource-discovery value for a resource location constraint. The following command creates a location constraint for a resource to prefer the specified node or nodes. The following command creates a location constraint for a resource to avoid the specified node or nodes. 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. 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. 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. 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. Note that it is not necessary to specify a score of INFINITY in these commands, since that is the default value for the score.

Commands:
pcs constraint location rsc prefers node [= score ]
pcs constraint location rsc avoids node [= score ]
pcs property set symmetric-cluster=false
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
pcs property set symmetric-cluster=true
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