keepAlived主备及双主

nginx用默认配置即可

1、主备配置

1、主keepAlived配置

vrrp_instance VI_1 {
    state MASTER   #主备区分
    interface eth0
    virtual_router_id 51  #主备一致
    priority 100   #主备区分
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.244.200
    }
    track_script {
        chk_nginx
    }
}

2、备keepAlived配置

vrrp_instance VI_1 {
    state BACKUP  #主备区分
    interface eth0
    virtual_router_id 51   #主备一致
    priority 50     #主备区分
    advert_int 1

    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.244.200
    }
}

2、互为主备

1、第一台keepAlived配置

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.244.200
    }
}

vrrp_instance VI_2 {
    state BACKUP
    interface eth0
    virtual_router_id 52
    priority 50
    advert_int 1

    authentication {
        auth_type PASS
        auth_pass 2222
    }
    virtual_ipaddress {
        192.168.244.201
    }
}

2、第二台keepAlived配置

vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 50
    advert_int 1

    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.244.200
    }
}
vrrp_instance VI_2 {
    state MASTER
    interface eth0
    virtual_router_id 52
    priority 100
    advert_int 1

    authentication {
        auth_type PASS
        auth_pass 2222
    }
    virtual_ipaddress {
        192.168.244.201
    }
}

 

3、检测nginx,实现主备高可用

1、第一台keepAlived配置

vrrp_script chk_nginx {
    script "/zjl/program/nginx/conf/checkNginxAlived.sh"
    interval 2
    weight 2
}

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.244.200
    }
    track_script {
        chk_nginx
    }
}

vrrp_instance VI_2 {
    state BACKUP
    interface eth0
    virtual_router_id 52
    priority 50
    advert_int 1

    authentication {
        auth_type PASS
        auth_pass 2222
    }
    virtual_ipaddress {
        192.168.244.201
    }
    track_script {
        chk_nginx
    }
}

2、第二台keepAlived配置

vrrp_script chk_nginx {
    script "/zjl/program/nginx/conf/checkNginxAlived.sh"
    interval 2
    weight 2
}
vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 51
    priority 50
    advert_int 1

    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.244.200
    }
    track_script {
        chk_nginx
    }
}
vrrp_instance VI_2 {
    state MASTER
    interface eth0
    virtual_router_id 52
    priority 100
    advert_int 1

    authentication {
        auth_type PASS
        auth_pass 2222
    }
    virtual_ipaddress {
        192.168.244.201
    }
    track_script {
        chk_nginx
    }
}

3、监测脚本

#!/bin/bash
psnginx=`ps -C nginx --no-heading|wc -l`
if [ $psnginx == 0 ] ; then
    echo "nginx服务已关闭,尝试重新启动..."
    /zjl/commond/nginxbegin-start.sh
    sleep 3
    if [ `ps -C nginx --no-heading|wc -l` -eq 0 ] ; then
        echo "nginx尝试启动失败关闭keepAlived"
        killall keepalived
    else
        echo "nginx重新启动成功"
    fi
else
    echo "nginx服务正常..."
fi

转载于:https://www.cnblogs.com/happydreamzjl/p/10986237.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值