高并发系列---【keepalived+nginx实现双主热备】

1.前提:先实现双机主备,具体参考https://www.cnblogs.com/hujunwei/p/15773502.html

2.修改nginx-master的配置文件,复制VI_1的部分,并着重修改紫色部分

! Configuration File for keepalived

global_defs {
   router_id nginx1
}

vrrp_script check_status {
   script "/etc/keepalived/check_nginx_status.sh"
   interval 2
   weight 10
}

vrrp_instance VI_1 {
    state MASTER
    interface ens33
    virtual_router_id 61
    priority 100
    #主备之间同步检查的时间间隔,默认1s
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }

    virtual_ipaddress {
        192.168.26.102
    }
    track_script {
        check_status
    }
}
vrrp_instance VI_2 {
    state BACKUP
    interface ens33
    virtual_router_id 62
    priority 50
    #主备之间同步检查的时间间隔,默认1s
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }

    virtual_ipaddress {
        192.168.26.103
    }
    track_script {
        check_status
    }
}

3.修改完成后,进行重启

systemctl restart keepalived
#查看ip,看ens33网卡上是否绑一个vip192.168.26.102,绑一个正常
ip addr

4.修改nginx-backup,复制VI_1的部分,并着重修改紫色部分

! Configuration File for keepalived

global_defs {
   router_id nginx2
}
vrrp_script check_nginx_status {
        script "/etc/keepalived/check_nginx_status.sh"
        # 每隔2秒运行一下上一行脚本
        interval 2
        # 如果脚本运行成功,则升级权重+10
        weight 10
}

vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    virtual_router_id 61
    priority 50
    #主备之间同步检查的时间间隔,默认1s
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
   track_script {
     #追踪nginx脚本
     check_nginx_status
   }
    virtual_ipaddress {
        192.168.26.102
    }
}
vrrp_instance VI_2 {
    state MASTER
    interface ens33
    virtual_router_id 62
    priority 100
    #主备之间同步检查的时间间隔,默认1s
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
   track_script {
     #追踪nginx脚本
     check_nginx_status
   }
    virtual_ipaddress {
        192.168.26.103
    }
}

5.修改完成后,进行重启

systemctl restart keepalived
#查看ip,看ens33网卡上是否绑一个vip192.168.26.103,绑一个正常 
ip addr

 

上一篇:记录一次面试失败,但是后知后觉又非常简单的面试题:如何校验字符串中‘()’的合法性


下一篇:Python QT由登陆界面到主界面