Pacemaker是一个集群资源管理器。它利用你喜欢的集群基础构件(corosync)提供的消息和成员管理能力来探测并从节点或资源级别的故障中恢复,以实现群集服务(亦称资源)的最大可用性。

各服务器IP分配

192.168.2.36 (corosync pacemaker master)

192.168.2.46   (corosync pacemaker slave)

192.168.2.38    192.168.2.39   (realserver)  192.168.2.111 (浮动IP)

软件包的安装

crmsh-1.2.6-0.rc2.2.1.x86_64.rpm pssh-2.3.1-2.1.x86_64.rpm
然后yum localinstall * -y
做一下远程链接无需验证:ssh-keygen 全部摁回车
然后再用这个命令:ssh-copy-id desktop36.example.com 之后就不许要验证密码了 把.ssh scp到另一台虚拟机上desktop46.example.com
#cd /etc/corosync/
#cp corosync.conf.example corosync.conf
然后编辑 #vim corosync.conf
bindnetaddr: 192.168.2.0(填本机ip网段)
mcastaddr: 226.94.1.97(这个随便改)
mcastport: 3427(这个也是随意)
service {
        name: pacemaker
        ver:  0

}
把这个文件scp到desktop46 保持一致
启动 /etc/init.d/corosync start(两边都启动)
用crm node show 看下两边节点是不是都起来了
然后再用crm_verify -LV验证下有没有错误,它会出现这个错误:
crm_verify[2195]: 2009/08/27_16:57:12
resources have been defined
crm_verify[2195]: 2009/08/27_16:57:12
the stonith-enabled option
crm_verify[2195]: 2009/08/27_16:57:12
ensure data integrity
Errors found during check: config not
#
ERROR: unpack_resources: Resource start-up disabled since no STONITH
ERROR: unpack_resources: Either configure some or disable STONITH with
ERROR: unpack_resources: NOTE: Clusters with shared data need STONITH to
valid -V may provide more details
目前,我们禁用这个特性,然后在 配置STONISH 章节来配置它。这里要指出,使用STONITH是非常有必
要的。关闭这个特性就是告诉集群:假装故障的节点已经安全的关机了。一些供应商甚至不允许这个特
性被关闭。
我们将 stonith-enabled设置为 false 来关闭STONITH
# crm configure property stonith-enabled=false
# crm_verify -L
设置完这个选项以后,校验配置文件就正常了。
添加一个资源
首先要做的是配置一个IP地址,不管集群服务在哪运行,我们要一个固定的地址来提供服务。在这里我
选择192.168.2.111作为浮动IP,给它取一个好记的名字 VIP 并且告诉集群 每30秒检查它一

wKioL1PnCCqggSuiAADYYXblhuc296.jpg用crm_mon查看检查下IP是不是已经添加上
wKioL1PnCJ6TgfnFAAKfCOVC6MY218.jpg

做节点失效备援:
关掉一个节点的corosync后,添加的那个IP资源不会在剩下的那个节点运行!
法定人数和双节点集群:
# crm configure property no-quorum-policy=ignore(当有半数以上的节点在线时,这个集群就认为自己拥有法定人数了,是“合法”的)
# crm configure show
node desktop36.example.com
node desktop46.example.com
primitive ClusterIP ocf:heartbeat:IPaddr2 \
params ip="192.168.2.111" cidr_netmask="32" \
op monitor interval="30s"
property $id="cib-bootstrap-options" \
dc-version="1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f" \
cluster-infrastructure="openais" \
expected-quorum-votes="2" \
stonith-enabled="false" \
no-quorum-policy="ignore"
然后用crm_mon检查后发现集群会在剩下的那个节点上启动这个IP。然而集群现在并没有达到法定人数
现在模拟节点恢复,我们启动 desktop36 上面的Corosync服务,然后检查集群状态。
# /etc/init.d/corosync start
Starting Corosync Cluster Engine (corosync): [ OK ]
# /etc/init.d/pacemaker start
Starting Pacemaker Cluster Manager: [ OK ]# crm_mon
============
Last updated: Fri Aug 28 15:32:13 2009
Stack: openais
Current DC: pcmk-2 - partition with quorum
Version: 1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f
2 Nodes configured, 2 expected votes
1 Resources configured.
============
Online: [ desktop36.example.com desktop46.example.com ]
ClusterIP
(ocf::heartbeat:IPaddr):
Started desktop36.example.com
现在我们可以看到让某些人惊奇的事情,IP资源回到原来那个节点(pcmk-1)上去了。
添加httpd服务
在两台节点都安装httpd
vim /etc/httpd/conf/httpd.conf
<Location /server-status>
    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1
</Location>(大概在921行)
crm(live)configure# primitive website ocf:heartbeat:apache params configfile=/etc/httpd/conf/httpd.conf op monitor interval=30s
过一会儿就可以看到集群把apache启动了
wKioL1PnDx6ye8KLAAFOKT6xkZA415.jpg确保资源在同一个节点上运行:
crm(live)configure# colocation website-with-vip inf: website vip
wKioL1PnD1TDTt6uAAFOKT6xkZA362.jpg指定优先的Location:
crm(live)configure# location master-node website 10: desktop36.example.com
添加fence:(注意添加fence时间一定要同步,并且火墙和selinux都要disabled的)
在宿主机上dd if=/dev/urandom of=fence_xvm.key bs=128 count=1 生成fence_xvm.key这个key文件 然后把它复制到两个节点上重启fence(在两个节点上创建这个/etc/cluster这个目录) 然后启动fence_virtd
crm(live)configure# property stonith-enabled=true
crm(live)configure# primitive vmfence stonith:fence_xvm params pcmk_host_map=desktop36.example.com:vm2;desktop46.example.com:vm3 op monitor interval=60s
然后用crm_mon 查看fence是否添加上
wKiom1PnDuuzfKH1AAGpqVW9pDA875.jpg做后测试用ifdown eth0 看这个机子会不会重启!!!
添加文件存储系统

192.168.2.184 (drbd)
lvcreate -L 2G -n iscsi lzh 然后启动iscsi /etc/init.d/iscsi start
iscsiadm -m discovery -t st -p 192.168.2.183 导入 iscsiadm -m node -l 登录
fdisk /dev/sda
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xa42947a5.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1009, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1009, default 1009):
Using default value 1009

Command (m for help): p

Disk /dev/sda: 2147 MB, 2147483648 bytes
67 heads, 62 sectors/track, 1009 cylinders
Units = cylinders of 4154 * 512 = 2126848 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xa42947a5

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1        1009     2095662   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
然后格式化mkfs.ext4 在另个节点partprobe同步
在crm命令行添加文件系统资源crm(live)configure# primitive webdata ocf:heartbeat:Filesystem params device=/dev/sda1 directory=/var/www/html fstype=ext4 op monitor interval=30s
指定资源的启动顺序:crm(live)configure# order webdata-after-website inf: webdata website
把这几个资源放在一个组:crm(live)configure# group webgrp vip webdata website
然后用crm_mon查看!!ok!