安装
rpm -ivh ./*.rpm --nodeps --force
检测脚本复制到/etc/keepalived/
,命名为check_platform.sh
#!bin/bash
# 检查中台前端服务端口5601的访问状态
curl -s http://127.0.0.1:5601 > /dev/null 2>&1
if [ $? -ne 0 ]; then
# 如果服务不可达,返回1表示失败
exit 1
fi
# 服务可达,返回0表示成功
exit 0
修改/etc/keepalived/
配置文件keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id keepalived1
vrrp_skip_check_adv_addr
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_script check_platform {
script "/etc/keepalived/check_platform.sh"
interval 2 # 每两秒执行一次脚本
weight -20 # 权重,服务失败直接-20
fall 2 # 连续失败2次触发优先级下降
rise 2 # 连续成功2次就恢复优先级
}
vrrp_instance PLATFORM_VI_1 {
state BACKUP #主从节点BACKUP、MASTER 都配主,都配从,都可以
interface ens192 #对应网卡ip a查看
virtual_router_id 81
priority 100 #权重
advert_int 1 #广播间隔
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.22.32.166 #虚IP
}
track_script {
check_platform
}
}
增加权限
chmod +x /etc/keepalived/check_platform.sh
启动
systemctl start keepalived
查看是否启动成功,网卡中多了虚拟的ip则启动成功
ip a
查看日志
journalctl -u keepalived -n -f