----------01在两台服务器上配置nfs服务,设置共享目录
nfs服务端; (sever client)
rpm -qa nfs-utils rpcbind
yum -y install nfs-utils rpcbind
systemctl start rpcbind.service
systemctl enable rpcbind.service
systemctl start nfs.service
systemctl enable nfs.service
mkdir /data01 -p
chown -R nfsnobody:nfsnobody /data01
echo "/data01 192.0.0.1/8(rw,sync)" >> /etc/exports
exportfs -a
exportfs -v
--------02 安装drbd
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
yum install -y drbd90-utils kmod-drbd90
modprobe drbd
echo drbd > /etc/modules-load.d/drbd.conf
lsmod |grep drbd
# 快照01
#配置:
mv /etc/drbd.d/global_common.conf /etc/drbd.d/global_common.conf.orig
wget http://soft73it.oss-cn-shenzhen.aliyuncs.com/app/drbd/global_common.conf -P /etc/drbd.d/ -q
wget http://soft73it.oss-cn-shenzhen.aliyuncs.com/app/drbd/r1.res -P /etc/drbd.d/ -q
cat << EOF > /etc/drbd.d/global_common.conf
global {
usage-count no;
}
common {
net {
protocol C;
}
}
EOF
使用分区 核心问题要分区
fdisk /dev/sdb n p w
#dd if=/dev/zero of=/dev/sdb1 bs=1M count=100
[root@node4 drbd.d]# cat r1.res
resource r1 { #定义资源组名称为r1
net {
cram-hmac-alg sha1; #使用sha1加密
shared-secret "123456"; #生成加密密钥
}
volume 1 { #定义卷组
device /dev/drbd1; #逻辑设备路径(建立块设备)
disk /dev/sdb1; #物理设备路径(用于复制的分区)
meta-disk internal; #meta data信息存放的方式,该处为内部存储,即和真实数据放在一起存储
}
on node4 { #on开头,后面是主机名称(需与uname -n相同)
node-id 0;
address 192.168.1.54:7000; #设置drbd监听地址和端口
}
on node5 {
node-id 1;
address 192.168.1.55:7000;
}
connection {
host node4 port 7000;
host node5 port 7000;
net {
protocol C; #使用drbd的第三种同步协议,表示收到对方主机写入确认后,则认为写入完成
}
}
}
#必须磁盘存在,不用格式化
drbdadm -c /etc/drbd.conf create-md all
drbdadm up r1
drbdadm primary --force r1
drbdadm status r1
drbdadm cstate r1
drbdadm dstate r1
drbdadm status
磁盘已经建立raid1,fdisk -l可以看到/dev/drbd1 磁盘
在主上执行挂载,从上无法格式 挂载
mkfs.xfs /dev/drbd1 ##格式化/dev/drbd1
mount /dev/drbd1 /data01 ##挂载
#当文件打开时,无法umount 无法转primary
systemctl enable drbd
切换:
主 umount /dev/drbd1 drbdadm secondary r1
从 drbdadm primary r mount /dev/drbd1 /data01
---------keepalive 集成------
参考 https://www.jianshu.com/p/a6b5ab36292a
处理keepalived脑裂现象:检测应用的存活状态的脚本,应用不存在则kill keepalive
# install keepalived
wget http://soft73it.oss-cn-shenzhen.aliyuncs.com/app/keepalived/202011/keepalive.sh -P /tmp -q
bash /tmp/keepalive.sh
wget http://soft73it.oss-cn-shenzhen.aliyuncs.com/app/keepalived/202011/drbd/app_check.sh /etc/keepalived/
wget http://soft73it.oss-cn-shenzhen.aliyuncs.com/app/keepalived/202011/drbd/notify_stop.sh /etc/keepalived/
chmod +x /etc/keepalived/app_check.sh
chmod +x /etc/keepalived/notify_stop.sh
验证:
systemctl stop nfs nfs检测异常会自动启动
systemctl stop keepalived keeplived检测异常会自动启动,但会导致vip漂移 drbd切换