实现环境:
 两台虚拟机
 192.168.238.128 node1.test.com
 192.168.238.129 node2.test.com
实验准备:两台主机可以互相解析主机名,把对方主机名写入hosts文件,设置主机名和uname -n显示的一样,我这里在
第三台机器192.168.238.130上面设置了nfs输出了一个目录 /web *(rw,sync,no_root_squash<必须的参数>)
vi /etc/hosts
192.168.238.128 node1.test.com node1
192.168.238.129 node2.test.com node2
hostname node1.test.com
vi /etc/sysconfig/network 确保主机名和uname -n显示的一样
HOSTNAME=node1.test.com
ssh-keygen -t rsa  配置两个主机不用密码可以互相ssh
ssh-copy-id -i .ssh/id_rsa.pub node2
scp -p /etc/hosts node2:/etc


下载软件包
cluster-glue-1.0.6-1.6.el5.i386.rpm
cluster-glue-libs-1.0.6-1.6.el5.i386.rpm
corosync-1.2.7-1.1.el5.i386.rpm
corosynclib-1.2.7-1.1.el5.i386.rpm
heartbeat-3.0.3-2.3.el5.i386.rpm
heartbeat-libs-3.0.3-2.3.el5.i386.rpm
libesmtp-1.0.4-5.el5.i386.rpm
openais-1.1.3-1.6.el5.i386.rpm
openaislib-1.1.3-1.6.el5.i386.rpm
pacemaker-1.0.11-1.2.el5.i386.rpm
pacemaker-libs-1.0.11-1.2.el5.i386.rpm
perl-TimeDate-1.16-5.el5.noarch.rpm
resource-agents-1.0.4-1.1.el5.i386.rpm

yum localinstall --nogpgcheck * -y
cd /etc/corosync/
mv corosync.conf.example corosync.conf
vi corosync.conf

在totem中设置
secauth: on 打开认证
threads: 2 为心跳验证打开2个线程,一般设置和cpu个数一样
bindnetaddr: 192.168.238.129 设置绑定的网卡
在logging中设置
to_syslog: no 日志已经保存在logfile中了,这里就不需要再输出到syslog了
最后添加以下两项:
service {
        ver : 0
        name: pacemaker
}

aisexec {
        user : root
        group: root
}
mkdir /var/log/cluster
corosync-keygen 生成心跳信息认证密钥 从/dev/random 从读取随机数,有时候因为没有随机数读取不成功
scp -p authkey corosync.conf node2然后再node2上面把corosync.conf里面的IP改一下
ssh node2 'mkdir -v /var/log/cluster'
然后启动两个节点,启动之前最好把两个节点的时间同步一下
service corosync start

查看日志进行验证
grep -e "Corosync Cluster Engine" -e "configuration file" /var/log/messages 制定两个查找条件
grep TOTEM /var/log/messages
grep ERROR: /var/log/messages |grep -V unpack_resources
grep pcmk_startup /var/log/messages

crm status查看集群状态信息,没有配置所以没有资源信息

进行资源的配置:
crm 可以进入crm的命令行交互模式,使用help可以查看帮助信息
crm configure
crm(live) configure# property stonith-enabled=false
//默认没有stonith设备不允许集群运行,这里没有设备,把stonith全局选项关掉
crm(live) configure# property no-quorum-policy=ignore
//这里把quorum也忽略了,我们是两个节点不需要quorum
crm(live) configure# rse_defaults resource-stickiness=100 //配置资源黏性为100
crm(live) configure# primitive WebIP ocf:heartbeat:IPaddr params ip=192.168.238.100 //设置一个虚拟IP的资源
crm(live) configure# primitive WebServer lsb:httpd
//如果在/etc/init.d/下找不到httpd脚本这里会报错,不要手动启动http,也不要设置http开机自启动
crm(live) configure# primitive Mount_nfs ocf:heartbeat:Filesystem params device=192.168.238.130:/web \
directory=/var/www/html fstype=nfs
我在192.168.238.100上面设置nfs输出了一个目录/web,在nfs输出选项里面要加上no_root_squash
crm(live) configure# group WEB WebIP WebServer Mount_nfs定义一个组,这些资源只能同时在一个节点上面运行
crm(live) configure# order Mount_after_WebServer mandatory: WebServer:start Mount_nfs
//定义资源的启动顺序,依次为IP,HTTP,挂载操作
crm(live) configure# order WebServer_after_WebIP mandatory: WebIP:start WebServer
crm(live) configure# commit

crm configure show查看cib文件的配置
crm-configure-edit可以进行cib文件的编辑,编辑之后commit递交
crm status查看集群状态信息,资源在哪个节点上面启动了

停止某个或者某组资源crm-resource stop 资源名/资源组名