Show Table of Contents
5.6. 资源操作
为保证资源正常工作,可在资源定义中添加监控操作。如果没有为资源指定监控操作,默认情况下
pcs 命令会创建一个监控操作,操作间隔由资源代理决定。如果资源代理未提供默认监控间隔,则 pcs 命令将创建一个以 60 秒为间隔的监控操作。
在 表 5.4 “操作属性” 中总结了资源监控操作的属性。
表 5.4. 操作属性
| 项 | 描述 |
|---|---|
id
| |
name
| |
interval
| |
timeout
| |
on-fail
|
操作从未失败时采用的动作。允许值为:
*
ignore - 假设资源未失败
*
block - 不对该资源执行任何进一步的操作。
*
stop - 停止该资源且不在任何其他位置启动。
*
restart - 停止该资源并重新启动(可能是在不同节点中)。
*
fence - 使用 STONITH 隔离资源失败的节点。
*
standby - 将全部资源从资源失败的节点中移除。
|
enabled
|
可在创建资源时使用以下命令配置监控操作。
pcs resource create resource_id standard:provider:type|type [resource_options] [op operation_action operation_options [operation_type operation_options]...]
例如:以下命令创建附带监控操作的
IPaddr2 资源。新资源名为 VirtualIP,IP 地址 192.168.0.99,子网掩码为 eth2 中的 24。监控操作每隔 30 秒执行一次。
# pcs resource create VirtualIP ocf:heartbeat:IPaddr2 ip=192.168.0.99 cidr_netmask=24 nic=eth2 op monitor interval=30s
# pcs resource create my_address IPaddr2 ip=10.20.30.40 cidr_netmask=24 op monitor
也可以使用以下命令在现有资源中添加监控操作。
pcs resource op add resource_id operation_action [operation_properties]
使用以下命令删除配置的资源操作。
pcs resource op remove resource_id operation_name operation_properties
注意
必须指定具体操作属性方可正确删除现有操作。
要更改监控选项值,可删除现有操作,然后添加新操作。例如:可使用以下命令创建
VirtualIP。
# pcs resource create VirtualIP ocf:heartbeat:IPaddr2 ip=192.168.0.99 cidr_netmask=24 nic=eth2
默认情况下这个命令创建三个操作。
Operations: start interval=0s timeout=20s (VirtualIP-start-timeout-20s)
stop interval=0s timeout=20s (VirtualIP-stop-timeout-20s)
monitor interval=10s timeout=20s (VirtualIP-monitor-interval-10s)
请执行以下命令更改停止超时操作。
#pcs resource op remove VirtualIP stop interval=0s timeout=20s#pcs resource op add VirtualIP stop interval=0s timeout=40s#pcs resource show VirtualIPResource: 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 timeout=20s (VirtualIP-monitor-interval-10s) stop interval=0s timeout=40s (VirtualIP-name-stop-interval-0s-timeout-40s)
请使用以下命令获取监控操作全局默认值。
pcs resource op defaults [options]
例如:使用以下命令为所有监控操作将全局
timeout 值设定为 240s。
# pcs resource op defaults timeout=240s
要显示当前配置的监控操作默认值,请不要在执行
pcs resource op defaults 命令是指定任何选项。
例如:以下命令显示集群的默认监控操作,已为该操作配置
timeout 值 240s。
# pcs resource op defaults
timeout: 240s
Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.