ToB企服应用市场:ToB评测及商务社交产业平台

标题: keepalived踩坑记载 [打印本页]

作者: 吴旭华    时间: 前天 18:50
标题: keepalived踩坑记载
环境

操作系统: CentOS7.9
keepalived: 1.35
master设置

  1. cat > /etc/keepalived/keepalived.conf<<'EOF'
  2. global_defs {
  3.     router_id Nginx1
  4. }
  5. vrrp_script chk_nginx {
  6.     script "/etc/keepalived/check_nginx.sh"
  7.     interval 3
  8.     weight -3
  9. }
  10. vrrp_instance VI_1 {
  11.     state MASTER
  12.     interface enp0s8
  13.     virtual_router_id 101
  14.     priority 120
  15.     advert_int 2
  16.     nopreempt
  17.     authentication {
  18.         auth_type PASS
  19.         auth_pass 12333
  20.     }
  21.     virtual_ipaddress {
  22.         192.168.240.6
  23.     }
  24.     track_script {
  25.       chk_nginx
  26.     }
  27. }
  28. EOF
复制代码
  1. cat > /etc/keepalived/check_nginx.sh<<'EOF'
  2. B=$(pgrep nginx | wc -l)
  3. if [[ $B -eq 0 ]]; then
  4.     /usr/bin/systemctl stop keepalived
  5.     exit 1
  6. fi
  7. exit 0
  8. EOF
复制代码
backup设置

  1. cat > /etc/keepalived/keepalived.conf<<'EOF'
  2. global_defs {
  3.     router_id Nginx2
  4. }
  5. vrrp_script chk_nginx {
  6.     script "/etc/keepalived/check_nginx.sh"
  7.     interval 3
  8.     weight -3
  9. }
  10. vrrp_instance VI_1 {
  11.     state BACKUP
  12.     interface enp0s8
  13.     virtual_router_id 101
  14.     priority 119
  15.     advert_int 2
  16.     nopreempt
  17.     authentication {
  18.         auth_type PASS
  19.         auth_pass 12333
  20.     }
  21.     virtual_ipaddress {
  22.         192.168.240.6
  23.     }
  24.     track_script {
  25.       chk_nginx
  26.     }
  27. }
  28. EOF
复制代码
  1. cat > /etc/keepalived/check_nginx.sh<<'EOF'
  2. B=$(pgrep nginx | wc -l)
  3. if [[ $B -eq 0 ]]; then
  4.     /usr/bin/systemctl stop keepalived
  5.     exit 1
  6. fi
  7. exit 0
  8. EOF
复制代码
说明


坑点

排错参考文档

【Linux】详解shell中source、sh、bash、./执行脚本的区别

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4