命令记不住

登陆

keepalived 文件配置

keepalived文件配置

1.cat /etc/keepalived/keepalived.conf

global_defs {
   router_id xxx-name-1
   vrrp_skip_check_adv_addr
   vrrp_garp_interval 0
   vrrp_gna_interval 0
   vrrp_iptables
   script_user root
   enable_script_security
}

vrrp_script check_port {
    script "/etc/keepalived/check.sh"
    interval 5
}

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass mininglamp
    }
    virtual_ipaddress {
        xxxxxxxx/24 dev eth0 label eth0:1
    }
    track_script {
        check_port
    }
    notify_master "/etc/keepalived/notify.sh master"
    notify_backup "/etc/keepalived/notify.sh backup"
}

2.cat /etc/keepalived/check.sh

#!/bin/bash

ssh_count=`netstat -ntlp |grep sshd |wc -l`

if [ "$ssh_count" -gt 0 ]; then
    exit 0
else
    systemctl stop keepalived
    exit 1
fi

3.cat /etc/keepalived/notify.sh

#!/bin/bash
state=$1
h="`hostname`"


curl 'https://api.xxxxxx.com/xxxxxx' \
   -H 'Content-Type: application/json' \
   -d "
   {
        \"msgtype\": \"text\",
        \"text\": {
            \"content\": \"$h change state to $state\"
        }
   }"
推荐阅读