Keepalived 常用配置+检测脚本

1、在与其他服务一起运行下做高可用时,比如NGINX,需要在NGINX断开的时候先尝试启动一次NGINX,如果启动不行,漂移keepalived到备机,所以需要在配置下加检测脚本。

2、配置:keepalived.conf

! Configuration File for keepalived

global_defs {

  notification_email {

      abc@163.com

}    notification_email_from abc@163.com

    smtp_server 127.0.0.1    smtp_connect_timeout 30    router_id LVS_DEVEL

}

vrrp_script chk_nginx {

    script  "/data/sh/check_nginx.sh"

    interval 2

    weight 20

} vrrp_instance VI_1 {

    state BACKUP

    interface eth0

    lvs_sync_daemon_inteface eth0

    virtual_router_id 151

    priority 100

    advert_int 5

    nopreempt

    authentication {

        auth_typePASS

        auth_pass  1111

    }    virtual_ipaddress {

        192.168.2.129

  }    track_script {

    chk_nginx

    } 

}

3、检测脚本:chk_nginx.sh

#!/bin/bash    

if [ "$(ps -ef | grep "nginx: master process"| grep -v grep )" == "" ]    

then    

/usr/local/nginx/sbin/nginx    

sleep 5    

if [ "$(ps -ef | grep "nginx: master process"| grep -v grep )" == "" ]    

then    

killall keepalived    

fi    

fi   

4、配置参数详解:

global_defs模块:

notification_email 当切换的时候发送通知对象,一般不需要

notification_email_from    发件人,一般不需要

smtp_server        smtp服务地址,一般不需要

smtp_connect_timeout        smtp连接超时时间,一般不需要

router_id          运行keepalived的标识,一般为主机名

vrrp_script模块:

script              脚本路径

interval            检测时间间隔

weight              权重

vrrp_instance模块:

state 主机状态,包括MASTER和BACKUP

virtual_router 路由id,主备要一致

priority 优先级,值越高,主机状态就是MASTER

advert_int 检查间隔

nopreempt 不抢占

authentication 设置认证

auth_type 认证方式

auth_pass          认证密码

virtual_ipaddress 设置VIP

track_script 脚本监控,名称为vrrp_script设置


5、查看本机IP信息:ip addr list

img_ec17d6073e4e122050cbfb566c951bd9.png
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值