Nginx负载均衡后端健康检查

栏目: 服务器 · Nginx · 发布时间: 7年前

内容简介:本次使用第三方模块nginx_upstream_check_module的,要使用这个第三方模块首先您需要进行下载,然后通过patch命令将补丁打入您原有的Nginx源码中,并且重新进行编译安装。下载nginx_upstream_check_module模块wget https://codeload.github.com/yaoweibin/nginx_upstream_check_module/zip/master

本次使用第三方模块nginx_upstream_check_module的,要使用这个第三方模块首先您需要进行下载,然后通过patch命令将补丁打入您原有的Nginx源码中,并且重新进行编译安装。

下载nginx_upstream_check_module模块

wget https://codeload.github.com/yaoweibin/nginx_upstream_check_module/zip/master

解压

unzip master

Nginx负载均衡后端健康检查

解压后的Nginx和nginx_upstream_check_module-master在同一目录下

Nginx负载均衡后端健康检查

将补丁打入源码(没有patch命令使用yum -y install patch安装)

cd nginx-1.6.3

patch -p1 < ../nginx_upstream_check_module-master/check_1.5.12+.patch

出现以下代表成功(根据nginx版本选择不同的check)

Nginx负载均衡后端健康检查

编译安装nginx

./configure --prefix=/usr/local/nginx --add-module=../nginx_upstream_check_module-master --with-http_stub_status_module

make && make install

通过以上的步骤,第三方的nginx_upstream_check_module模块就在Nginx中准备好了。接下来我们讲解一下如何使用这个模块。首先看一下upstream的配置信息

interval:必要参数,检查请求的间隔时间。

fall:当检查失败次数超过了fall,这个服务节点就变成down状态。

rise:当检查成功的次数超过了rise,这个服务节点又会变成up状态。

timeout:请求超时时间,超过等待时间后,这次检查就算失败。

default_down:后端服务器的初始状态。默认情况下,检查功能在Nginx启动的时候将会把所有后端节点的状态置为down,检查成功后,在置为up。

type:这是检查通信的协议类型,默认为http。以上类型是检查功能所支持的所有协议类型。

一个完整的nginx配置信息如下nginx.conf

worker_processes  4;

error_log  logs/error.log;

events {

worker_connections  10240;

}

http {

include      mime.types;

default_type  application/octet-stream;

sendfile        on;

keepalive_timeout  65;

upstream  ekp  { 

server  10.1.1.131:8080;

server  10.1.1.132:8080;   

server  10.1.1.135:8080;   

check interval=3000 rise=2 fall=5;

check_keepalive_requests 100;

check_http_send "HEAD / HTTP/1.1\r\nConnection: keep-alive\r\n\r\n";

check_http_expect_alive http_2xx http_3xx;

server {

listen      80;

server_name  www.test.com;

access_log  /usr/local/nginx/logs/access.log;

location / {

root  ekp;

index  index.html index.htm index.jsp;

proxy_pass        http://ekp;   

proxy_set_header  Host            $host;

proxy_set_header  X-Real-IP        $remote_addr;

proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;

client_max_body_size    200m;

proxy_connect_timeout      10;

proxy_read_timeout          300;

proxy_send_timeout          300;

}

location /nstatus {

check_status;

access_log on;

}

}

}

PS:这里配置按照参考文档加timeout=1000 type=http 否则无法负载均衡

访问测试 http://ip/nstatus

Nginx负载均衡后端健康检查

Linux公社的RSS地址https://www.linuxidc.com/rssFeed.aspx

本文永久更新链接地址: https://www.linuxidc.com/Linux/2019-04/158352.htm


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Learn Python 3 the Hard Way

Learn Python 3 the Hard Way

Zed A. Shaw / Addison / 2017-7-7 / USD 30.74

You Will Learn Python 3! Zed Shaw has perfected the world’s best system for learning Python 3. Follow it and you will succeed—just like the millions of beginners Zed has taught to date! You bring t......一起来看看 《Learn Python 3 the Hard Way》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具