1. 静态解析
vm-4-11 & 12 & 13 执行
# cat >> /etc/hosts << EOF
192.168.4.11 vm-4-11
192.168.4.12 vm-4-12
192.168.4.13 vm-4-13
EOF
2. 共享存储
vm-4-11 & vm-4-12 执行
# yum -y install iscsi-initiator-utils
# cat /etc/iscsi/initiatorname.iscsi
InitiatorName=`iqn.1994-05.com.redhat:541e78fb3870`
InitiatorName=`iqn.1994-05.com.redhat:f1661e45fe92`
vm-4-13 执行
# yum -y install -y targetcli
# systemctl start target && systemctl enable target
# targetcli /backstores/block create block01 /dev/sdb
# targetcli /backstores/block create block02 /dev/sdc
# targetcli /iscsi create
# targetcli /iscsi/iqn.2003-01.org.linux-iscsi.vm-4-13.x8664:sn.d28ab1075e9d/tpg1/luns create /backstores/block/block01
# targetcli /iscsi/iqn.2003-01.org.linux-iscsi.vm-4-13.x8664:sn.d28ab1075e9d/tpg1/luns create /backstores/block/block02
# targetcli /iscsi/iqn.2003-01.org.linux-iscsi.vm-4-13.x8664:sn.d28ab1075e9d/tpg1/acls create iqn.1994-05.com.redhat:541e78fb3870
# targetcli /iscsi/iqn.2003-01.org.linux-iscsi.vm-4-13.x8664:sn.d28ab1075e9d/tpg1/acls create iqn.1994-05.com.redhat:f1661e45fe92
最终结果
# targetcli ls
3. 挂载共享存储盘
vm-4-11 & vm-4-12 执行
# iscsiadm -m discovery -t sendtargets -p vm-4-13
192.168.4.13:3260,1 iqn.2003-01.org.linux-iscsi.vm-4-13.x8664:sn.d28ab1075e9d
login && automatic
# iscsiadm -m node -T iqn.2003-01.org.linux-iscsi.vm-4-13.x8664:sn.d28ab1075e9d -p vm-4-13 -l
# iscsiadm -m node -T iqn.2003-01.org.linux-iscsi.vm-4-13.x8664:sn.d28ab1075e9d -p vm-4-13 --op update -n node.startup -v automatic
logout:
# iscsiadm -m node -T iqn.2003-01.org.linux-iscsi.vm-4-13.x8664:sn.d28ab1075e9d -p vm-4-13 -o delete
or
# iscsiadm -m node -U all
4. 安装集群软件
vm-4-11 & vm-4-12 执行
# yum -y install pcs fence-agents-all lvm2-cluster gfs2-utils
# systemctl restart pcsd && systemctl enable pcsd
# echo "hacluster" | passwd hacluster --stdin
vm-4-11 | vm-4-12 任选1台执行
# pcs cluster destroy --all
# pcs cluster auth vm-4-11 vm-4-12 -u hacluster -p hacluster
# pcs cluster setup --name mysql-ha vm-4-11 vm-4-12
# pcs cluster start --all
# pcs cluster enable --all
# pcs property set stonith-enabled=true
# pcs property set no-quorum-policy=ignore
# pcs property list
# pcs cluster status
# pcs status
# pcs status corosync
5. 配置fence
vm-4-11 | vm-4-12 任选1台执行
# ls -la /dev/disk/by-id/
# pcs stonith delete scsi
# pcs stonith create scsi fence_scsi pcmk_host_list="vm-4-11 vm-4-12" pcmk_reboot_action="off" pcmk_monitor_action="metadata" devices="/dev/disk/by-id/wwn-0x6001405ca469c234a7b461891011aede" meta provides=unfencing
# sg_persist -k /dev/sdb
6. 建立lvm
vm-4-11 | vm-4-12 任选1台执行
# parted --script /dev/sdc "mklabel gpt"
# parted --script /dev/sdc "mkpart primary 0% 100%"
# parted --script /dev/sdc "set 1 lvm on"
# pvcreate /dev/sdc1
# vgcreate vg_mysql /dev/sdc1
# lvcreate -n lv_mysql -l 100%VG vg_mysql
# mkfs.xfs /dev/vg_mysql/lv_mysql
# pvdisplay && pvscan
# vgdisplay && vgscan
# lvdisplay && lvscan
7. 部署mysql
vm-4-11 & vm-4-12 执行
# yum install -y mariadb-server
# mkdir -p /mnt/data_mysql
# mount /dev/vg_mysql/lv_mysql /mnt/data_mysql
vm-4-11 执行
# systemctl start mariadb && systemctl stop mariadb
# mv /var/lib/mysql /mnt/data_mysql
# ln -s /mnt/data_mysql/mysql /var/lib/mysql
# umount /mnt/data_mysql
vm-4-12 执行
# rm -rf /var/lib/mysql
# ln -s /mnt/data_mysql/mysql /var/lib/mysql
8. 配置lvm
vm-4-11 & vm-4-12 执行
# cat /etc/lvm/lvm.conf |egrep 'locking_type = |use_lvmetad ='
locking_type = 1
use_lvmetad = 0
修改这2项如上
# lvmconf --enable-halvm --services --startstopservices
# vgs --noheadings -o vg_name
vg_mysql
如果包含非ha卷组,如rhel_home rhel_root,将其放入/etc/lvm/lvm.conf的 volume_list = [ "rhel_root", "rhel_home" ],没有则为 volume_list = []
# dracut -H -f /boot/initramfs-$(uname -r).img $(uname -r)
# reboot
9. 配置资源
vm-4-11 | vm-4-12 任选1台执行
# pcs resource create lvm_mysql ocf:heartbeat:LVM volgrpname=vg_mysql exclusive=true --group group_mysql
# pcs resource create filesystem_mysql ocf:heartbeat:Filesystem device="/dev/vg_mysql/lv_mysql" directory="/mnt/data_mysql" fstype="xfs" --group group_mysql
# pcs resource create vip_mysql ocf:heartbeat:IPaddr2 ip=192.168.4.10 cidr_netmask=24 nic=eth0:0
# pcs resource create app_mysql service:mariadb --group group_mysql
10. 配置约束
vm-4-11 | vm-4-12 任选1台执行
pcs constraint order set lvm_mysql filesystem_mysql app_mysql vip_mysql
pcs constraint colocation set lvm_mysql filesystem_mysql app_mysql vip_mysql
pcs status
11. 测试
vm-4-11 执行
# mysql -u root -p
> create database demo
> grant all privileges on demo.* to root@'%' identified by 'password';
> flush privileges
远程机 执行
# mysql -h 192.168.4.10 -u root -p
成功登录
vm-4-11 执行
# pcs node standby vm-4-11
模拟当机,ip地址 & mnt目录 & mysql服务 均已飘移到vm-4-12
远程机 执行
# mysql -h 192.168.4.10 -u root -p
成功登录
vm-4-11 执行
# pcs node unstandby vm-4-11
恢复运行
12. custom ocf resource
https://dopensource.com/2017/04/27/creating-custom-ocf-resource-agents/