第 11 章 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.
11.1. Configuring location constraints 复制链接链接已复制到粘贴板!
You can configure a location constraint to control which nodes a cluster resource can run on in a cluster. You can use a location constraint to make a resource prefer a specific node or to prevent it from running on certain nodes.
11.1.1. Configuring a basic location constraint 复制链接链接已复制到粘贴板!
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.
Procedure
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:
# pcs constraint location rsc prefers node[=score] [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] [node[=score]] ...The following table summarizes the meanings of the basic options for configuring location constraints:
Expand 表 11.1. Location Constraint Options Field Description rscA resource name
nodeA node’s name
scorePositive integer value to indicate the degree of preference for whether the given resource should prefer or avoid the given node.
INFINITYis the defaultscorevalue for a resource location constraint.A value of
INFINITYforscorein apcs constraint location rsc preferscommand 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
INFINITYforscorein apcs constraint location rsc avoidscommand indicates that the resource will never run on that node, even if no other node is available. This is the equivalent of setting apcs constraint location addcommand 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 itsresource-stickinessscore is higher than apreferslocation constraint’s score, then the resource will be left where it is.
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.
Procedure
The following command creates a location constraint to specify that resources
dummy0todummy9prefernode1:# pcs constraint location 'regexp%dummy[0-9]' prefers 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.
Procedure
To configure a location constraint with extended regular expressions:
# pcs constraint location 'regexp%dummy[[:digit:]]' prefers node1
11.1.4. Displaying location constraints 复制链接链接已复制到粘贴板!
You can list all current location constraints.
-
If
resourcesis specified, location constraints are displayed per resource. This is the default behavior. -
If
nodesis specified, location constraints are displayed per node. - If specific resources or nodes are specified, then only information about those resources or nodes is displayed.
Procedure
To list all current location constraints:
# pcs constraint location [config [resources [resource...]] | [nodes [node...]]] [--full]To display all current location, order, and colocation constraints, use the following command. To show the internal constraint IDS, specify the
--fulloption:# pcs constraint [config] [--full]By default, listing resource constraints does not display expired constraints. To include expired constraints in the listing, use the
--alloption of thepcs constraintcommand. This will list expired constraints, noting the constraints and their associated rules as(expired)in the display.To list the constraints that reference specific resources:
# pcs constraint ref resource ...