上篇博客演示了DRBD的配置和工作原理,其角色切换是手动的实现的,有时需要自动完成其角色转换
下面由drbd+pacemaker实现高可用来演示其功能
我们在上篇博客的基础上继续演示
(一)
集群资源不能开机自启动,先将服务关闭
[[email protected] ~]## cat /proc/drbd看谁是主节点 卸载降级 停止
umount /mydata
drbdadm secondary web
sercice drbd stop
chkconfig drbd off
次节点也停止
service drbd stop
chkconfig drbd off
(二)安装软件
[[email protected] ~]#yum install -y corosync pacemaker
下载并安装 crmsh-1.2.6-4.el6.x86_64.rpm pssh-2.3.1-2.el6.x86_64.rpm
(三)编辑配置文件
vim /etc/corosync/corosync.conf
bindnetaddr 172.16.0.0
mcastaddr 226.94.15.127 #多播地址
添加下面两项
service {
name: pacemaker
ver: 0
}
aisexec { user: root
group: root
}
生成认证文件authkey
将认证文件和配置文件复制到另个节点上
[[email protected] ~]#scp -p authkey corosync.conf node2.lxb.com:/etc/xorosync/
(四)启动服务 (两边都启动)
(五) 进入crm命令行定义资源
先配置属性
将DRBD配置成高可用资源
crm(live)configure# primitive webdrbd ocf:linbit:drbd params drbd_resource=web op monitor role=Master interval=50s timeout=30s op monitor role=Slave interval=60s timeout=30s op start timeout=240s op stop timeout=100s crm(live)configure#verify crm(live)configure# master MS_Webdrbd webdrbd meta master-max="1" master-node-max="1" clone-max="2" clone-node-max="1" notify="true" crm(live)configure#verify crm(live)configure#commit
(六)演示
由上图可知 此时node1为主节点 假如该节点故障
crm(live)#node standby node1.lxb.com
node2自动提升为主节点
我们让node1再上线
crm(live)#node online node1.lxb.com
由上面可知节点下线 再上线 先为备用节点 当主节点下线时 自动转移为主节点 而不是一上线直接为主节点
(七)
下面添加文件系统资源来演示效果
crm(live)configure#primitive mysqlfs ocf:heartbeat:Filesystem params device=/dev/debd0 directory=/mydata fstype=ext4 op monitor interbal=30s timeout=40s op start timeout=60s op stop timeout=60s onfail=restart crm(live)configure#verify #如果出错可以删除重新定义 也可以edit修改
文件系统可以挂载使用 要与主从资源的主资源在一起 而且要文件系统资源后启动
#位置约束 crm(live)configure#colocation mysqlfs_with_ms_webdrbd_master inf: mysqlfs ms_webdrbd:Master crm(live)configure#verify #顺序约束 crm(live)configure#order mysqlfs_after_ms_webdrbd_master mandatory: ms_webdrbd:promote mysqllfs:start crm(live)configure#verify
将节点1下线
转载于:https://blog.51cto.com/baglinux/1402163