测试多台服务器 使用nginx集群,宕机

主要解决问题:

多台服务器进行集群部署,然后当其中一台服务器出现问题时,nginx的upstream流的处理效果!

upstream deerChain{
  server 192.168.0.161:9527 fail_timeout=1s max_fails=1 weight=1;
  server 192.168.0.97:9527 fail_timeout=1s max_fails=1 weight=1;
}

//上述的测试,出现一个问题,并不是立即生效的,而且差不多5秒之后,不在访问宕机的服务器;

要想更加准确的监测,需要下载安装一个第三方的插件

 

以下是在 Linux 系统上安装 Nginx 以及 ngx_http_upstream_check_module 的步骤:
  1. 下载 Nginx 源代码和 ngx_http_upstream_check_module 模块的源代码:
    wget http://nginx.org/download/nginx-<version>.tar.gz
    wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/master.zip
    将 <version> 替换为您想要安装的 Nginx 版本号。
    1. 解压 Nginx 源代码和 ngx_http_upstream_check_module
      tar zxvf nginx-<version>.tar.gz
      unzip master.zip
      3、编译 Nginx 并添加 ngx_http_upstream_check_module
       
      cd nginx-<version>
      ./configure --add-module=../nginx_upstream_check_module-master
      make
      sudo make install
       
      这将编译并安装 Nginx,并将 ngx_http_upstream_check_module 集成到 Nginx 中。
      1. 配置 Nginx 使用健康检查模块。在 Nginx 配置文件中,您可以添加如下配置:

         

        http {
        ...
        upstream backend {
        server backend1.example.com;
        server backend2.example.com;
        # check interval=30000 rise=2 fall=5 timeout=1000;

         


        }
        ...
        }

posted @ 2024-06-05 14:27  文刀水告  阅读(4)  评论(0编辑  收藏  举报