首页 > 其他 > 详细

Nginx+keepalived双主架构实战

时间:2021-08-03 18:53:50      阅读:27      评论:0      收藏:0      [点我收藏+]

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

 

Nginx+keepalived双主架构实战

原文:https://www.cnblogs.com/sunjinchao/p/15094865.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!