• 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
  • 相关阅读:
    JUnit5依赖注入与测试接口
    Python如何设计面向对象的类(下)
    JUnit5参数化测试的几种方式
    JUnit5的条件测试、嵌套测试、重复测试
    熬夜肝了一份 C++/Linux 开发学习路线
    适合普通大学生的 Java 后端开发学习路线
    二本,拿腾讯,阿里 offer 了
    适合普通大学生的前端学习路线
    41道计算机网络高频面试题(附带答案)
    在Rancher中修改K8S服务参数的万金油法则
  • 原文地址:https://www.cnblogs.com/happydreamzjl/p/10986237.html
Copyright © 2020-2023  润新知