• Nginx+keepalived双主架构实战


    Nginx + Keepalived 如何更好的把2台服务器利用起来,可以借助Nginx + Keepalived 双主架构来实现,同时两台对外提供服务,拥有2个VIP地址,同时接收用户的请求。

     安装Nginx 与 Keepalived 安装方法不再赘述

    (1)master1 上的keepalived.conf 配置文件内容如下:

    ! Configuration File for keepalived
    
    global_defs {
       notification_email {
         acassen@firewall.loc
         failover@firewall.loc
         sysadmin@firewall.loc
       }
        notification_email_from Alexandre.Cassen@firewall.loc
        smtp_server 127.0.0.1
        smtp_connect_timeout 30
        router_id LVS_DEVEL
       }
    
     vrrp_script chk_nginx {
    
       script "/data/sh/check_nginx.sh"
       interval 2
       weight 2
    
     }
    
     # VIP1
    
     vrrp_instance VI_1 {
    
      state MASTER
      interface eth0
      lvs_sync_daemon_inteface eth0
      virtual_router_id 151
      priority 100
      adver_int 5
      nopreempt
      authentication {
    
          auth_type PASS
          auth_type 1111
      }
      virtual_ipaddress{
            192.168.33.188
        }
      track_script {
    
      chk_nginx
      }
    
    
     }
    
      # VIP1
    
     vrrp_instance VI_2 {
    
      state BACKUP
      interface eth0
      lvs_sync_daemon_inteface eth0
      virtual_router_id 152
      priority 90
      adver_int 5
      nopreempt
      authentication {
    
          auth_type PASS
          auth_type 2222
      }
      virtual_ipaddress{
            192.168.33.199
        }
      track_script {
    
      chk_nginx
      }
    
    
     }
    MASTER1

    (2)master2上的keepalived.conf配置文件内容如下:

    ! Configuration File for keepalived
    
    global_defs {
       notification_email {
         acassen@firewall.loc
         failover@firewall.loc
         sysadmin@firewall.loc
       }
        notification_email_from Alexandre.Cassen@firewall.loc
        smtp_server 127.0.0.1
        smtp_connect_timeout 30
        router_id LVS_DEVEL
       }
    
     vrrp_script chk_nginx {
    
       script "/data/sh/check_nginx.sh"
       interval 2
       weight 2
    
     }
    
     # VIP1
    
     vrrp_instance VI_1 {
    
      state MASTER
      interface eth0
      lvs_sync_daemon_inteface eth0
      virtual_router_id 151
      priority 90
      adver_int 5
      nopreempt
      authentication {
    
          auth_type PASS
          auth_type 1111
      }
      virtual_ipaddress{
            192.168.33.188
        }
      track_script {
    
      chk_nginx
      }
    
    
     }
    
      # VIP1
    
     vrrp_instance VI_2 {
    
      state BACKUP
      interface eth0
      lvs_sync_daemon_inteface eth0
      virtual_router_id 152
      priority 100
      adver_int 5
      nopreempt
      authentication {
    
          auth_type PASS
          auth_type 2222
      }
      virtual_ipaddress{
            192.168.33.199
        }
      track_script {
    
      chk_nginx
      }
    
    
     }
    MASTER2

    (3)两台Nginx服务器上配置 /data/sh/chechk_nginx.sh脚本内容如下:

    #!/bin/bash
    # auto check nginx process
    killall -0 nginx
    if [[ $? -ne 0 ]]; then
        /etc/init.d/keepalived stop
    fi
    人生苦短,我用Python
  • 相关阅读:
    Ajax缓存解决办法【转】
    【转】关于找工作的鸡零狗碎(续)
    科技爱好者周刊(第 167 期):广告拦截器太过分了
    科技爱好者周刊(第 166 期):视频学习胜过读书吗?
    GitHub镜像
    支付宝小程序环境判断
    怎么样给背景图加透明度
    JavaScript如何实现上拉加载,下拉刷新?
    什么是HTTP? HTTP 和 HTTPS 的区别?
    网页中的一键加QQ群、唤起QQ群聊天窗口
  • 原文地址:https://www.cnblogs.com/sunjinchao/p/15094865.html
Copyright © 2020-2023  润新知