前提先执行下面操作:
#crm
crm(live/host1)# configure
crm(live/host1)configure# property stonith-enabled=false
crm(live/host1)configure# property no-quorum-policy=ignore
crm(live/host1)configure# verify
crm(live/host1)configure# commit
然后下面开始配置HA资源:
方式一:
直接crm configure edit进入整体复制粘贴即可:
node host1 \
attributes standby=on
node host2 \
attributes standby=off
primitive data_drbd ocf:linbit:drbd \
params drbd_resource=data \
op monitor role=Master interval=10s timoue=20s \
op monitor role=Slave interval=20s timeout=20s \
op start interval=0 timeout=240 \
op stop interval=0 timeout=120
primitive myip IPaddr \
params ip=192.168.1.11
primitive mysql service:mysql
primitive mysqldatafs Filesystem \
params device="/dev/drbd0" directory="/data" fstype=ext4 \
op start interval=0 timeout=60 \
op stop interval=0 timeout=60
ms MS_data_drbd data_drbd \
meta master-max=1 master-node-max=1 clone-max=2 clone-node-max=1 notify=true
colocation myip_with_mysql inf: myip mysql
order mysql_after_mysqldatafs inf: mysqldatafs mysql
colocation mysql_with_mysqldatafs inf: mysql mysqldatafs
order mysqldatafs_afer_MS_data_drbd inf: MS_data_drbd:promote mysqldatafs:start
colocation mysqldatafs_with_MS_data_drbd inf: mysqldatafs MS_data_drbd:Master
property cib-bootstrap-options: \
have-watchdog=false \
dc-version="1.1.19+20180928.0d2680780-1.8-1.1.19+20180928.0d2680780" \
cluster-infrastructure=corosync \
cluster-name=cluster-database \
stonith-enabled=false \
no-quorum-policy=ignore
配置说明如下:
复制完保存退出查看集群资源状态,输入命令crm status
成功!
方式二:
shell脚本执行
#!/bin/bash
crm configure property stonith-enabled=false
sleep 1
crm configure property no-quorum-policy=ignore
sleep 1
crm configure primitive data_drbd ocf:linbit:drbd params drbd_resource=data op monitor role=Master interval=10s timoue=20s op monitor role=Slave interval=20s timeout=20s op start interval=0 timeout=240 op stop interval=0 timeout=120
sleep 1
crm configure ms MS_data_drbd data_drbd meta master-max=1 master-node-max=1 clone-max=2 clone-node-max=1 notify=true
sleep 1
crm configure primitive mysqldatafs Filesystem params device="/dev/drbd0" directory="/HA" fstype=ext4 op start interval=0 timeout=60 op stop interval=0 timeout=60
sleep 1
crm configure colocation mysqldatafs_with_MS_data_drbd inf: mysqldatafs MS_data_drbd:Master
sleep 1
crm configure order mysqldatafs_afer_MS_data_drbd inf: MS_data_drbd:promote mysqldatafs:start
sleep 1
crm configure primitive mysql service:mysql
sleep 1
crm configure colocation mysql_with_mysqldatafs inf: mysql mysqldatafs
sleep 1
crm configure order mysql_after_mysqldatafs inf: mysqldatafs mysql
sleep 1
crm configure primitive myip IPaddr params ip=192.168.1.23
sleep 1
crm configure colocation myip_with_mysql inf: myip mysql
执行完后重启两边的pacemaker服务:
#service pacemaker restart
#crm status
成功!