keepalived配置


一、基本信息

代理主机 01:192.168.198.99
代理主机 02:192.168.198.98
虚拟 IP:192.168.198.88
网卡:ens33

二、配置文件

1. /etc/hosts

192.168.198.99 proxy-1
192.168.198.98 proxy-2

2. /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {
   notification_email {
        [email protected].com
   }
   notification_email_from [email protected].com
   smtp_server 127.0.0.1
   router_id proxy-1
   vrrp_mcast_group4 224.4.4.4
}

vrrp_script chk_proxy {
    script "/etc/keepalived/proxy_check.sh"
    interval 2
    weight -2
}

vrrp_instance VI_1 {
    state BACKUP
    nopreempt
    interface ens33
    virtual_router_id 11
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }

    virtual_ipaddress {
        192.168.198.88/24 dev ens33 label ens33:1
    }

    track_script {
        chk_proxy
    }

}

3. /etc/keepalived/proxy_check.sh

#!/bin/bash
# === nginx prxy check script ===
netstat -nlpt | grep -w "80" &>> /dev/null

if [ $? -ne 0 ]
then
    systemctl stop keepalived
fi
    exit 0

文章作者: Truda
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 Truda !
评论
  目录