天天看點

keepalived檢測腳本及注意事項

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

    sleep 3

    if [ `ps -C nginx --no-header | wc -l` ]

    then

    killall 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

    }

    }

轉載于:https://www.cnblogs.com/mmdln/p/8988977.html