[root@node1 corosync]# corosync-keygen
Corosync Cluster Engine Authentication key generator.
Gathering 1024 bits for key from /dev/random.
Press keys on your keyboard to generate entropy.
Press keys on your keyboard to generate entropy (bits = 192).
2.查看corosync引擎是否正常启动
[root@node1 ~]#grep -e "Corosync Cluster Engine" -e "configuration file"/var/log/cluster/corosync.log
Feb 26 17:33:28corosync [MAIN ] Corosync Cluster Engine ('1.4.1'): started and ready to provideservice.
Feb 26 17:33:28corosync [MAIN ] Successfully read main configuration file'/etc/corosync/corosync.conf'.
3.查看初始化成员节点通知是否正常发出
[root@node1 ~]#grep TOTEM /var/log/cluster/corosync.log
Feb 26 17:33:28corosync [TOTEM ] Initializing transport (UDP/IP Multicast).
Feb 26 17:33:28corosync [TOTEM ] Initializing transmit/receive security: libtomcryptSOBER128/SHA1HMAC (mode 0).
Feb 26 17:33:28corosync [TOTEM ] The network interface [172.16.120.176] is now up.
Feb 26 17:33:28corosync [TOTEM ] Process pause detected for 616 ms, flushing membershipmessages.
Feb 26 17:33:28corosync [TOTEM ] A processor joined or left the membership and a new membershipwas formed.
Feb 26 17:33:46corosync [TOTEM ] A processor joined or left the membership and a newmembership was formed.
4.检查启动过程中是否有错误产生
[root@node1 ~]#grep ERROR: /var/log/cluster/corosync.log
Feb 26 17:33:28corosync [pcmk ] ERROR: process_ais_conf: You have configured a cluster using thePacemaker plugin for Corosync. The plugin is not supported in this environment and willbe removed very soon.
Feb 26 17:33:28corosync [pcmk ] ERROR: process_ais_conf: Please see Chapter 8 of 'Clustersfrom Scratch' (http://www.clusterlabs.org/doc) for details on using Pacemakerwith CMAN
7.查看状态
[root@node1~]# crm_mon
Last updated:Wed Feb 26 17:41:58 2014
Last change:Wed Feb 26 17:33:51 2014 via crmd on node1.test.com
Stack: classicopenais (with plugin)
CurrentDC: node1.test.com- partition with quorum
Version:1.1.10-14.el6_5.2-368c726
2 Nodesconfigured, 2 expected votes
0 Resourcesconfigured
Online: [node1.test.com node2.test.com ]
5.再次测试
启动刚才停止的node1的服务,再次查看状态。
crm(live)#status
Last updated:Thu Feb 27 10:48:24 2014
Last change:Thu Feb 27 10:48:08 2014 via crm_attribute on node1.test.com
Stack: classicopenais (with plugin)
Current DC:node1.test.com - partition with quorum
Version:1.1.10-14.el6_5.2-368c726
2 Nodes configured, 2 expected votes
2 Resourcesconfigured
Online: [node1.test.com node2.test.com ]
ResourceGroup: Webservice
Webip (ocf::heartbeat:IPaddr): Started node2.test.com
httpd (lsb:httpd): Started node2.test.com
crm(live)#
#查看状态可知,node1和node2正常运行,且资源运行在node2上。
[root@node1~]# ssh node2 "service corosync stop" #停止node2上的corosync
SignalingCorosync Cluster Engine (corosync) to terminate: [ OK ]
Waiting forcorosync services to unload:..[ OK ]
[root@node1~]# crm status #再次查看状态验证
Last updated:Thu Feb 27 10:51:10 2014
Last change:Thu Feb 27 10:48:08 2014 via crm_attribute on node1.test.com
Stack: classicopenais (with plugin)
Current DC:node1.test.com - partition WITHOUT quorum
Version:1.1.10-14.el6_5.2-368c726
2 Nodesconfigured, 2 expected votes
2 Resourcesconfigured
Online: [node1.test.com ]
OFFLINE: [node2.test.com ]
ResourceGroup: Webservice
Webip (ocf::heartbeat:IPaddr): Startednode1.test.com
httpd (lsb:httpd): Started node1.test.com
crm(live)# status #查看状态,发现组Webip已经被删除,而Webip和httpd被分配到不同的节点上
Last updated: Thu Feb 27 11:26:59 2014
Last change: Thu Feb 27 11:26:53 2014 via cibadmin on node1.test.com
Stack: classic openais (with plugin)
Current DC: node1.test.com - partition with quorum
Version: 1.1.10-14.el6_5.2-368c726
2 Nodes configured, 2 expected votes
2 Resources configured
Online: [ node1.test.com node2.test.com ]
Webip (ocf::heartbeat:IPaddr): Started node1.test.com
httpd (lsb:httpd): Started node2.test.com
3.增加共享存储
此时,为实现共享存储,添加了一台NFSserver, NFS共享 172.16.120.88:/web
并在/web目录下建了一个index.html 其内容为 from nfs server
4.添加nfs服务至集群。
crm(live)configure# primitive webstore ocf:heartbeat:Filesystem params device="172.16.120.88:/web" directory="/var/www/html" fstype="nfs"
crm(live)configure# verify
WARNING: Webstore: default timeout 20s for start is smaller than theadvised 60
WARNING: Webstore: default timeout 20s for stop is smaller than theadvised 60
crm(live)configure# commit
5.定义资源约束:
crm(live)configure# colocation httpd_with_webstore INFINITY: httpd webstore
crm(live)configure# colocation httpd_with_webip INFINITY: httpd webip
crm(live)configure# verify
WARNING: Webstore: default timeout 20s for start is smaller than theadvised 60
WARNING: Webstore: default timeout 20s for stop is smaller than the advised60
crm(live)configure# commit
crm(live)# status
Last updated: Thu Feb 27 12:39:14 2014
Last change: Thu Feb 27 12:38:09 2014 via cibadmin on node1.test.com
Stack: classic openais (with plugin)
Current DC: node1.test.com - partition with quorum
Version: 1.1.10-14.el6_5.2-368c726
2 Nodes configured, 2 expected votes
3 Resources configured
Online: [ node1.test.com node2.test.com ]
Webip (ocf::heartbeat:IPaddr): Started node2.test.com
httpd (lsb:httpd): Started node2.test.com
Webstore (ocf::heartbeat:Filesystem): Started node2.test.com
# 查看资源状况,可以看出Webip,httpd,Webstore 运行在同一节点
7.测试
测试显示,网页的内容来自NFS server
8.故障模拟
在node2上模拟故障,手动执行standby,可以看出三个资源被自动转移至node1,实验成功
crm(live)node# standby
crm(live)node# cd
crm(live)# status
Last updated: Thu Feb 27 12:42:46 2014
Last change: Thu Feb 27 12:42:40 2014 via crm_attribute on node2.test.com
Stack: classic openais (with plugin)
Current DC: node1.test.com - partition with quorum
Version: 1.1.10-14.el6_5.2-368c726
2 Nodes configured, 2 expected votes
3 Resources configured
Node node2.test.com: standby
Online: [ node1.test.com ]
Webip (ocf::heartbeat:IPaddr): Started node1.test.com
httpd (lsb:httpd): Started node1.test.com
Webstore (ocf::heartbeat:Filesystem): Started node1.test.com