drbd参考上一篇博客
先明确主服务器的keepalivde的配置
drbd关闭时执行的脚本
keepalivde关闭时执行的脚本
故障恢复主服务器自动抢回vip的脚本
脚本记得给执行权限
从服务器的keepalivde的配置
主服务器失效后,从服务器自动挂载,并且成为主服务器,vip也会跟随过来。
原主服务器正常后,主服务器自动降为从服务器,并且取消挂载,vip也会自动转移走。
两台主机操作
drbdadm status #确定drbd正常工作
dnf install -y keepalived
alpha节点操作
/etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from keepalived@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id DRBD_HA_MASTER
}
vrrp_script chk_drbd {
script "/etc/keepalived/check_drbd.sh"
interval 5
}
vrrp_instance VI_1 {
state MASTER
interface ens160
virtual_router_id 51
priority 150
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
chk_drbd
}
notify_stop /etc/keepalived/notify_stop.sh ### keepalived服务关闭执行的脚本
notify_master /etc/keepalived/notify_master.sh ### 重新拿回 master 的脚本
virtual_ipaddress {
192.168.110.88 ### vip 请选择一个没有在占用的IP地址
}
}
通过上面的配置文件,这里需要编写三个脚本,如下:
/etc/keepalived/check_drbd.sh
#!/bin/bash
# Author:hukey
systemctl is-active --quiet drbd
if [ $? -ne 0 ]; then
systemctl start drbd
if [ $? -ne 0 ]; then
umount /mnt
drbdadm secondary drbd0
systemctl stop keepalived
fi
fi
/etc/keepalived/notify_stop.sh
#!/bin/bash
# Author:hukey
time=`date "+%F %H:%M:%S"`
echo -e "$time ------notify_stop------\n" >> /etc/keepalived/logs/notify_stop.log
umount /mnt
drbdadm secondary drbd0
/usr/sbin/fuser -k /mnt &>> /etc/keepalived/logs/notify_stop.log
/bin/umount /mnt &>> /etc/keepalived/logs/notify_stop.log
echo -e "\n" >> /etc/keepalived/logs/notify_stop.log
/etc/keepalived/notify_master.sh
#!/bin/bash
# Author:hukey
time=`date "+%F %H:%M:%S"`
echo -e "$time ------notify_master------\n" >> /etc/keepalived/logs/notify_master.log
systemctl start drbd &>> /etc/keepalived/logs/notify_master.log
for (( i=1; i <=3; i++))
do
drbdadm status | egrep -q 'Primary'
if [ $? -ne 0 ]; then
mount /mnt
drbdadm primary drbd0
/bin/mount /dev/drbd0 /mnt &>> /etc/keepalived/logs/notify_master.log
break
else
sleep 3
fi
done
echo -e "\n" >> /etc/keepalived/logs/notify_master.
脚本所需目录和命令
yum install -y psmisc
mkdir -pv /etc/keepalived/logs
------------------------alpha节点操作完毕------------------------
bravo节点操作
/etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from keepalived@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id DRBD_HA_BACKUP
}
vrrp_instance VI_1 {
state BACKUP
interface ens160
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
notify_master /etc/keepalived/notify_master.sh
notify_backup /etc/keepalived/notify_backup.sh
virtual_ipaddress {
192.168.110.88
}
}
/etc/keepalived/notify_master.sh
#!/bin/bash
# Author:hukey
time=`date "+%F %H:%M:%S"`
echo -e "$time ------notify_master------\n" >> /etc/keepalived/logs/notify_master.log
systemctl start drbd &>> /etc/keepalived/logs/notify_master.log
for (( i=1; i <=3; i++))
do
drbdadm status | egrep -q 'Primary'
if [ $? -ne 0 ]; then
drbdadm primary drbd0
mount /dev/drbd0 /mnt
/bin/mount /dev/drbd0 /mnt &>> /etc/keepalived/logs/notify_master.log
break
else
sleep 3
fi
done
echo -e "\n" >> /etc/keepalived/logs/notify_master.log
/etc/keepalived/notify_backup.sh
#!/bin/bash
# Author:hukey
time=`date "+%F %H:%M:%S"`
echo -e "$time ------notify_backup------\n" &>> /etc/keepalived/logs/notify_backup.log
umount /mnt
drbdadm secondary drbd0
/usr/sbin/fuser -k /data &>> /etc/keepalived/logs/notify_backup.log
/bin/umount /dev/drbd0 &>> /etc/keepalived/logs/notify_backup.log
echo $time
echo -e "\n" &>> /etc/keepalived/logs/notify_backup.log
启动服务 两台主机操作
#开机自启
systemctl enable drbd keepalived
systemctl restart drbd keepalived
启动后查看 alpha 节点 VIP 和 目录是否挂载:
注意:
如果发现 vip 或者 drbd 没有挂载,检查一下配置文件是否有问题。
测试
1.关闭 alpha 节点 keepalived 服务
systemctl stop keepalived
2.查看 bravo 节点是否升级为主节点
3.alpha开启节点 keepalived 服务 bravo 节点关闭keepalived 服务
如果vip会自动漂移和会自动挂载就说明成功了
还有一个可以测试的,主服务器systemctl stop drbd,五秒后使用systemctl status drbd查看,如果已经启动说明脚本基本没问题。
最后drbd+keepalived就完成了,还可以加上nfs。nfs比较简单就不写了。。。
博主真是太厉害了!!!
博主真是太厉害了!!!
叼茂SEO.bfbikes.com
不错不错,我喜欢看
想想你的文章写的特别好https://www.ea55.com/
想想你的文章写的特别好www.jiwenlaw.com
哈哈哈,写的太好了https://www.cscnn.com/
真棒!
真棒!
《冰球少年2022》国产剧高清在线免费观看:https://www.jgz518.com/xingkong/37738.html
《三叉戟》动作片高清在线免费观看:https://www.jgz518.com/xingkong/138599.html
《油脂》爱情片高清在线免费观看:https://www.jgz518.com/xingkong/23512.html
哈哈哈,写的太好了https://www.lawjida.com/