首页 Keepalived教程实战案例: 实现双主模式Nginx反向代理的高可用

实战案例: 实现单主模式的Nginx反向代理的高可用

实战案例:实现HAProxy高可用

运维派隶属马哥教育旗下专业运维社区,是国内成立最早的IT运维技术社区,欢迎关注公众号:yunweipai
领取学习更多免费Linux云计算、Python、Docker、K8s教程关注公众号:马哥linux运维

实战案例:实现双主模式Nginx反向代理的高可用
#在两个节点都配置nginx反向代理
[root@ka1-centos8 ~]vim /etc/nginx/nginx.conf
http {
    upstream websrvs {
        server 10.0.0.7:80 weight=1;
        server 10.0.0.17:80 weight-1;
    }
    upstream websrvs2 {
        server 10.0.0.27:80 weight=1;
        server 10.0.0.37:80 weight-1;
    }

    server {
        listen 80;
        server_name www.a.com;
        location /{
            proxy_pass http://webservs/;
        }
    }
    server {
        listen 80;
        server_name www.b.com;
        location /{
            proxy_pass http://webservs2/;
        }
    }

}

#在两个节点都配置实现双主模式的nginx反向代理高可用
[root@ka1-centos8 ~]#cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
    global_defs {
        notification_email {
        root@localhost
        }
    notification_email_from kaadmin@localhost
    smtp_server 127.0.0.1
    smtp_connect_timeout 30
    router_id ka1.magedu.org            #在另一个节点为ka2.magedu.org
    vrrp_mcast_group4 224.100.100.100
}
vrrp_script check_nginx {
    script "/etc/keepalived/check_nginx.sh"
    #script "/usr/bin/killall -0 nginx"
    interval 1
    weight -30
    fall 3
    rise 5
   timeout 2
}

vrrp_instance VI_1 {
    state MASTER                            #在另一个节点为BACKUP
    interface eth0
    virtual_router_id 66
    priority 100                            #在另一个节点为80
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 123456
    }
    virtual_ipaddress {
        10.0.0.10/24 dev eth0 label eth0:1
    }
    track_interface {
        eth0
    }
    notify_master "/etc/keepalived/notify.sh master"
    notify_backup "/etc/keepalived/notify.sh backup"
    notify_fault "/etc/keepalived/notify.sh fault"
    track_script {
        chk_nginx
    }
}

vrrp_instance VI_2 {
    state BACKUP                        #在另一个节点为MASTER
    interface eth0
    virtual_router_id 88
    priority 80                         #在另一个节点为100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 123456
    }
    virtual_ipaddress {
        10.0.0.20/24 dev eth0 label eth0:2
    }
    track_interface {
        eth0
    }
    notify_master "/etc/keepalived/notify.sh master"
    notify_backup "/etc/keepalived/notify.sh backup"
    notify_fault "/etc/keepalived/notify.sh fault"
    track_script {
        chk_nginx
    }
}
[root@ka1-centos8 ~]# yum install psmisc -y
[root@ka1-centos8 ~]# cat /etc/keepalived/check_nginx.sh
#!/bin/bash
/usr/bin/killall -0 nginx
[root@ka1-centos8 ~]# chmod a+x /etc/keepalived/check_nginx.sh 

本文链接:http://www.yunweipai.com/35393.html

实战案例: 实现单主模式的Nginx反向代理的高可用

实战案例:实现HAProxy高可用

网友评论comments

发表评论

电子邮件地址不会被公开。

暂无评论

Copyright © 2012-2021 YUNWEIPAI.COM - 运维派 京ICP备16064699号-6
扫二维码
扫二维码
返回顶部