根据红帽高可用组件配置指南编写,只截取了简单部分,详细内容参考原文或pcs帮助文档
每个节点都执行:
安装
yum -y install pcs pacemaker fence-agents-all
启动
systemctl enable --now pcsd
密码
echo 'pacemakerFortristack' | passwd --stdin hacluster
在第一个节点执行验证
pcs cluster auth cnode1 cnode2 cnode3
在第一个节点执行
pcs cluster setup --name mycluster cnode1 cnode2 cnode3
pcs cluster start --all
第一节点添加远程节点
pcs cluster auth cnode4
pcs cluster node add-remote cnode4
第一节点添加stonith
[root@cnode1 ~]# pcs stonith create cnode1_ipmi fence_ipmilan pcmk_host_list=cnode1 ipaddr=192.168.3.11 login=ADMIN passwd=ADMIN lanplus=1 cipher=1 op monitor interval=60s
[root@cnode1 ~]# pcs stonith create cnode2_ipmi fence_ipmilan pcmk_host_list=cnode2 ipaddr=192.168.3.12 login=ADMIN passwd=ADMIN lanplus=1 cipher=1 op monitor interval=60s
[root@cnode1 ~]# pcs stonith create cnode3_ipmi fence_ipmilan pcmk_host_list=cnode3 ipaddr=192.168.3.13 login=ADMIN passwd=ADMIN lanplus=1 cipher=1 op monitor interval=60s
[root@cnode1 ~]# pcs stonith create cnode4_ipmi fence_ipmilan pcmk_host_list=cnode4 ipaddr=192.168.3.14 login=ADMIN passwd=ADMIN lanplus=1 cipher=1 op monitor interval=60s
配置位置
[root@cnode1 ~]# pcs constraint location cnode1_ipmi avoids cnode1
[root@cnode1 ~]# pcs constraint location cnode2_ipmi avoids cnode2
[root@cnode1 ~]# pcs constraint location cnode3_ipmi avoids cnode3
[root@cnode1 ~]# pcs constraint location cnode4_ipmi avoids cnode4
pcs stonith list [filter]
pcs stonith disable stonith_id # 禁用隔离设备,这会阻止任何节点使用该设备
pcs constraint location cnode1_ipmilan avoids cnode1 # 配置位置avoid
pcs property set stonith-enabled=false # 将完全禁用所有隔离设备
| 字段 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| pcmk_host_map | string | A mapping of host names to port numbers for devices that do not support host names. For example: node1:1;node2:2,3 tells the cluster to use port 1 for node1 and ports 2 and 3 for node2 | |
| pcmk_host_list | string | 此设备控制的机器列表(可选,当pcmk_host_check=static-list时必选) | |
| pcmk_host_check | string | dynamic-list | 如何确定被设备控制的机器。允许的值: dynamic-list (查询设备)、static-list (检查 pcmk_host_list 属性)、none(假设每个设备都可以隔离每台机器) |
pcs stonith describe stonith_agent
pcs stonith create cnode1_ipmi fence_ipmilan pcmk_host_list=cnode1 ipaddr=192.168.3.11 login=ADMIN passwd=ADMIN lanplus=1 cipher=1 op monitor interval=60s
一些fence设备需要主机名映射到fence设备能理解的格式,比如加端口
pcs stonith show [stonith_id] [--full]
pcs stonith update stonith_id [stonith_device_options]
pcs stonith delete stonith_id
pcs stonith fence nodexx [--off] # 指定了off,会调用stonith来关闭节点,而不是重启
如果 stonith 设备无法隔离节点,即使它不再活跃,集群可能无法恢复该节点中的资源。
如果发生了这种情况,在手动确定该节点已关闭后,您可以输入以下命令向集群确认节点已关闭,并释放其资源以用于恢复。
pcs stonith confirm nodexx
pcmk支持多个设备来fence一个节点,这叫做fencing topologies。要使用拓扑,先像平时一样创建独立fence设备,然后定义一个或多个fence等级。
添加隔离的级别
pcs stonith level add level node devices # devices以逗号分隔
列出
pcs stonith level
举个例子
# pcs stonith level add 1 rh7-2 my_ilo
# pcs stonith level add 2 rh7-2 my_apc
# pcs stonith level
Node: rh7-2
Level 1 - my_ilo
Level 2 - my_apc
删除level和清理
pcs stonith level remove level [node_id] [stonith_id] ... [stonith_id]
pcs stonith level clear [node|stonith_id(s)]
pcs resource create resource_id type [resource_options] [op opeation_options]
pcs resource delete resource_id
pcs resource list # 列举所有可用资源
pcs resource list # 根据filter过滤
pcs resource describe [standard:provider:]type # 查看资源option
pcs resource meta resource_id|group_id|clone_id|master_id meta_options
pcs resource show resource_id # 查看资源详情
pcs resource defaults [options] # 设置资源默认值,如resource-stickiness=100
pcs resource group list
pcs resource group add # 无此group,则顺势添加
pcs resource group remove
三种操作: monitor start stop
属性有:timeout, on-fail, enabled, interval, name, id
pcs resource op add resource_id operation_action [operation_properties] # 添加操作
pcs resource op remove resource_id operation_name operation_properties
只能这样更新:
pcs resource update VirtualIP op stop interval=0s timeout=40s # 没有列出的选项都将重置为默认值
pcs resource [show] # 列举所有已配置的资源
pcs resource show resource_id # 展示资源参数详情
pcs resource update resource_id [resource_options]
如:pcs resource update VirtualIP ip=192.168.0.120
见8.5
允许同一资源在不同时刻进行不同的监控操作
pcs resource op add VirtualIP monitor interval=60s OCF_CHECK_LEVEL=10
pcs resource enable resource_id
pcs resource disable resource_id
pcs resource failcount show httpd # 故障计数
pcs resource failcount reset httpd # 清理计数
pcs resource cleanup # 针对失败的资源,忘记资源操作历史记录并重新检测当前状态
pcs resource cleanup resource_id # 清理指定的resource
pcs resource refresh # 针对所有状态资源
位置约束、顺序约束、共存约束(资源相对于其他资源的位置)
location order colocation
资源运行在哪个节点除了 位置限制 还有 资源粘性 的影响
以下命令为资源创建位置约束,指定偏好节点:
pcs constraint location resource_id prefers node=[score] [node=[score]] ... INFINITY是默认分数值
以下命令为资源创建位置约束,指定避免节点:
pcs constraint location resource_id avoids node=[score] [node=[score]] ...
redhat7.4开始支持正则,通过正则表达式指定dummy0到dummy9位置限制:
pcs constraint location 'regexp%dummy[0-9]' prefers node1 # or dummy[[:digit:]]
pcs constraint location命令的 resource-discovery 选项,是否应该为指定资源在该节点上执行资源发现。在大量节点时显著提高性能
命令为:
pcs constraint location add id resource_id node score [resource-discovery=option]
其中的option可以为:
更复杂的位置约束,使用第11章的pacemaker rules,如下:
pcs constraint location resource_id rule [resource-discovery=option] [role=master|slave] [score=socre] expression
expression选项是以下之一:
以下命令配置一个周一到周五从上午 9 点下午 5 点为 true 的表达式。请注意,小时值为 16 可以匹配到 16:59:59,因为小时数仍然匹配
pcs constraint location WebServer rule score=INIFITY date-spec hours="9-16" weekdays="1-5"
配置opt-in集群,首先
pcs property set symmetric-cluster=false
# pcs constraint location Webserver prefers example-1=200
# pcs constraint location Webserver prefers example-3=0
# pcs constraint location Database prefers example-2=200
# pcs constraint location Database prefers example-3=0
设置为0分,表示可运行在此节点上,但不是首选
配置opt-out集群,首先
pcs property set symmetric-cluster=true
# pcs constraint location Webserver prefers example-1=200
# pcs constraint location Webserver avoids example-2=INFINITY
# pcs constraint location Database avoids example-1=INFINITY
# pcs constraint location Database prefers example-2=200
两个资源都可切换到节点 example-3
pcs resource defaults resource-stickiness=1
粘性设置为0时,Pacemaker 的默认行为是移动资源,以便在集群节点中平均分配这些资源。这可能导致健康的资源变化频率超过您的要求。
所以设置为1,这个小值可以被您创建的其他限制轻松覆盖,但可以防止 Pacemaker 在集群中无用地移动处于健康状态的资源
如果位置约束分数高于资源粘性值,集群仍然可以将健康资源移至位置约束点的节点
pcs constraint order [action] resource_id then [action] resource_id [options]
action可能的值有:start / stop / promote / demote
option可能的项目有:
kind optional(), mandatory(若第一个资源停止,则第二个资源必须停止), serialize()
symmetrical(true:按反序停止)
pcs constraint order set RSC1 RSC2 RSC3
pcs constraint order remove RSC1 RSC2 RSC3
pcs constraint colocation add [master|slave] source_resource with [master|slave] target_resource [score] [options]
source_resource 依赖 target_resource,所以先决定target的位置,然后source也就确定了
score 正数表示运行在同一节点上,负数表示否。默认+INFINITY
当score为+INFINITY或-INFINITY时,强制放置,不满足情况则source_resource不运行
如,要求RSC1和RSC2始终在同一台机器中运行:
pcs constraint colocation add RSC1 with RSC2 score=INFINITY。。若RSC2无法在任何节点上运行,则不允许RSC1运行
强制放置是must,advisory放置是I would prefer if,
pcs constraint colocation set RSC1 RSC2 with RSC3 RSC4 … 表示RSC1 RSC2是有关系的,这里是RSC3 RSC4集合的共存关系
pcs constraint colocation remove source_resource target_resource
pcs constraint [show|list] # 列出所有限制
pcs constraint location [show [resources|nodes [ | ]...] [--full]]
如:pcs constraint location show resources openstack-nova-compute-clone
pcs constraint order show # 列出所有顺序限制
pcs constraint colocation show [--full] # 显示所有colocation
pcs constraint ref resource_id # 列出引用特定资源的约束
pcs resource move resource_id [dest-node] [--master] [lifetime=lifetime]
执行如上命令时,实际上是添加constraint INFINITY or -INFINITY
可使用pcs resource clear / pcs constraint delete 命令删除
如果指定--master,则约束范围仅为master角色的资源,必须指定master_id而不是resource_id
修改集群参数
pcs property set cluster-recheck-interval=value
这样就可以在move的时候指定lifetime了
pcs resource move resource1 node2 lifetime=PT1H30M # 区别Month和Minute,Minute前加PT
由于故障转移或手动移动,资源可能不在原始节点上,要想重定位到首选节点上
pcs resource relocate run [resource1] [resource2] ... # 若未指定任何资源,则所有资源重定位到首选节点
删除由pcs resource relocate run创建的限制,使用pcs resource relocate clear
显示资源的当前状态及最佳节点 忽略资源粘性 输入 pcs resource relocate show
创建资源时,可为资源设置migration-threshold,使其在多个故障后迁移至新节点
直到 pcs resource failcount reset 重新计数后
migration-threshold默认为INFINITY
例如,为RSC1添加一个迁移阈值为10,表示资源在10个故障后将迁移到新节点
pcs resource meta RSC1 migration-threshold=10
以下为整个集群设置迁移阈值的默认值
pcs resource defaults migration-threshold=10
有特殊情况:
若集群有属性start-failure-is-fatal为true(默认值),资源启动失败会导致故障计数为INFINITY,
所以资源会立马迁移
停止失败不同,若没启用STONITH,集群将无法继续
创建一个ping资源,创建为clone,一遍资源在所有节点中运行
pcs resource create ping ocf:pacemaker:ping dampen=5s multiplier=1000 host_list=192.168.4.11 clone
如下,配置WebServer的位置约束规则,若当前运行主机无法ping桶4.11,则WebServer将移至能ping 通4.11的主机
pcs constraint location WebServer rule score=-INFINITY pingd lt 1 or not_defined pingd
禁用和启用
pcs resource disable resource_id [--wait=[n]] # 指定了wait,但不指定n,默认60min,试了,并不是
pcs resource eanble resource_id [--wait=[n]]
禁止,相当于添加-INFINITY的位置约束
pcs resource ban resource_id [node] [--master] [lifetime=lifetime] [--wait=[n]]
可执行pcs resource clear或者pcs constraint delete删除约束
重启
pcs resource restart resource_id # 只能重启已运行的资源
debug-start
pcs resource debug-start resource_id # 可以看到启动是否成功,失败原因
pcs cluster start --all 启动所有资源,失败日志在/var/log/cluster/corosync.log或/var/log/messages中查看
停止monitor最简单的方法就是删除它,但有时,只想临时禁用
pcs resource update将enabled="false",要恢复即enable="true"
当使用pcs resource update更新资源操作时,没有强调的选项都将置为默认值
见6.8
pcs resource update RSC1 op monitor enabled=false
比如,你曾配置过超时为600s的监控操作,为了 保持这个配置你就得在更新其他值的时候 把这个超时也指定出来
pcs resource update RSC1 op monitor timeout=600 enabled=true
将资源设置为非受管,表示资源仍然在配置中,但pcmk不管理该资源
pcs resource unmanage resource1 [resource2] ...
pcs resource manage resource1 [reosurce2] ...
创建克隆资源,以便在多个节点上激活该资源
可以克隆资源代理支持的任何资源,克隆由一个资源或一个资源组组成
只有同时可在多个节点上活跃的资源才适用克隆
创建克隆资源
pcs resource create resource_id standard:provider:type|type [resource options] clone [meta clone_options] # 克隆的名称为resource_id-clone
不能在单条命令中创建资源组以及资源组的克隆,但可以这样
pcs resource clone resource_id | group_name [clone_options] ... # resource_id-clone or group_name-clone
当你创建依赖另一个克隆资源A的克隆资源B时,应该设置
interleave=true,确保当依赖的克隆在同一节点上停止或启动时,依赖克隆的副本可以停止或启动。如果不设置此项,则如果克隆资源B依赖于克隆资源A,且某个节点离开集群,当该节点返回集群且资源A在该节点上启动时,则所有节点上资源B的所有副本将重新启动。 这是因为当依赖的克隆资源没有设置interleave选项时,该资源的所有实例都依赖于它所依赖的资源的任何运行实例。
删除资源或资源组的克隆,不会删除资源或资源组本身:
pcs resource unclone resource_id | group_name
如
pcs resource unclone ping # 之前创建的ping
上边clone_options包括哪些?
| 字段 | 描述 |
|---|---|
| priority, target-role, ismanaged | 继承自resource,见6.3 |
| clone-max | 要启动的资源副本数量。默认为集群中的节点数量 |
| clone-node-max | 在一个节点上可以启动资源的副本数 ; 默认值为 1 |
| notify | 当停止或启动克隆的副本时,预先并在操作成功时告知所有其他副本。false or true.默认false |
| globally-unique | 每个副本是否执行不同的功能,true or false,若false,则资源在任何位置行为相同,因此每台机器只能有一个克隆副本;若true,同一机器上的副本不同。若clone-node-max大于1,则默认true,否则默认false |
| ordered | 是否以顺序的方式启动副本,而不是并行,默认false |
| interleave | 更改顺序限制的行为,不用等待所有节点上的A依赖启动或停止完成才启停B,默认false |
| clone-min | If a value is specified, any clones which are ordered after this clone will not be able to start until the specified number of instances of the original clone are running, even if the interleave option is set to true. |
克隆限制
当clone-max小于节点总数时,可以使用位置约束,与常规的位置约束不同,需指定clone-id
pcs constraint location SRC-clone prefers node1
…
多状态是一种特殊的克隆资源
Master 和 Slave 两种
当已经有一个实例启动了,再启动的实例只能是Slave
创建
pcs resource create resource_id ::type [resource opts] master # 名称为resource_id-master
从已有资源创建
pcs resource master mster/slve_name resource_id|group_name [master_options]
多状态资源属性 master_options:
| 项 | 描述 |
|---|---|
| id | 多状态资源的名称 |
| priority, target-role, is-managed | 见6.3 |
| clone-max, clone-node-max, notify, globally-unique, ordered, interleave | 见clone-options |
| master-max | 可以提升为master状态的副本数,默认1 |
| master-node-max | 单个节点上,可以提升为master状态的最多副本数,默认1 |
要仅为master资源添加监控操作,可以在资源中添加额外的monitor,但注意,资源中的每个monitor操作都必须具有不同的interval
例如:
pcs resource op add RSC interval=11s role=Master
在大多数情况下,多状态资源在每个活跃的集群节点上都有一个副本
也可以指定集群使用资源位置约束来优先分配哪些节点。这些限制与常规资源的写法不同。
参考7.1 位置限制
使用colocation来指定资源是master还是slave
pcs constraint colocation add [master|slave] source_resource with [master|slave] target_resource [score] [options]
参考7.3 资源共存
顺序也可以限制,参考7.2
pcs constraint order [action] resource_id then [aciton] resource_id [options]
…
libvirt管理的虚拟机可使用VirtualDomain这个type来创建为资源
还应该考虑如下事项:
自启动若还想管理虚拟机内部的服务,可以将其配置为guest node,详见9.4
…
pacemaker_remote可以让未运行corosync的节点集成到集群,像真实集群节点一样管理集群资源
pacemaker_remote 提供的功能包括以下:
描述pacemaker_remote
pacemaker_remote服务的节点,不需要corosync。使用ocf:pacemaker:remote代理将远程节点作为资源加入到集群中pacemaker_remote服务的虚拟机节点,虚拟机作为集群资源,并集成到集群中作为远程节点libvirt-lxclinux容器驱动程序定义的Linux容器运行了pacemaker_remote的pcmk集群有以下特征:
pacemaker_remote服务pacemaker和corosync连接到远程节点的pacemaker_remote服务pacemaker_remote服务集群节点与其管理的远程节点和客户节点区别在于运行了cluster stack - (corosync),意味着远程节点和客户节点有以下限制:
集群节点和remote节点必须共享相同的私钥,默认情况下,私钥放在集群节点和远程节点的/etc/pacemaker/authkey中
RHEL7.4开始,
pcs cluster node add-guest 会设置客户机authkey
pcs cluster node add-remote 设置远程节点的authkey
…
编辑 /etc/sysconfig/pacemaker 修改变量 PCMK_remote_port=3121
概述使用PCMK启动虚拟机,并将虚拟机作为集群资源
VirtualDomain资源authkey
…
…
pcs resource bundle create bundle_id container docker [container_options] [network network_options] [port-map port_options]... [storage-map storage_options]... [meta meta_options] [--disabled] [--wait[=n]]
需要每个运行Bundle的节点都能正常使用docker,已有docker image
Docker Parameters
promoted-max if that is positive, otherwise 1 – 一个正整数,指定要启动的容器数docker run,作为容器网络配置docker run的其他命令行选项Bundle Network Parameters
** Bundle资源 端口映射参数**
** Bundle资源 存储映射参数**
source-dir不存在,期望容器或资源代理会创建
若bundle包含PCMK资源,PCMK将自动映射 source-dir=/etc/pacemaker/authkey target-dir=/etc/pacemaker/authkey source-dir-root=/var/log/pacemaker/bundles target-dir=/var/log 到容器,所以没必要配置这些到 storage
在集群的任何节点上,PCMK_auth_location环境变量不得设置为/etc/pacemaker/authkey以外的任何值
若Bundle包含有PCMK资源,则容器镜像必须包含pacemaker_remote
包含资源的捆绑包中的容器必须具有可访问的网络环境,以便集群节点上的 Pacemaker 可以与容器内的 Pacemaker 远程联系
…
非受管或集群处于维护模式时,重启pacemaker可能会导致bundle失败control-port,bundle才能运行在远程节点上创建一个包含有httpd资源(ocf:heartbeat:apach)的bundle —— httpd-bundle
此流程需要以下先决条件:
pcmktest:httpPacemaker Remote daemon/var/local/containers/httpd-bundle-0, /var/local/containers/httpd-bundle-1, and /var/local/containers/httpd-bundle-2,其中包含 web 服务器 root 的 index.html 文件。在生产中,更有可能使用一个共享的文档根目录,但示例中,此配置允许您使每个主机上的 index.html 文件与众不同,以便您可以连接到 Web 服务器并验证是否提供了 index.html 文件。此流程为bundle配置参数:
ocf:heartbeat:IPaddr2资源,每个容器一个,IP从192.168.122.131开始http-port,容器:80…
RHEL HA add-on 集群使用votequorum和fencing来避免脑裂
很多votes分配给集群中的每个系统,只有当得票超过半数,集群操作才被允许。
该服务必须载入到所有集群节点,若只是部分集群节点,则结果无法预计
pcs cluster setup时的选项:
auto_tie_breaker_node中配置的nodeid(或者如果没有设置最低的nodeid)保持联系的节点集,将保持quorum。其他节点将inquorate。此选项主要用于节点数量为偶数的集群,因为它允许集群以偶数分割继续工作。quorum。wait_for_all选项主要用于双节点集群和使用仲裁设备lms(最后一人站)算法的偶数节点集群。 wait_for_all选项在双节点集群、不使用仲裁设备且禁用auto_tie_breaker时自动启用。 您可以通过显式地将wait_for_all设置为0来覆盖它。expected_votes和quorum。在启用该选项时,必须启用wait_for_all。 与quorum devices不兼容。expected_votes和quorum所需的等待时间。查看集群仲裁配置
pcs quota [config]
查看集群仲裁状态
pcs quota status
直接修改预期vote,让集群在没有仲裁的情况下继续操作
pcs quorum expected-votes votes
pcs quorum update [auto_tie_breaker=[0|1]] [last_man_standing=[0|1]] [last_man_standing_window=[time-in-ms] [wait_for_all=[0|1]]
在您知道集群不仲裁但您希望集群进行资源管理的情况下,您可以使用以下命令来防止集群在建立仲裁时等待所有节点。
使用这个命令时需要特别小心。在运行此命令前,请确定关闭没有在集群中的节点,并确保无法访问共享资源。
pcs cluster quorum unblock
建议在具有偶数节点的集群中使用仲裁设备
…
rules可以让集群配置更动态
规则的一种用法是分配机器到不同的组(使用node attribute),然后在创建位置约束时使用该属性
每条规则包含多个表达式、日期表达式甚至其他规则
表达式的结果根据规则的 boolean-op 字段合并,以确定规则最终评估为 true 或 false。接下来的操作要看规则使用的上下文而定。
规则的属性:
| 字段 | 描述 |
|---|---|
| role | 只有资源位于该角色时才会应用该规则。允许的值有:started, slave and master |
| score | 规则评估为true时要应用的分数,仅限于作为位置约束的一部分时使用 |
| score-attribute | 如果规则评估为 true,则要查找节点属性并将其用作分数,仅限于作为位置约束一部分的规则使用 |
| boolean-op | 如何组合多个表达式对象的结果。允许的值: and , or.默认值为 and. |
节点属性表达式用于根据节点定义的属性控制资源
| 字段 | 描述 |
|---|---|
| attribute | 要测试的节点属性 |
| type | 值应该如何进行测试,string, integer or version,默认string |
| operation | 执行的对比,允许的值, lt gt lte gte eq ne defined not_defined |
| value | 用于比较的值(必填) |
除了管理员为集群添加的属性,集群还有內建属性
| 字段 | 描述 |
|---|---|
| #uname | 节点名 |
| #id | 节点ID |
| #kind | 节点类型:cluster, remote or container. |
| #is_dc | 是否是DC |
| #cluster_name | 集群属性cluster-name的值 |
| #site_name | 节点属性site-name的值,若未设置则为 #cluster_name |
| #role | 此节点上相关的多状态资源的角色。仅在多状态资源的位置约束的规则内有效。 |
…
…
要使用pcs配置规则,见7.1.3 使用规则确定资源位置
若删除的规则是constraint中的最后一条规则,则constraint被删除
pcs cosntraint rule remove rule_id
集群属性:
| 选项 | 默认值 | 描述 |
|---|---|---|
| batch-limit | 0 | 集群可以并行执行多少资源动作,与网络负载和速度有关 |
| migration-limit | -1(umlimited) | 在一个节点上并行执行迁移的数量 |
| no-quorum-policy | stop | 当集群没有仲裁时做啥,允许:ignore(继续所有资源管理)、freeze、stop、suicide |
| symmetric-cluster | true | 资源是否默认可以在任何节点上运行 |
| stonith-enabled | true | 是否开启stonith,失败的节点或有资源却无法停止的节点应该被隔离 |
| stonith-action | reboot | 发送到STONITH设备的操作,允许的值:reboot、off,poweroff也允许,但只用于旧设备 |
| cluster-delay | 60s | 网络上的往返延迟(不包括动作执行时间)“正确”的值取决于网络和集群节点的速度和负载 |
| stop-orphan-resources | true | 已删除的资源是否应被停止 |
| stop-orphan-actions | true | 指示是否应取消已删除的操作 |
| start-failure-is-fatal | true | 指示在特定节点上启动资源的失败是否会阻止该节点上的进一步启动尝试。 |
| pe-error-series-max | -1 (all) | |
| pe-warn-series-max | -1(all) | |
| pe-input-seires-max | -1(all) | |
| cluster-infrastructure | 当前运行的 Pacemaker 的消息堆栈。用于信息和诊断目的,用户不能配置。 | |
| DC-version | 集群的 Designated Controller(DC)上的 Pacemaker 版本。用于诊断目的,用户不能配置。 | |
| last-lrm-refresh | 最后一次刷新本地资源管理器,自 epoca 起以秒为单位。用于诊断目的,用户不能配置。 | |
| cluster-recheck-interval | 15min | 对选项、资源参数和约束进行基于时间的更改的轮询间隔。 允许的值:0禁用轮询,正值是以秒为单位的间隔(除非指定了其他SI单位,例如5min)。 注意,这个值是检查之间的最大时间间隔; 如果集群事件发生的时间早于该值指定的时间,检查将更快完成。 |
| maintenance-mode | false | Maintenance Mode 让集群进入"手动关闭"模式,而不要启动或停止任何服务,直到有其他指示为止。当维护模式完成后,集群会对任何服务的当前状态进行完整性检查,然后停止或启动任何需要它的状态。 |
| shutdown-escalation | 20min | |
| stonith-timeout | 60s | 等待 STONITH 操作完成的时间。 |
| stop-all-resources | false | 集群是否应该停止所有资源 |
| enable-acl | false | 指明群集是否可以使用访问控制列表,如 pcs acl 命令所设置。 |
| placement-strategy | default | |
| fence-reaction | stop |
设置集群属性的值
pcs property set property=value
删除集群属性
pcs property unset property
恢复默认值
pcs property set property= # 对咯,留空
pcs property list # 显示所有
pcs property list --all # 显示所有,包括未明确设置的默认值
pcs property show
pcs property list --defaults # 显示所有默认的
pacemaker集群是一个事件驱动的系统,其中事件可能是资源或节点故障、配置更改、资源启停
可以按如下两种方式配置集群告警:
ocf:pacemaker:ClusterMon资源可以监控集群状态,并触发每个集群事件的警报,此资源在后台以固定时间间隔运行crm_mon命令,详见13.2先copy告警脚本
install --mode=0755 /usr/share/pacemaker/alerts/alert_file.sh.sample /var/lib/pacemaker/alert_file.sh
创建文件,创建告警代理
touch /var/log/pcmk_alert_file.log
chown hacluster:haclient /var/log/pcmk_alert_file.log
chmod 600 /var/log/pcmk_alert_file.log
pcs alert create id=alert_file description="Log events to a file" path=/var/lib/pacemaker/alert_file.sh
pcs alert recipient add alert_file id=my-alert_logfile value=/var/log/pcmk_alert_file.log
创建snmp告警代理
# install --mode=0755 /usr/share/pacemaker/alerts/alert_snmp.sh.sample /var/lib/pacemaker/alert_snmp.sh
# pcs alert create id=snmp_alert path=/var/lib/pacemaker/alert_snmp.sh meta timestamp-format="%Y-%m-%d,%H:%M:%S.%01N"
# pcs alert recipient add snmp_alert value=192.168.1.2
# pcs alert
Alerts:
Alert: snmp_alert (path=/var/lib/pacemaker/alert_snmp.sh)
Meta options: timestamp-format=%Y-%m-%d,%H:%M:%S.%01N.
Recipients:
Recipient: snmp_alert-recipient (value=192.168.1.2)
创建电子邮件告警
# install --mode=0755 /usr/share/pacemaker/alerts/alert_smtp.sh.sample /var/lib/pacemaker/alert_smtp.sh
# pcs alert create id=smtp_alert path=/var/lib/pacemaker/alert_smtp.sh options email_sender=donotreply@example.com
# pcs alert recipient add smtp_alert value=admin@example.com
# pcs alert
Alerts:
Alert: smtp_alert (path=/var/lib/pacemaker/alert_smtp.sh)
Options: email_sender=donotreply@example.com
Recipients:
Recipient: smtp_alert-recipient (value=admin@example.com)
pcs alert create path=path [id=alert-id] [description=description] [options [option=value]...] [meta [meta-option=value]...]
pcs alert [config|show] # 显示
pcs alert update alert-id [path=path] [description=description] [options [option=value]...] [meta [meta-option=value]...]
pcs alert remove alert-id
通常,警报是针对接收方的。因此,每个警报可能被额外配置为一个或多个接收方。集群将为每个接收者单独调用代理。
pcs alert recipient add alert-id ... # 添加
pcs alert recipient update recipient-id ... # 更新
pcs alert recipient remove recipient-id # 移除
与资源代理一样,可以对警报代理配置 meta 选项来影响 Pacemaker 调用它们的方式
| Meta-Attribute | Default | Description |
|---|---|---|
| timestamp-format | %H:%M:%S.%06N | |
| timeout | 30s | 如果警报代理没有在这段时间内完成,它将被终止 |
# pcs alert create id=my-alert path=/path/to/myscript.sh meta timeout=15s
# pcs alert recipient add my-alert value=someuser@example.com id=my-alert-recipient1 meta timestamp-format="%D %H:%M"
# pcs alert recipient add my-alert value=otheruser@example.com id=my-alert-recipient2 meta timestamp-format=%c
…
Pacemaker 警报有三种类型:节点警报、保护警报和资源警报
传递给警报代理的环境变量
| 环境变量 | 描述 |
|---|---|
| CRM_alert_kind | 警报类型(node,fencing, or resource) |
| CRM_alert_version | Pacemaker 发送警报的版本 |
| CRM_alert_recipient | 配置的接受者 |
| CRM_alert_node_sequence | |
| CRM_alert_timestamp | |
| CRM_alert_node | 受影响的节点 |
| CRM_alert_desc | 有关事件的详情 |
| CRM_alrt_nodeid | 状态更改的节点ID |
| CRM_alert_task | 请求的隔离或资源操作 |
| CRM_alert_rc | 保护或资源操作的数字返回代码(仅由隔离和资源警告提供) |
| CRM_alert_rsc | 受影响资源的名称(仅限资源警报) |
| CRM_alert_interval | 资源操作的时间间隔(仅限资源警报) |
| CRM_alert_target_rc | 操作的语气数字返回代码(仅限资源警报) |
| CRM_alert_status | Pacemaker 用来表示操作结果的数字代码(仅用于资源警报) |
在编写警报代理时,您必须考虑以下问题
警报接口设计为与 ocf:pacemaker:ClusterMon 资源使用 的外部脚本界面向后兼容。为了保持这种兼容性,传递给警报代理的环境变量会预先带有 CRM_notify_ 和 CRM_alert_。兼容性问题之一是 ClusterMon 资源以 root 用户身份运行外部脚本,而警报代理则以 hacluster 用户身份运行。有关配置由 ClusterMon 触发的脚本的详情请参考 第 13.2 节 “使用监控资源的事件通知”。