ToB企服应用市场:ToB评测及商务社交产业平台
标题:
keepalived踩坑记载
[打印本页]
作者:
吴旭华
时间:
前天 18:50
标题:
keepalived踩坑记载
环境
操作系统: CentOS7.9
keepalived: 1.35
master设置
cat > /etc/keepalived/keepalived.conf<<'EOF'
global_defs {
router_id Nginx1
}
vrrp_script chk_nginx {
script "/etc/keepalived/check_nginx.sh"
interval 3
weight -3
}
vrrp_instance VI_1 {
state MASTER
interface enp0s8
virtual_router_id 101
priority 120
advert_int 2
nopreempt
authentication {
auth_type PASS
auth_pass 12333
}
virtual_ipaddress {
192.168.240.6
}
track_script {
chk_nginx
}
}
EOF
复制代码
cat > /etc/keepalived/check_nginx.sh<<'EOF'
B=$(pgrep nginx | wc -l)
if [[ $B -eq 0 ]]; then
/usr/bin/systemctl stop keepalived
exit 1
fi
exit 0
EOF
复制代码
backup设置
cat > /etc/keepalived/keepalived.conf<<'EOF'
global_defs {
router_id Nginx2
}
vrrp_script chk_nginx {
script "/etc/keepalived/check_nginx.sh"
interval 3
weight -3
}
vrrp_instance VI_1 {
state BACKUP
interface enp0s8
virtual_router_id 101
priority 119
advert_int 2
nopreempt
authentication {
auth_type PASS
auth_pass 12333
}
virtual_ipaddress {
192.168.240.6
}
track_script {
chk_nginx
}
}
EOF
复制代码
cat > /etc/keepalived/check_nginx.sh<<'EOF'
B=$(pgrep nginx | wc -l)
if [[ $B -eq 0 ]]; then
/usr/bin/systemctl stop keepalived
exit 1
fi
exit 0
EOF
复制代码
说明
坑点
检测脚本/etc/keepalived/check_nginx.sh第一行肯定不要写#!/bin/bash
检测脚本/etc/keepalived/check_nginx.sh的退出状态码不起作用,以是只能/usr/bin/systemctl stop keepalived
排错参考文档
【Linux】详解shell中source、sh、bash、./执行脚本的区别
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/)
Powered by Discuz! X3.4