22.2. 配置全局资源操作默认
您可以使用 pcs resource op defaults update
命令为所有资源更改资源操作的默认值。
以下命令为所有监控操作设置 timeout
值 240 秒。
# pcs resource op defaults update timeout=240s
原始的 pcs resource defaults name=value
命令(在以前的版本中为所有资源设置默认值)仍然被支持,除非设置了多组默认值。但是,pcs resource op defaults update
是该命令的首选版本。
22.2.1. 覆盖特定于资源的操作值
请注意,只有在集群资源定义中没有指定该选项时,集群资源才会使用全局默认值。默认情况下,资源代理为所有操作定义 timeout
选项。要接受全局操作超时值,您必须明确地创建没有 timeout
选项的集群资源,或者您必须通过更新集群资源来删除 timeout
选项,如以下命令所示。
# pcs resource update VirtualIP op monitor interval=10s
例如,在为所有监控操作设置了一个 240 秒的 timeout
值,并更新集群资源 VirtualIP
来删除 monitor
操作的超时值后,资源 VirtualIP
的 start
、stop
和 monitor
操作的超时值将分别为 20s、40s 和 240s。这里,超时操作的全局默认值仅应用于 monitor
操作,其中默认的 timeout
选项已被上一条命令删除。
# pcs resource config VirtualIP
Resource: VirtualIP (class=ocf provider=heartbeat type=IPaddr2)
Attributes: ip=192.168.0.99 cidr_netmask=24 nic=eth2
Operations: start interval=0s timeout=20s (VirtualIP-start-timeout-20s)
monitor interval=10s (VirtualIP-monitor-interval-10s)
stop interval=0s timeout=40s (VirtualIP-name-stop-interval-0s-timeout-40s)
22.2.2. 更改一组资源操作的默认值
您可以使用 pcs resource op defaults set create
命令创建多组资源操作默认值,该命令允许您指定包含 resource
和操作表达式的规则。Pacemaker 支持的所有规则表达式都被允许。
使用此命令,您可以为特定类型的所有资源配置默认资源操作值。例如,在使用捆绑包时,可以配置 Pacemaker 创建的隐式 podman
资源。
以下命令为所有 podman
资源操作设定默认的超时值 90s。在本例中,::podman
是指类型为 podman
的任何类、任何供应商的资源。
id
选项用来命名资源操作默认选项,当并不强制使用。如果您没有设定此选项, pcs
则会自动生成 ID。设置这个值可让您提供更描述性的名称。
# pcs resource op defaults set create id=podman-timeout meta timeout=90s rule resource ::podman
以下命令为所有资源的 stop
操作设置默认的超时值 120s。
# pcs resource op defaults set create id=stop-timeout meta timeout=120s rule op stop
对于特定类型的所有资源,可以为特定的操作设置默认值。以下示例为所有 podman
资源设置 stop
操作的默认超时值 120s。
# pcs resource op defaults set create id=podman-stop-timeout meta timeout=120s rule resource ::podman and op stop
22.2.3. 显示当前配置的资源操作默认值
pcs resource op defaults [config]
命令显示目前配置的资源操作的默认值的列表,包括您指定的任何规则。从 Red Hat Enterprise Linux 9.5 开始,您可以以文本、JSON 和命令格式显示这个命令的输出。
-
指定
--output-format=text
以纯文本格式显示配置的资源操作默认值,这是此选项的默认值。 -
指定
--output-format=cmd
显示从当前集群默认值配置创建的pcs resource op defaults
命令。您可以使用这些命令在不同的系统上重新创建配置的资源操作默认值。 -
指定
--output-format=json
以 JSON 格式显示配置的资源操作默认值,这适用于机器解析。
以下示例显示了使用此示例命令重置了任何 ocf:pacemaker:podman
资源的默认资源操作值后 pcs resource op defaults config
命令的三种不同输出格式:
# pcs resource op defaults set create id=op-set-1 score=100 meta timeout=30s rule op monitor and resource ocf:pacemaker:podman
Warning: Defaults do not apply to resources which override them with their own defined values
本例以纯文本形式显示了配置的资源操作默认值。
# pcs resource op defaults config Meta Attrs: op-set-1 score=100 timeout=30s Rule: boolean-op=and score=INFINITY Expression: op monitor Expression: resource ocf:pacemaker:podman
本例显示了从当前集群默认值配置创建的 pcs resource op defaults
命令。
# pcs resource op defaults config --output-format=cmd pcs -- resource op defaults set create id=op-set-1 score=100 \ meta timeout=30s \ rule 'op monitor and resource ocf:pacemaker:podman'
本例以 JSON 格式显示了配置的资源操作默认值。
# pcs resource op defaults config --output-format=json {"instance_attributes": [], "meta_attributes": [{"id": "op-set-1", "options": {"score": "100"}, "rule": {"id": "op-set-1-rule", "type": "RULE", "in_effect": "UNKNOWN", "options": {"boolean-op": "and", "score": "INFINITY"}, "date_spec": null, "duration": null, "expressions": [{"id": "op-set-1-rule-op-monitor", "type": "OP_EXPRESSION", "in_effect": "UNKNOWN", "options": {"name": "monitor"}, "date_spec": null, "duration": null, "expressions": [], "as_string": "op monitor"}, {"id": "op-set-1-rule-rsc-ocf-pacemaker-podman", "type": "RSC_EXPRESSION", "in_effect": "UNKNOWN", "options": {"class": "ocf", "provider": "pacemaker", "type": "podman"}, "date_spec": null, "duration": null, "expressions": [], "as_string": "resource ocf:pacemaker:podman"}], "as_string": "op monitor and resource ocf:pacemaker:podman"}, "nvpairs": [{"id": "op-set-1-timeout", "name": "timeout", "value": "30s"}]}]}