大致过程:
pacemaker安装与配置
drbd安装与配置
pacemaker资源及其约束的配置
测试自动切换
OS:CentOS 6.2
主节点:SER-206
备用节点:SER-104
一、pacemaker的安装与配置:
参考:http://share.blog.51cto.com/278008/850752,过程略,直接贴配置文件如下:
cat /etc/corosync/corosync.conf
-
# Please read the corosync.conf.5 manual page
-
compatibility: whitetank
-
aisexec {
-
user: root
-
group: root
-
}
-
service {
-
name: pacemaker
-
ver: 0
-
}
-
totem {
-
version: 2
-
secauth: off
-
threads: 0
-
interface {
-
ringnumber: 0
-
bindnetaddr: 10.10.14.0
-
mcastaddr: 226.94.1.1
-
mcastport: 5405
-
ttl: 64
-
}
-
}
-
-
logging {
-
fileline: off
-
to_stderr: no
-
to_logfile: yes
-
to_syslog: no
-
logfile: /var/log/cluster/corosync.log
-
debug: off
-
timestamp: on
-
logger_subsys {
-
subsys: AMF
-
debug: off
-
}
-
}
-
-
amf {
-
mode: disabled
-
}
二、drbd的安装与配置:
参考:http://share.blog.51cto.com/278008/845357,但是编译和安装过程有所不同,配置文件也有所改动:
下载drbd源码并编译、安装:
-
mkdir -p /root/rpmbuild/SOURCES
-
-
wget http://oss.linbit.com/drbd/8.4/drbd-8.4.1.tar.gz
-
tar -zxvf drbd-*
-
cd drbd-*
-
./configure --enable-spec --with-km
-
cp ../drbd*.tar.gz `rpm -E %_sourcedir`
-
rpmbuild -bb drbd.spec
-
rpmbuild -bb drbd-kernel.spec
-
-
rpm -ivh /root/rpmbuild/RPMS/drbd-* //全部安装
-
modprobe drbd
注:1) 可以看到本文的编译过程跟官方文档稍有不同,因为按照官方文档进行编译时一直出错,始终过不去。
2) 这里的编译安装跟前面的文章也稍有不同。刚开始按照前面的文章进行安装与配置,drbd本身是OK的;但是在pacemaker中配置drbd资源时,出了错:
- ERROR: lrm_get_rsc_type_metadata(578): got a return code HA_FAIL from a reply message of rmetadata with function get_ret_from_msg.
- ERROR: ocf:linbit:drbd: could not parse meta-data.
这个错误的原因是,drbd资源没有安装成功:
ls -lh /usr/lib/ocf/resource.d/linbit,发现该目录中根本找不到drbd这个ra。
下面是drbd的最终配置文件:
cat /etc/drbd.d/global_common.conf
-
global {
-
usage-count yes;
-
}
-
-
common {
-
handlers {
-
pri-on-incon-degr "/usr/lib/drbd/notify-pri-on-incon-degr.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f";
-
pri-lost-after-sb "/usr/lib/drbd/notify-pri-lost-after-sb.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f";
-
local-io-error "/usr/lib/drbd/notify-io-error.sh; /usr/lib/drbd/notify-emergency-shutdown.sh; echo o > /proc/sysrq-trigger ; halt -f";
-
}
-
-
startup {
-
# wfc-timeout degr-wfc-timeout outdated-wfc-timeout wait-after-sb
-
}
-
-
options {
-
# cpu-mask on-no-data-accessible
-
}
-
-
disk {
-
on-io-error detach;
-
resync-rate 30M;
-
}
-
-
net {
-
protocol C;
-
cram-hmac-alg sha1;
-
shared-secret "111111";
-
}
-
}
与前面的文章基本相同,但取消了startup的配置,以及disk的fence选项。
cat /etc/drbd.d/redis.res
-
resource redis {
-
device /dev/drbd0;
-
disk /dev/VolGroup00/LogVol01;
-
meta-disk internal;
-
on SER-206 {
-
address 10.10.14.174:9876;
-
}
-
on SER-104 {
-
address 10.10.14.5:9876;
-
}
-
}
三、配置pacemaker资源及约束:
1) 规划
需要哪些资源?
...
需要哪些约束?
...
重申一遍:配置某个RA前,进入ra模式使用meta查看一下该RA的常用选项,及其语法规则,有的选项后面带单位s(秒),有的不带。另外,建议直接调高pacemaker群集默认的最小值。示例如:
crm(live)ra#meta ocf:heartbeat:Filesystem
crm(live)configure# property default-action-timeout=60
2) 开始配置
主备节点停止drbd自启动:
chkconfig drbd off
主备节点创建redis的RA,不用手动写脚本了,方便:
-
cp $REDIS_HOME/utils/redis_init_scripts /etc/init.d/redis
-
-
然后,要修改CONF目录的配置,指定自己的redis配置文件的真实路径。
使用CLI配置资源及约束:
配置集群的几个默认属性:
-
crm(live)configure# property no-quorum-polic=ignore
-
crm(live)configure# property stonith-enabled=false
-
crm(live)configure# property default-action-timeout=60
-
crm(live)configure# rsc_defaults resource-stickiness=100
-
crm(live)configure# commit
配置虚拟IP资源:
-
crm(live)configure# primitive VIP ocf:heartbeat:IPaddr2 \ #斜杠前有空格
-
> params ip=10.10.0.2 cidr_netmask=24 \ #根据实际情况进行配置,跟前端服务器的网段要能通!
-
> op monitor interval=10s timeout=20s
-
crm(live)configure# commit
配置drbd资源,以及drbd主从资源:
-
crm(live)# cib new drbd
-
INFO: drbd shadow CIB created
-
crm(drbd)# configure primitive drbd0 ocf:linbit:drbd \
-
> params drbd_resource=redis drbdconf=/etc/drbd.conf \
-
> op start timeout=250 \
-
> op stop timeout=110 \
-
> op promote timeout=100 \
-
> op demote timeout=100 \
-
> op notify timeout=100 \
-
> op monitor role=Master interval=20 timeout=30 \
-
> op monitor role=Slave interval=30 timeout=30
-
-
crm(drbd)# configure ms ms-drbd0 drbd0 \
-
> meta master-max=1 master-node-max=1 clone-max=2 clone-node-max=1 notify=true
-
crm(drbd)# cib commit drbd
配置文件系统资源:
-
crm(live)# cib new fs
-
INFO: fs shadow CIB created
-
crm(fs)# configure primitive fs-drbd0 ocf:heartbeat:Filesystem \
-
> params device=/dev/drbd0 directory=/data fstype=xfs \
-
> op start timeout=70 \
-
> op stop timeout=70 \
-
> op notify timeout=70 \
-
> op monitor interval=30 timeout=50
-
crm(fs)# cib commit fs
配置redis资源:
-
crm(live)configure# primitive redis lsb:redis
-
crm(live)configure# commit
把fs-drbd0、VIP、redis进行编组:
-
crm(live)configure# group redis_group fs_drbd0 VIP redis
-
crm(live)configure# commit
配置组资源和drbd主节点的约束:
-
crm(live)configure# colocation redis_group-on-drbd inf: redis_group ms-drbd0:Master
-
crm(live)configure# order redis_group-after-drbd inf: ms-drbd0:Promote redis_group:start
查看集群状态:
crm status
四、测试自动切换:
本人测试OK。