码迷,mamicode.com
首页 > 其他好文 > 详细

keepalived

时间:2020-12-09 12:31:15      阅读:14      评论:0      收藏:0      [点我收藏+]

标签:float   val   本机   找不到   shu   组播   track   security   lob   

  

keepalived配置文件

! Configuration File for keepalived

global_defs {
   notification_email {
     root@localhost
   }
   notification_email_from root@localhost
   smtp_server localhost
   smtp_connect_timeout 30
   router_id LVS_DEVEL
   vrrp_skip_check_adv_addr
   #vrrp_strict  # 严格遵守VRRP协议
   vrrp_garp_interval 0
   vrrp_gna_interval 0
   script_user root
   enable_script_security
}


vrrp_script check_script {
    script "/opt/nginx_check.sh"  # 不能使用 ‘‘ 否则找不到脚本
    interval 2
    weight -20
    user root
}

vrrp_instance vi_1 {
    state MASTER  # BACKUP
    interface ens33  # 绑定网卡
    virtual_router_id 55  #VRID
    priority 100
    mcast_src_ip 192.168.8.9  # 本机 IP 地址
    advert_int 1  # 组播信息发送间隔,两个节点设置必须一样
    #nopreempt
    authentication {
        auth_type PASS
        auth_pass 1111
    }

    virtual_ipaddress {
        192.168.8.200
    }

    track_script {
        check_script
    }

    notify_master "/opt/notify.sh master"
    notify_backup "/opt/notify.sh backup"
    notify_fault "/opt/notify.sh fault"
}

 

检查脚本

#!/bin/bash

if [[ `ps -C nginx --no-header | wc --lines` -eq 0 ]];then
    systemctl restart nginx
    echo -e \e[7m nginx restarting\e[0m
    sleep 1
    if [[ `ps -C nginx --no-header | wc --lines` -eq 0 ]];then
        systemctl stop keepalived
        echo -e \e[7m keepalived shutdown\e[0m
    fi
fi

 

发送邮件脚本

#!/bin/env bash

recipient=root@localhost
vip=192.168.8.200

function notify() {
    local subject="$(hostname) is $1,vip($vip) floating"
    local body="$(date +‘%F %T‘): vrrp transition, $(hostname) changed to $1"
    echo "$body" | mailx -s "$subject" $recipient
}

case $1 in
master)
    notify master
    ;;
backup)
    notify backup
    ;;
fault)
    notify fault
    ;;
*)
    echo "Usage: $(basename $0) {master|backup|fault}"
    exit 5
    ;;
esac

 

脚本权限必须为744

 

Keepalived - 随笔分类 - Linux-1874 - 博客园 (cnblogs.com)

keepalived

标签:float   val   本机   找不到   shu   组播   track   security   lob   

原文地址:https://www.cnblogs.com/dissipate/p/14089944.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!