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

keepAlived主备及双主

时间:2019-06-06 19:03:36      阅读:77      评论:0      收藏:0      [点我收藏+]

标签:rtu   begin   ati   code   主备   int   back   wc -l   监测   

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

keepAlived主备及双主

标签:rtu   begin   ati   code   主备   int   back   wc -l   监测   

原文地址:https://www.cnblogs.com/happydreamzjl/p/10986237.html

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