ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

Linux - Keepalived + Nginx(双主)

2021-08-29 19:33:19  阅读:194  来源: 互联网

标签:10.0 noise nginx Keepalived Nginx org root 双主 eth0


客户端 cli.noise.org : 10.0.0.7 - cli.noise.org

keepalived1  + nginx - 10.0.0.34 - ka1.noise.org

keepalived2  + ngixn - 10.0.0.22 - ka2.noise.org

后台web服务器1: 10.0.0.35 - rs1.noise.org

后台web服务器2: 10.0.0.36 - rs2.noise.org

 

==========================================================

ka1.noise.org - keepalived.conf

  
global_defs {
   notification_email {
     root@localhost
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id ka1.noise.org       -》 唯一ID
   vrrp_mcast_group 224.0.100.100    -》 多播地址
}


vrrp_script check_nginx {
    script "/data/check_nginx.sh"  -》 检查脚本,nginx服务挂掉,自动重启
    interval 1
    weight -30
    fall 3
    rise 5
    timeout 2
}


vrrp_instance VI_1 {      -》 集群VI_1, ka1为主节点
    state MASTER        -》 节点状态
    interface eth0
    virtual_router_id 66    -》 唯一集群ID 
    #nopreempt
    priority 100        -》 节点优先级
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 123456
    }
    virtual_ipaddress {
        10.0.0.20/24 dev eth0 label eth0:1  -》 集群漂移VIP
    }

    track_interface {
        eth0
    }

    track_script {
        check_nginx
    }
}

vrrp_instance VI_2 {  -》 集群VI_2
    state BACKUP      -> 当前节点作为子节点
    interface eth0
    virtual_router_id 88  -》 唯一集群ID
    #nopreempt
    priority 80      -》 节点优先级
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 123456
    }
    virtual_ipaddress {
        10.0.0.30/24 dev eth0 label eth0:1  -》 集群VIP
    }

    track_interface {
        eth0
    }

    track_script {
        check_nginx
    }
}

 

===============================================

此为ka2.noise.org的配置,部分配置与ka1.noise.org相反

! Configuration File for keepalived global_defs { notification_email { root@localhost } notification_email_from Alexandre.Cassen@firewall.loc smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id ka2.noise.org vrrp_mcast_group 224.0.100.100 } vrrp_script check_nginx { script "/data/check_nginx.sh" interval 1 weight -30 fall 3 rise 5 timeout 2 } vrrp_instance VI_1 { state BACKUP interface eth0 virtual_router_id 66 #nopreempt priority 80 advert_int 1 authentication { auth_type PASS auth_pass 123456 } virtual_ipaddress { 10.0.0.20/24 dev eth0 label eth0:1 } track_interface { eth0 } track_script { check_nginx } } vrrp_instance VI_2 { state MASTER interface eth0 virtual_router_id 88 #nopreempt priority 100 advert_int 1 authentication { auth_type PASS auth_pass 123456 } virtual_ipaddress { 10.0.0.30/24 dev eth0 label eth0:1 } track_interface { eth0 } track_script { check_nginx } }

===================================

两个ka节点nginx配置一样,负责反向代理

http { upstream websrvs { server 10.0.0.35:80 weight=1; server 10.0.0.36:80 weight=1; } server { listen 80; location / { proxy_pass http://websrvs/; } } }

==================================

[19:07:33 root@ka1 ~]#cat /data/check_nginx.sh 
#!/bin/bash
#
#**************************************************************************************
#Author:                                   Noise Lys
#QQ:                                       578110218
#Date:                                     2021-08-29
#Filename:                                 /data/check_nginx.sh
#URL:                                      https://www.cnblogs.com/noise/
#Description:                              The test script
#Copyright (C):                            2021 All rights reserved
#**************************************************************************************
/usr/bin/killall -0 nginx || systemctl restart nginx 

=================================

开始检查结果,访问10.0.0.20即集群VI_1的VIP时,主节点ka1.noise.org工作,ka2.noise.org不工作
但是访问10.0.0.30即集群VI_2的VIP时,主节点ka2.noise.org工作,ka1.noise.org不工作
[19:00:48 root@cli ~]#curl 10.0.0.20
rs1.noise.org
[19:00:49 root@cli ~]#curl 10.0.0.20
rs2.noise.org
[19:00:49 root@cli ~]#curl 10.0.0.20
rs1.noise.org
[19:00:49 root@cli ~]#curl 10.0.0.20
rs2.noise.org
[19:00:50 root@cli ~]#curl 10.0.0.20
rs1.noise.org
[19:00:50 root@cli ~]#curl 10.0.0.30
rs1.noise.org
[19:00:52 root@cli ~]#curl 10.0.0.30
rs2.noise.org
[19:00:53 root@cli ~]#curl 10.0.0.30
rs1.noise.org
[19:00:53 root@cli ~]#curl 10.0.0.30
rs2.noise.org

 

标签:10.0,noise,nginx,Keepalived,Nginx,org,root,双主,eth0
来源: https://www.cnblogs.com/noise/p/15203354.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有