corosync默认启用了stonith,而当前集群并没有相应的stonith设备,因此此默认配置目前尚不可用,这可以通过如下命令验正:
# crm_verify -L
crm_verify[5202]: 2011/06/14_19:10:38 ERROR: unpack_resources: Resource start-up disabled since no STONITH resources have been defined
crm_verify[5202]: 2011/06/14_19:10:38 ERROR: unpack_resources: Either configure some or disable STONITH with the stonith-enabled option
crm_verify[5202]: 2011/06/14_19:10:38 ERROR: unpack_resources: NOTE: Clusters with shared data need STONITH to ensure data integrity
Errors found during check: config not valid
-V may provide more details
我们里可以通过如下命令先禁用stonith:
# crm configure property stonith-enabled=false
使用如下命令查看当前的配置信息:
# crm configure show
node node1.linuxidc.com
node node2.linuxidc.com
property $id="cib-bootstrap-options" \
dc-version="1.0.11-1554a83db0d3c3e546cfd3aaff6af1184f79ee87" \
cluster-infrastructure="openais" \
expected-quorum-votes="2" \
stonith-enabled="false
从中可以看出stonith已经被禁用。
上面的crm,crm_verify命令是1.0后的版本的pacemaker提供的基于命令行的集群管理工具;可以在集群中的任何一个节点上执行。
7、为集群添加集群资源
corosync支持heartbeat,LSB和ocf等类型的资源代理,目前较为常用的类型为LSB和OCF两类,stonith类专为配置stonith设备而用;
可以通过如下命令查看当前集群系统所支持的类型:
# crm ra classes
heartbeat
lsb
ocf / heartbeat pacemaker
stonith
如果想要查看某种类别下的所用资源代理的列表,可以使用类似如下命令实现:
# crm ra list lsb
# crm ra list ocf heartbeat
# crm ra list ocf pacemaker
# crm ra list stonith
# crm ra info [class:[provider:]]resource_agent
例如:
# crm ra info ocf:heartbeat:IPaddr
8、接下来要创建的web集群创建一个IP地址资源,以在通过集群提供web服务时使用;这可以通过如下方式实现:
语法:
primitive [:[
:]]
[params attr_list]
[operations id_spec]
[op op_type [=...] ...]
op_type :: start | stop | monitor
例子:
primitive apcfence stonith:apcsmart \
params ttydev=/dev/ttyS0 hostlist="node1 node2" \
op start timeout=60s \
op monitor interval=30m timeout=60s
应用:
# crm configure primitive WebIP ocf:heartbeat:IPaddr params ip=172.16.100.1
通过如下的命令执行结果可以看出此资源已经在node1.linuxidc.com上启动:
# crm status
============
Last updated: Tue Jun 14 19:31:05 2011
Stack: openais
Current DC: node1.linuxidc.com - partition with quorum
Version: 1.0.11-1554a83db0d3c3e546cfd3aaff6af1184f79ee87
2 Nodes configured, 2 expected votes
1 Resources configured.
============
Online: [ node1.linuxidc.com node2.linuxidc.com ]
WebIP (ocf::heartbeat:IPaddr): Started node1.linuxidc.com
当然,也可以在node1上执行ifconfig命令看到此地址已经在eth0的别名上生效:
# ifconfig
eth0:0 Link encap:Ethernet HWaddr 00:0C:29:AA:DD:CF
inet addr:172.16.100.1 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:67 Base address:0x2000
而后我们到node2上通过如下命令停止node1上的corosync服务:
# ssh node1 -- /etc/init.d/corosync stop
查看集群工作状态:
# crm status
============
Last updated: Tue Jun 14 19:37:23 2011
Stack: openais
Current DC: node2.linuxidc.com - partition WITHOUT quorum
Version: 1.0.11-1554a83db0d3c3e546cfd3aaff6af1184f79ee87
2 Nodes configured, 2 expected votes
1 Resources configured.
============
Online: [ node2.linuxidc.com ]
OFFLINE: [ node1.linuxidc.com ]
上面的信息显示node1.linuxidc.com已经离线,但资源WebIP却没能在node2.linuxidc.com上启动。这是因为此时的集群状态为"WITHOUT quorum",即已经失去了quorum,此时集群服务本身已经不满足正常运行的条件,这对于只有两节点的集群来讲是不合理的。因此,我们可以通过如下的命令来修改忽略quorum不能满足的集群状态检查:
# crm configure property no-quorum-policy=ignore
片刻之后,集群就会在目前仍在运行中的节点node2上启动此资源了,如下所示:
# crm status
============
Last updated: Tue Jun 14 19:43:42 2011
Stack: openais
Current DC: node2.linuxidc.com - partition WITHOUT quorum
Version: 1.0.11-1554a83db0d3c3e546cfd3aaff6af1184f79ee87
2 Nodes configured, 2 expected votes
1 Resources configured.
============
Online: [ node2.linuxidc.com ]
OFFLINE: [ node1.linuxidc.com ]
WebIP (ocf::heartbeat:IPaddr): Started node2.linuxidc.com
好了,验正完成后,我们正常启动node1.linuxidc.com:
# ssh node1 -- /etc/init.d/corosync start
查看状态:
# crm status
============
Last updated: Mon Apr 16 02:52:14 2012
Stack: openais
Current DC: node2.linuxidc.com - partition with quorum
Version: 1.0.11-1554a83db0d3c3e546cfd3aaff6af1184f79ee87
2 Nodes configured, 2 expected votes
2 Resources configured.
============
Online: [ node1.linuxidc.com node2.linuxidc.com ]
WebIP (ocf::heartbeat:IPaddr): Started node1.linuxidc.com
正常启动node1.linuxidc.com后,集群资源WebIP很可能会重新从node2.linuxidc.com转移回node1.linuxidc.com。资源的这种在节点间每一次的来回流动都会造成那段时间内其无法正常被访问,所以,我们有时候需要在资源因为节点故障转移到其它节点后,即便原来的节点恢复正常也禁止资源再次流转回来。这可以通过定义资源的黏性(stickiness)来实现。在创建资源时或在创建资源后,都可以指定指定资源黏性。
