DRBD+Heartbeat 解决NFS单点故障(3)

[root@test02 ~]#/etc/init.d/rpcbind start
[root@test02 ~]#/etc/init.d/nfs start
[root@test02 ~]# chown -Rnfsnobody.nfsnobody /data
[root@test02 ~]# showmount -e172.16.1.112
Export list for 172.16.1.112:
/data 172.16.1.0/24

[root@test02 ~]# mount -t nfs172.16.1.112:/data /mnt
[root@test02 ~]# ls /mnt
drbd.test lost+found  test01.test
[root@test02 ~]# touch/mnt/test02.test
[root@test02 ~]# ls /mnt
drbd.test lost+found  test01.test  test02.test

[root@test02 ~]# umount /mnt
[root@test02 ~]#/etc/init.d/nfs stop
[root@test02 ~]# umount /data
[root@test02 ~]# drbdadmsecondary r1
version: 8.4.6(api:1/proto:86-101)
GIT-hash:833d830e0152d1e457fa7856e71e11248ccf3f70 build by root@test02, 2015-12-0710:40:31
 0: cs:Connected ro:Secondary/Secondaryds:UpToDate/UpToDate C r-----
    ns:124 nr:1080952 dw:1081076 dr:1726 al:2bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0

至此:drbd nfs手动挂载测试成功

1.4  配置heartbeat
配置heartbeat以达到nfs主节点失效自动将所有资源切换到备用节点

1.4.1          两台nfs服务器上安装heartbeat
添加epel扩展源。官方yum源没有heartbeat

yum -y install epel-release
yum install heartbeat -y

1.4.2          将两台服务器默认配置文件拷贝到/etc/ha.d/并做更改

[root@test01 ~]# rpm -qdheartbeat|grep doc
/usr/share/doc/heartbeat-3.0.4/AUTHORS
/usr/share/doc/heartbeat-3.0.4/COPYING
/usr/share/doc/heartbeat-3.0.4/COPYING.LGPL
/usr/share/doc/heartbeat-3.0.4/ChangeLog
/usr/share/doc/heartbeat-3.0.4/README
/usr/share/doc/heartbeat-3.0.4/apphbd.cf
/usr/share/doc/heartbeat-3.0.4/authkeys
/usr/share/doc/heartbeat-3.0.4/ha.cf
/usr/share/doc/heartbeat-3.0.4/haresources

1 [root@test01 ~]# cp/usr/share/doc/heartbeat-3.0.4/authkeys /usr/share/doc/heartbeat-3.0.4/ha.cf/usr/share/doc/heartbeat-3.0.4/haresources /etc/ha.d/

[root@test01 ~]# egrep -v"#|^$" /etc/ha.d/ha.cf
logfile /var/log/ha-log
logfacility    local0
keepalive 2
deadtime 30
warntime 10
initdead 60
mcast eth0 225.0.0.1 694 1 0
auto_failback on
node    test01
node    test02

[root@test01 ~]# egrep -v"#|^$" /etc/ha.d/authkeys
auth 1
1 sha1 liyanan
[root@test01 ~]# chmod600  /etc/ha.d/authkeys
[root@test01 ~]# ll  /etc/ha.d/authkeys       
-rw------- 1 root root 647 12月  7 15:13 /etc/ha.d/authkeys
 
[root@test01 ~]#echo " test01drbddisk::r1 Filesystem::/dev/drbd0::/data::ext4 nfsIPaddr::172.16.1.100/24/eth1
" >>/etc/ha.d/haresources

将附件的脚本加入到/etc/ha.d/resource.d/ 下并赋予可执行权限。

1.4.3          启动两台服务器heartbeat

[root@test01 ~]#/etc/init.d/heartbeat start
[root@test01 ~]#/etc/init.d/heartbeat status
heartbeat OK [pid 5362 et al]is running on test01 [test01]...

1.4.4          测试heartbeat

全部启动heartbeat服务

[root@test01 ha.d]#/etc/init.d/heartbeat status
heartbeat OK [pid 22646 et al]is running on test01 [test01]...
[root@test02 ~]#/etc/init.d/heartbeat status
heartbeat OK [pid 13217 et al]is running on test02 [test02]...

检查test01挂载

[root@test01 ha.d]# df -h
Filesystem      Size Used Avail Use% Mounted on
/dev/sda2      9.4G 1.6G  7.3G  18% /
tmpfs          495M    0 495M  0% /dev/shm
/dev/sda1      190M  36M  145M  20% /boot
/dev/drbd0      991M 1.3M  939M  1% /data

检查test02挂载

[root@test02 ~]# df -h
Filesystem      Size Used Avail Use% Mounted on
/dev/sda2      9.4G 1.6G  7.3G  18% /
tmpfs          495M    0 495M  0% /dev/shm
/dev/sda1      190M  36M  145M  20% /boot

关闭test01的heartbeat服务后再检查挂载

[root@test01 ha.d]#/etc/init.d/heartbeat stop
Stopping High-Availabilityservices: Done.

[root@test01 ha.d]# df -h
Filesystem      Size Used Avail Use% Mounted on
/dev/sda2      9.4G 1.6G  7.3G  18% /
tmpfs          495M    0  495M  0% /dev/shm
/dev/sda1      190M  36M  145M  20% /boot

再次检查test02挂载

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

转载注明出处:https://www.heiqu.com/2365fd427a01eb69c2c342fa85f0b0b1.html