keepalived检测脚本的作用及注意事项:

  1. 默认每隔3秒钟执行一次检测脚本,检查nginx服务是否启动,如果没启动就把nginx服务启动起来,如果启动不成功,就把keepalived服务down掉,让漂浮到备keepalived上
  2. 检测脚本
    #!/bin/bash
    run=`ps -C nginx --no-header | wc -l`
    if [ $run -eq 0 ]
    then
    /usr/local/nginx/sbin/nginx -s stop
    /usr/local/nginx/sbin/nginx
    run=`ps -C nginx --no-header | wc -l`
    if [ $run -eq 0 ]
    then
    pkill keepalived
    fi
    fi
  3. 检测脚本一定要写在vrrp_instance的前面也就是上面,而且花括号一定要有空格,追踪trace_script要定在vip的后面,多少人栽在了这上面好多小时
  4. vrrp_script check_ng {
    script " /etc/keepalived/check_nginx.sh "
    interval 2
    }
    vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
    auth_type PASS
    auth_pass 1111
    }
    virtual_ipaddress {
    192.168.76.25/24
    }
    track_script {
    check_ng
    }
    }

发表评论

邮箱地址不会被公开。 必填项已用*标注