16.2. 使用规则配置 Pacemaker 位置约束
使用以下命令配置使用规则的 Pacemaker 约束。
pcs constraint location rsc rule [resource-discovery=option] [role=promoted|unpromoted] [score=score | score-attribute=attribute] expression
pcs constraint location rsc rule [resource-discovery=option] [role=promoted|unpromoted] [score=score | score-attribute=attribute] expression
-
如果省略
score
,则默认为 INFINITY。 -
当使用规则来配置位置约束时,
score
的值可以是正数,也可以是负数,正数表示"首选",负数表示"避免"。 -
如果省略
resource-discovery
,则默认为always
。有关resource-discovery
选项的信息,请参阅 将资源发现限制到节点的子集。 - 与基本位置限制一样,您也可以使用这些限制的资源使用正则表达式。
16.2.1. Pacemaker 规则中的 expression 选项 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
expression 选项可以是以下之一,其中 duration_options 和 date_spec_options 是:hours, months, weeks 和 years,如 Pacemaker 规则 中的 "Properties of a Date Specification" 表中所述。
-
defined|not_defined attribute
-
attribute lt|gt|lte|gte|eq|ne [string|integer|number|version] value
-
date gt|lt date
-
date in_range date to date
-
date in_range date to duration duration_options …
-
date-spec date_spec_options
-
expression 和|或 expression
-
(表达式)
16.2.2. Pacemaker 规则中的持续时间 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
请注意,持续时间是通过计算方式为 in_range
操作指定结束的方法。例如,您可以指定 19 个月的持续时间。支持的 duration
选项的值是 seconds
,minutes
,hours
,days
,weeks
,months
和 years
。
下面的位置约束配置一个满足以下位置的表达式(如果现在是 2018 年)。
pcs constraint location Webserver rule score=INFINITY date-spec years=2018
# pcs constraint location Webserver rule score=INFINITY date-spec years=2018
以下命令配置一个周一到周五从上午 9 点下午 5 点为 true 的表达式。请注意,小时值为 16 可以匹配到 16:59:59,因为小时数仍然匹配。
pcs constraint location Webserver rule score=INFINITY date-spec hours="9-16" weekdays="1-5"
# pcs constraint location Webserver rule score=INFINITY date-spec hours="9-16" weekdays="1-5"
以下命令配置一个在 13 号是星期五为真的表达式。
pcs constraint location Webserver rule date-spec weekdays=5 monthdays=13
# pcs constraint location Webserver rule date-spec weekdays=5 monthdays=13