第 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
    FieldDescription

    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.

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 dummy0 to dummy9 prefer node1:

    # 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 resources is specified, location constraints are displayed per resource. This is the default behavior.
  • If nodes is 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 --full option:

    # pcs constraint [config] [--full]

    By default, listing resource constraints does not display expired constraints. To include expired constraints in the listing, use the --all option of the pcs constraint command. 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 ...
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2026 Red Hat
返回顶部