第 11 章 确定资源可在哪些节点上运行
位置限制决定资源可在哪些节点上运行。您可以配置位置限制,以确定资源是否首选或避免指定节点。
除了位置约束外,资源运行的节点还受到该资源的 resource-stickiness
值的影响,这决定了资源在当前运行的节点上的保留程度。有关设置 resource-stickiness
值的详情,请参考 配置资源以首选其当前节点。
11.1. 配置位置限制 复制链接链接已复制到粘贴板!
您可以配置基本的位置约束,以指定资源是首选某个节点还是避免某个节点,使用可选的 score
值来指示约束的相对首选程度。
以下命令为资源创建一个位置约束,以偏好指定节点。请注意,可以使用单个命令为多个节点在特定资源上创建限制。
pcs constraint location rsc prefers node[=score] [node[=score]] ...
pcs constraint location rsc prefers node[=score] [node[=score]] ...
以下命令为资源创建一个位置约束,以避免指定节。
pcs constraint location rsc avoids node[=score] [node[=score]] ...
pcs constraint location rsc avoids node[=score] [node[=score]] ...
下表总结了配置位置限制的基本选项的含义。
项 | 描述 |
---|---|
| 资源名称 |
| 节点的名称 |
|
正整数值来指示给定资源应首选的资源还是避免给定节点的首选程度。
一个数字分数(即不是 |
11.1.1. 配置基本位置约束 复制链接链接已复制到粘贴板!
以下命令创建了一个位置约束,以指定资源 Webserver
首选节点 node1
。
pcs constraint location Webserver prefers node1
# pcs constraint location Webserver prefers node1
11.1.2. 使用正则表达式配置位置约束 复制链接链接已复制到粘贴板!
pcs
支持命令行中的位置限制中的正则表达式。这些限制适用于基于正则表达式匹配资源名称的多个资源。这可让您使用单一命令行配置多个位置限制。
以下命令创建了一个位置约束,从资源 dummy0
到 dummy9
都首选 node1
。
pcs constraint location 'regexp%dummy[0-9]' prefers node1
# pcs constraint location 'regexp%dummy[0-9]' prefers node1
11.1.3. 使用扩展正则表达式配置位置约束 复制链接链接已复制到粘贴板!
因为 Pacemaker 使用 POSIX 扩展正则表达式,如 http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_04 所述,您可以使用以下命令指定相同的约束。
pcs constraint location 'regexp%dummy[[:digit:]]' prefers node1
# pcs constraint location 'regexp%dummy[[:digit:]]' prefers node1
11.1.4. 显示位置限制 复制链接链接已复制到粘贴板!
以下命令列出所有当前位置限制。
-
如果指定了
resources
,则会按资源显示位置约束。这是默认的行为。 -
如果指定了
nodes
,则按节点显示位置约束。 - 如果指定了特定资源或节点,则只显示那些资源或节点的信息。
pcs constraint location [config [resources [resource...]] | [nodes [node...]]] [--full]
pcs constraint location [config [resources [resource...]] | [nodes [node...]]] [--full]
您可以使用以下命令显示所有当前位置、顺序和托管约束。要显示内部约束 IDS,请指定 --full
选项。
pcs constraint [config] [--full]
pcs constraint [config] [--full]
默认情况下,列出资源约束不会显示过期的限制。要在列表中包含已过期的 constaints,请使用 pcs constraint
命令的 --all
选项。这将列出已过期的限制,请注意显示中的限制及其关联的规则为 (expired)
。
以下命令列出引用特定资源的约束。
pcs constraint ref resource ...
pcs constraint ref resource ...