部署heartbeat+DRBD+NFS
heartbeat主从,DRBD主从
实验环境:
nfs01 eth0 10.0.0.31 eth1 172.16.1.31
nfs02 eth0 10.0.0.36 eth1 172.16.1.36
vip eth0 10.0.0.33
安装heartbeat
nfs01:
关闭防火墙、关闭selinux
[root@nfs01 ~]# uname -r
2.6.32-696.el6.x86_64
[root@nfs01 ~]# cat /etc/redhat-release
CentOS release 6.9 (Final)
[root@nfs01 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.1.31 nfs01
172.16.1.36 nfs02
安装heartbeat
[root@nfs01 ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
[root@nfs01 ~]# yum -y install heartbeat*
[root@nfs01 ~]# rpm -qa |grep heartbeat
heartbeat-libs-3.0.4-2.el6.x86_64
heartbeat-3.0.4-2.el6.x86_64
heartbeat-devel-3.0.4-2.el6.x86_64
[root@nfs01 ~]# cp -a /usr/share/doc/heartbeat-3.0.4/{ha.cf,haresources,authkeys} /etc/ha.d/
[root@nfs01 ~]# chmod 600 /etc/ha.d/authkeys
[root@nfs01 ~]# cd /etc/ha.d/
[root@nfs01 ha.d]# cat ha.cf
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
warntime 10
initdead 60
udpport 694
bcast eth1
ucast eth1 172.16.1.36
auto_failback on
node nfs01
node nfs02
ping 172.16.1.36
respawn hacluster /usr/lib64/heartbeat/ipfail
apiauth ipfail gid=haclient uid=hacluster
[root@nfs01 ha.d]# echo -e "auth 1\n1 sha1 ha_nfs" >authkeys
[root@nfs01 ha.d]# echo 'nfs01 IPaddr::172.16.1.33/24/eth1' >/etc/ha.d/haresources
nfs02:
[root@nfs02 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.1.31 nfs01
172.16.1.36 nfs02
[root@nfs02 ~]# cat /etc/redhat-release
CentOS release 6.9 (Final)
[root@nfs02 ~]# uname -r
2.6.32-696.el6.x86_64
[root@nfs02 ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
安装heartbeat
[root@nfs02 ~]# yum -y install heartbeat*
[root@nfs02 ~]# rpm -qa |grep heartbeat
heartbeat-libs-3.0.4-2.el6.x86_64
heartbeat-3.0.4-2.el6.x86_64
heartbeat-devel-3.0.4-2.el6.x86_64
[root@nfs02 ~]# cp -a /usr/share/doc/heartbeat-3.0.4/{ha.cf,haresources,authkeys} /etc/ha.d/
[root@nfs02 ~]# chmod 600 /etc/ha.d/authkeys
[root@nfs02 ~]# cat /etc/ha.d/ha.cf
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
warntime 10
initdead 60
udpport 694
bcast eth1
ucast eth1 172.16.1.31
auto_failback on
node nfs01
node nfs02
ping 172.16.1.31
respawn hacluster /usr/lib64/heartbeat/ipfail
apiauth ipfail gid=haclient uid=hacluster
[root@nfs02 ~]# echo -e "auth 1\n1 sha1 ha_nfs" >/etc/ha.d/authkeys
[root@nfs02 ~]# echo 'nfs01 IPaddr::172.16.1.33/24/eth1' >/etc/ha.d/haresources
测试heartbeat可用性:
nfs01和nfs02都启动heartbeat服务
[root@nfs01 ha.d]# /etc/init.d/heartbeat start
Starting High-Availability services: INFO: Resource is stopped
Done.
[root@nfs01 ha.d]# ip a s eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:8a:db:1f brd ff:ff:ff:ff:ff:ff
inet 172.16.1.31/24 brd 172.16.1.255 scope global eth1
inet 172.16.1.33/24 brd 172.16.1.255 scope global secondary eth1
inet6 fe80::20c:29ff:fe8a:db1f/64 scope link
valid_lft forever preferred_lft forever
[root@nfs02 ~]# /etc/init.d/heartbeat start
Starting High-Availability services: INFO: Resource is stopped
Done.
[root@nfs02 ~]# ip a s eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:a0:73:f2 brd ff:ff:ff:ff:ff:ff
inet 172.16.1.36/24 brd 172.16.1.255 scope global eth1
inet6 fe80::20c:29ff:fea0:73f2/64 scope link
valid_lft forever preferred_lft forever
安装DRBD
一下为两台设备相同的操作(两台设备都添加一块512M的硬盘)
[root@nfs01 ~]# rpm -Uvh https://www.elrepo.org/elrepo-release-6-8.el6.elrepo.noarch.rpm
[root@nfs01 ~]# yum install drbd84-utils kmod-drbd84 -y
[root@nfs01 ~]# reboot
[root@nfs01 ~]# cp /etc/drbd.d/global_common.conf{,.bak}
[root@nfs01 ~]# cat /etc/drbd.d/global_common.conf
global {
usage-count no;
}
common {
protocol C;
handlers {
}
startup {
wfc-timeout 240;
degr-wfc-timeout 240;
outdated-wfc-timeout 240;
}
syncer {
rate 30M;
}
disk {
on-io-error detach;
}
net {
cram-hmac-alg sha1;
shared-secret "testdrbd";
}
}
[root@nfs01 ~]# vim /etc/drbd.d/r0.res
resource r0 {
on nfs01 {
device /dev/drbd1;
disk /dev/sdb1;
address 10.0.0.31:7789;
meta-disk internal;
}
on nfs02 {
device /dev/drbd1;
disk /dev/sdb1;
address 10.0.0.36:7789;
meta-disk internal;
}
}
[root@nfs01 ~]# fdisk -cu /dev/sdb
n;p;1;回车;回车;w
[root@nfs01 ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 536 MB, 536870912 bytes
64 heads, 32 sectors/track, 512 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x019defe6
Device Boot Start End Blocks Id System
/dev/sdb1 2 512 523264 83 Linux
[root@nfs01 ~]# mkdir /nfs
[root@nfs01 ~]# drbdadm create-md r0
[root@nfs01 ~]# drbdadm create-md r0 #再次执行,输入yes
[root@nfs01 ~]# cat /proc/drbd
[root@nfs01 ~]# /etc/init.d/drbd start
[root@nfs01 ~]# /etc/init.d/drbd status
以下操作只在主节点执行
[root@nfs01 ~]# drbdadm primary --force r0
[root@nfs01 ~]# /etc/init.d/drbd status
[root@nfs01 ~]# mkfs.ext4 /dev/drbd1
[root@nfs01 ~]# mount /dev/drbd1 /nfs/
[root@nfs01 ~]# touch /nfs/$(date +%F).txt
验证DRBD故障切换
[root@nfs01 ~]# umount /nfs/
[root@nfs01 ~]# drbdadm secondary r0
[root@nfs02 ~]# drbdadm primary r0
[root@nfs02 ~]# mount /dev/drbd1 /nfs/
[root@nfs02 ~]# ll /nfs/
total 12
-rw-r--r-- 1 root root 0 Jan 15 22:40 2019-01-15.txt
drwx------ 2 root root 12288 Jan 15 22:40 lost+found
安装NFS
以下操作两台设备都需要操作
[root@nfs01 ~]# yum install nfs-utils -y
[root@nfs01 ~]# /etc/init.d/rpcbind start
[root@nfs01 ~]# chkconfig rpcbind on
[root@nfs01 ~]# echo '/nfs 172.16.1.0/24(rw,all_squash,sync)'>/etc/exports
[root@nfs01 ~]# echo 'nfs01 IPaddr::172.16.1.33/24/eth1 drbddisk::r0 Filesystem::/dev/drbd1::/nfs::ext4 nfs' >/etc/ha.d/haresources
[root@nfs01 ~]# sed -i.bak '69s#primary#primary --force#g' /etc/ha.d/resource.d/drbddisk
[root@nfs01 ~]# /etc/init.d/drbd restart
[root@nfs01 ~]# /etc/init.d/heartbeat restart
完
服务宕机切换脚本:
[root@nfs02 scripts]# cat check_hb_nfs_drbd.sh
#!/bin/bash
stop_heartbeat(){
/etc/init.d/heartbeat stop >/dev/null 2>&1
}
/etc/init.d/drbd status >/dev/null 2>&1
[ $? -ne 0 ] && stop_heartbeat
/etc/init.d/nfs status >/dev/null 2>&1
if [ $? -ne 0 ];then
/etc/init.d/nfs restart >/dev/null 2>&1
# /etc/init.d/nfs status >/dev/null 2>&1
[ $? -ne 0 ] && stop_heartbeat
fi

浙公网安备 33010602011771号