一、基础环境准备:
防火墙添加规则(VRRP协议通信,所有节点都要执行):
firewall-cmd --direct --permanent --add-rule ipv4 filter INPUT 0 --in-interface em1 --destination 224.0.0.18 --protocol vrrp -j ACCEPT
配置生效命令:
firewall-cmd —reload
seliunx:
查看状态:/usr/sbin/sestatus -v
sed -i “s/^SELINUX=.*/SELINUX=disabled/g” /etc/selinux/config
防火墙重启
ystemctl start/stop/restart firewalld
二、keepalive的安装
yum install -y keepalived
配置keepalived:
/etc/keepalived/keepalived.conf
主节点:
! Configuration File for keepalived
vrrp_script checkService
{
script “/etc/keepalived/traefik.sh”
interval 10
}
vrrp_instance VI_1 {
state BACKUP
interface ens160 #网卡
virtual_router_id 79 #id不能重复
priority 101
nopreempt
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
x.x.x.x # 无人用的IP
}
track_script {
checkService
}
}
备节点:
! Configuration File for keepalived
vrrp_script checkService
{
script “/etc/keepalived/traefik.sh” #检测脚本位置
interval 3
}
vrrp_instance VI_1 {
state BACKUP
interface ens160
virtual_router_id 79
mcast_src_ip x.x.x.x #主节点IP
nopreempt
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
x.x.x.x #无人用的IP
}
track_script {
checkService
}
}
重启keepalived命令:
systemctl start/stop/status keepalived.service
三、traefik检查脚本
traefik.sh
#!/bin/bash
checktraefik=$(/usr/bin/docker node ps |grep ‘traefik:v2.7.1’|grep ‘80’|grep ‘Running’|wc -l)
if [ $checktraefik -eq 1 ];then
exit 0
else
exit 1
fi