keepalived配置如下

! Configuration File for keepalived
global_defs {
    notification_email {
        root@localhost
    }
    notification_email_from root@localhost
    smtp_server 127.0.0.1
    smtp_connect_timeout 30
    router_id localhost001    # 主机名
    #vrrp_skip_check_adv_addr
    #vrrp_garp_interval 0
    #vrrp_gna_interval 0
}

vrrp_sync_group VG_1 {
    group {
        VI_1
    }
}

vrrp_script check_process {
    script /etc/keepalived/script/check_nginx.sh
    interval 5
    fall 2
}

vrrp_instance VI_1 {
    state BACKUP
    interface enp3s0          # 监控网络配置,注意是'enp3s0',使用ifconfig查看
    virtual_router_id 15
    priority 222
    advert_int 1
    track_interface {
        enp3s0                # 监控网络配置,注意是'enp3s0',使用ifconfig查看
    }
    track_script {
        check_process
    }
    authentication {
        auth_type PASS
        auth_pass 105901
    }
    virtual_ipaddress {
        28.105.90.15          # 虚拟vip
    }
    nopreempt
#        notify /etc/keepalived/script/sms_notify.sh
}

vi /etc/keepalived/script/check_nginx.sh

#!/bin/bash
count=`ps -ef|grep "nginx: master process" | grep -v grep | wc -l`
if [ $count -eq 0 ];then
    service nginx start
    sleep 3
    if [ `ps -ef|grep "nginx: master process" | grep -v grep | wc -l` -eq 0 ];then
        killall keepalived
    fi
fi

 

posted on 2022-12-30 15:54  圣上有喜  阅读(72)  评论(0编辑  收藏  举报