Chapter 12. Determining which nodes a resource can run on
Chapter 12. Determining which nodes a resource can run on 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. In addition to location constraints, the node on which a resource runs is influenced by the resource-stickiness value for that resource, which determines to what degree a resource prefers to remain on the node where it is currently running. For information about setting the resource-stickiness value, see Configuring a resource to prefer its current node . 12.1. Configuring location constraints You can configure a basic location constraint to specify whether a resource prefers or avoids a node, with an optional score value to indicate the relative degree of preference for the constraint. The following command creates a location constraint for a resource to prefer the specified node or nodes. Note that it is possible to create constraints on a particular resource for more than one node with a single command. The following command creates a location constraint for a resource to avoid the specified node or nodes. The following table summarizes the meanings of the basic options for configuring location constraints. Table 12.1. Location Constraint Options Field Description rsc A resource name node A node's name score Positive integer value to indicate the degree of preference for whether the given resource should prefer or avoid the given node. INFINITY is the default score value for a resource location constraint. A value of INFINITY for score in a pcs constraint location rsc prefers command indicates that the resource will prefer that node if the node is available, but does not prevent the resource from running on another node if the specified node is unavailable. A value of INFINITY for score in a pcs constraint location rsc avoids command indicates that the resource will never run on that node, even if no other node is available. This is the equivalent of setting a pcs constraint location add command with a score of -INFINITY . A numeric score (that is, not INFINITY ) means the constraint is optional, and will be honored unless some other factor outweighs it. For example, if the resource is already placed on a different node, and its resource-stickiness score is higher than a prefers location constraint's score, then the resource will be left where it is. The following command creates a location constraint to specify that the resource Webserver prefers node node1 . pcs supports regular expressions in location constraints on the command line. These constraints apply to multiple resources based on the regular expression matching resource name. This allows you to configure multiple location constraints with a single command line. The following command creates a location constraint to specify that resources dummy0 to dummy9 prefer node1 . Since Pacemaker uses POSIX extended regular expressions as documented at http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_04 , you can specify the same constraint with the following command. 12.2. Limiting resource discovery to a subset of nodes Before Pacemaker starts a resource anywhere, it first runs a one-time monitor operation (often referred to as a "probe") on every node, to learn whether the resource is already running. This process of resource discovery can result in errors on nodes that are unable to execute the monitor. When configuring a location constraint on a node, you can use the resource-discovery option of the pcs constraint location command to indicate a 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. The following command shows the format for specifying the resource-discovery option of the pcs constraint location command. In this command, a positive value for score corresponds to a basic location constraint that configures a resource to prefer a node, while a negative value for score corresponds to a basic location`constraint that configures a resource to avoid a node. As with basic location constraints, you can use regular expressions for resources with these constraints as well. The following table summarizes the meanings of the basic parameters for configuring constraints for resource discovery. Table 12.2. Resource Discovery Constraint Parameters Field Description id A user-chosen name for the constraint itself. rsc A resource name node A node's name score Integer value to indicate the degree of preference for whether the given resource should prefer or avoid the given node. A positive value for score corresponds to a basic location constraint that configures a resource to prefer a node, while a negative value for score corresponds to a basic location constraint that configures a resource to avoid a node. A value of INFINITY for score indicates that the resource will prefer that node if the node is available, but does not prevent the resource from running on another node if the specified node is unavailable. A value of -INFINITY for score indicates that the resource will never run on that node, even if no other node is available. A numeric score (that is, not INFINITY or -INFINITY ) means the constraint is optional, and will be honored unless some other factor outweighs it. For example, if the resource is already placed on a different node, and its resource-stickiness score is higher than a prefers location constraint's score, then the resource will be left where it is. resource-discovery options * always - Always perform resource discovery for the specified resource on this node. This is the default resource-discovery value for a resource location constraint. * 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. Warning Setting resource-discovery to never or exclusive removes Pacemaker's ability to detect and stop unwanted instances of a service running where it is not supposed to be. It is up to the system administrator to make sure that the service can never be active on nodes without resource discovery (such as by leaving the relevant software uninstalled). 12.3. Configuring a location constraint strategy When using location constraints, you can configure a general strategy for specifying which nodes a resource 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. Opt-out clusters - Configure a cluster in which, by default, all resources can run anywhere and then create location constraints for resources that are not allowed to run on specific nodes. Whether you should choose to configure your cluster as an opt-in or opt-out cluster depends on both 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. 12.3.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. When configuring location constraints for an opt-in cluster, setting a score of zero allows a resource to run on a node without indicating any preference to prefer or avoid the node. 12.3.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. This is the default configuration if symmetric-cluster is not set explicitly. The following commands will then yield a configuration that is equivalent to the example in "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. 12.4. Configuring a resource to prefer its current node Resources have a resource-stickiness value that you can set as a meta attribute when you create the resource, as described in Configuring resource meta options . The resource-stickiness value determines how much a resource wants to remain on the node where it is currently running. Pacemaker considers the resource-stickiness value in conjunction with other settings (for example, the score values of location constraints) to determine whether to move a resource to another node or to leave it in place. With a resource-stickiness value of 0, a cluster may move resources as needed to balance resources across nodes. This may result in resources moving when unrelated resources start or stop. With a positive stickiness, resources have a preference to stay where they are, and move only if other circumstances outweigh the stickiness. This may result in newly-added nodes not getting any resources assigned to them without administrator intervention. By default, a resource is created with a resource-stickiness value of 0. Pacemaker's default behavior when resource-stickiness is set to 0 and there are no location constraints is to move resources so that they are evenly distributed among the cluster nodes. This may result in healthy resources moving more often than you desire. To prevent this behavior, you can set the default resource-stickiness value to 1. This default will apply to all resources in the cluster. This small value can be easily overridden by other constraints that you create, but it is enough to prevent Pacemaker from needlessly moving healthy resources around the cluster. The following command sets the default resource-stickiness value to 1. With a positive resource-stickiness value, no resources will move to a newly-added node. If resource balancing is desired at that point, you can temporarily set the resource-stickiness value to 0. Note that if a location constraint score is higher than the resource-stickiness value, the cluster may still move a healthy resource to the node where the location constraint points. For further information about how Pacemaker determines where to place a resource, see Configuring a node placement strategy .
pcs constraint location rsc prefers node [= score ] [ node [= score ]] pcs constraint location rsc avoids node [= score ] [ node [= score ]] pcs constraint location Webserver prefers node1 pcs constraint location 'regexp%dummy[0-9]' prefers node1 pcs constraint location 'regexp%dummy[[:digit:]]' prefers node1 pcs constraint location add id rsc node score [resource-discovery= option ] 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 pcs resource defaults update resource-stickiness=1