CentOS 7.5数据库架构之NFS+Heartbeat+DRBD实测(5)

dbdackup也是同样的安装方法,配置文件直接scp过去就可以了,然后修改

[root@dbmaster ~]# scp -r /usr/local/heartbeat/etc/ha.d/{authkeys,haresources,ha.cf} root@dbbackup:/usr/local/heartbeat/etc/ha.d/ [root@dbbackup ha.d]# vim /usr/local/heartbeat/etc/ha.d/ha.cf ucast ens32 192.168.111.3 #把backup节点上ha.cf配置文件中ucast中IP改为对方 [root@dbmaster ~]# ln -svf /usr/local/heartbeat/lib64/heartbeat/plugins/RAExec/* /usr/local/heartbeat/lib/heartbeat/plugins/RAExec/ [root@dbmaster ~]# ln -svf /usr/local/heartbeat/lib64/heartbeat/plugins/* /usr/local/heartbeat/lib/heartbeat/plugins/ #2机器将这些库文件链接过去,要不启动报错 May 13 13:09:27 dbmaster heartbeat: [86183]: ERROR: Illegal directive [ucast] in /usr/local/heartbeat/etc/ha.d/ha.cf 部署NFS及配合heartbeat [root@dbbackup ~]# yum -y install nfs-utils nfs-utils-lib nfs4-acl-tools #dbmaster和dbbackup安装 [root@dbmaster ~]# vim /etc/exports /nfs 192.168.111.0/255.255.255.0(rw,sync,no_root_squash) #设置nfs共享目录,权限,网段 [root@dbmaster ~]# systemctl restart rpcbind #启动顺序一定是rpcbind->nfs,否则有可能出现错误 #在这里nfs不需要启动,它由heartbeat控制 [root@dbmaster ~]# systemctl start heartbeat [root@dbmaster ~]# systemctl enable heartbeat #最多等一两分钟VIP肯定出来,否则查看日志 [root@dbmaster ~]# ip a | grep inet #主上查看 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host inet 192.168.111.3/24 brd 192.168.111.255 scope global noprefixroute ens32 inet 192.168.111.100/24 brd 192.168.111.255 scope global secondary ens32:0 #到了这,VIP肯定要出来,可以稍等会,观察下日志。如果出错,上面可能哪一步没有到位 [root@dbmaster ~]# mount | grep drbd /dev/drbd0 on /nfs type ext4 (rw,relatime,data=ordered) #这个也已经根据配置自动挂载 [root@dbbackup ~]# showmount -e 192.168.111.100 Export list for 192.168.111.100: /nfs 192.168.111.0/255.255.255.0 #查看VIP共享的目录

配置nfs自动挂载

[root@localhost ~]# mkdir /nfs [root@localhost ~]# mount 192.168.111.100:/nfs/ /nfs/ #客户端测试 [root@localhost ~]# echo "192.168.111.100:/nfs /nfs nfs defaults,soft,intr 0 0" >> /etc/fstab [root@localhost ~]# tail -1 /etc/fstab 192.168.111.100:/nfs /nfs nfs defaults,soft,intr 0 0 #Nfs是类型 #soft参数是为了向用户输出错误信息 #intr参数为了解决当网络出现故障时,我们可以通过按下ctrl+c组合键来终止操作

验证:接下来我们在主上把nfs服务关掉,模拟故障,看VIP是否切换主机

[root@dbmaster ~]# systemctl stop nfs [root@dbmaster ~]# systemctl status nfs ● nfs-server.service - NFS server and services Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; disabled; vendor preset: disabled) Drop-In: /run/systemd/generator/nfs-server.service.d └─order-with-mounts.conf Active: inactive (dead) since 二 2019-05-14 18:21:09 CST; 6s ago Process: 61802 ExecStopPost=/usr/sbin/exportfs -f (code=exited, status=0/SUCCESS) Process: 61799 ExecStopPost=/usr/sbin/exportfs -au (code=exited, status=0/SUCCESS) Process: 61797 ExecStop=/usr/sbin/rpc.nfsd 0 (code=exited, status=0/SUCCESS) Main PID: 60625 (code=exited, status=0/SUCCESS) 5月 14 16:35:58 dbmaster systemd[1]: Starting NFS server and services... 5月 14 16:35:58 dbmaster systemd[1]: Started NFS server and services. 5月 14 18:21:09 dbmaster systemd[1]: Stopping NFS server and services... 5月 14 18:21:09 dbmaster systemd[1]: Stopped NFS server and services.

我在主被两台机器上查看debug日志,没有任何变动

[root@dbbackup ~]# cd /nfs #我在挂载了VIP的机器上查看共享目录能否使用,卡死终端

总结下原因:heartbeat没有监控到nfs的服务状态,它自身想当然的认为,只有heartbeat服务出故障,才切VIP。

解决:我们将nfs,和heartbeat服务做一个捆绑,类似于事物性质。即nfs出问题,heartbeat也要宕掉。这里通过脚本实现。

[root@dbmaster ~]# vim /opt/monitornfs.sh while true do drbdstatus=`cat /proc/drbd 2> /dev/null | grep ro | tail -n1 | awk -F':' '{print $4}' | awk -F'/' '{print $1}'` nfsstatus=`systemctl status nfs&>/dev/null ; echo $?` if [ -z $drbdstatus ];then sleep 10 continue elif [ $drbdstatus == 'Primary' ];then if [ $nfsstatus -ne 0 ];then systemctl start nfs &> /dev/null newnfsstatus=`systemctl status nfs&>/dev/null ; echo $?` if [ $newnfsstatus -ne 0 ];then systemctl stop heartbeat #尝试开启之后若还是不行,则关掉heartbeat fi fi fi sleep 5 done [root@dbmaster ~]# chmod +x /opt/monitornfs.sh [root@dbmaster ~]# nohup /opt/monitornfs.sh & #以上关于脚本操作,在dbbackup上重复

测试

[root@dbmaster ~]# systemctl stop nfs #主节点关掉nfs服务 #但是后台的脚本又给他开启了 [root@dbmaster ~]# systemctl stop heartbeat #VIP切换到备机了

但是nfs客户端的使用并不影响,切换的时候会有轻微的延迟。

nfs切记要挂载到别的机器上不要为了省事,省机器

Linux公社的RSS地址https://www.linuxidc.com/rssFeed.aspx

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/457e3b51f6565777a75797eeae2a5949.html