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

实战案例: 实现 VIP高可用

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

运维派隶属马哥教育旗下专业运维社区,是国内成立最早的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;
    }
    server {
        listen 80;
        location /{
            proxy_pass http://websrvs/;
        }
    }
}

#在两个节点都配置实现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.0.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
    }
}

[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 

本文链接:https://www.yunweipai.com/35391.html

实战案例: 实现 VIP高可用

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

网友评论comments

发表回复

您的电子邮箱地址不会被公开。

暂无评论

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