zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    解决“iOS 7 app自动更新,无法在app中向用户展示更新内容”问题
    ios 数组排序
    六年谈游戏工作室与游戏开发过程简介(转)
    mysql按位的索引判断值是否为1
    mysql按位的索引判断位的值
    git bash here右键菜单
    将VSCode添加到右键
    给vscode添加右键打开功能
    winrar压缩过滤文件及文件夹
    编译wxWidgets
  • 原文地址:https://www.cnblogs.com/sunjinchao/p/15094865.html
Copyright © 2011-2022 走看看