---
title: "nginx安装健康检查模块nginx_upstream_check_module"
author: "fuhuijun"
date: "2016-08-19T12:08:10Z"
tags: []
categories: ["企业架构"]
slug: "nginx-nginx-upstream-check-module"
draft: false
lastmod: "2016-08-19T16:46:52Z"
id: 2318924
url: "https://fuhuijun.iteye.com/blog/2318924"
---

随着业务增长，nginx上负载均衡器的后端节点部署越来越多，需要对后端节点的运行状态进行监控，故引入阿里的健康检测模块nginx\_upstream\_check\_module，通过它可以用来检测后端 realserver 的健康状态。

 

一、下载

     1、nginx

           [http://nginx.org/download/nginx-1.9.2.tar.gz](http://nginx.org/download/nginx-1.9.2.tar.gz)

     2、nginx\_upstream\_check\_module

           [http://github.com/yaoweibin/nginx\_upstream\_check\_module](http://github.com/yaoweibin/nginx_upstream_check_module)

 

 二、安装配置

    1、文件列表信息

```
[root@iZ233438q9fZ upload]# ll
drwxr-xr-x 6 ftpuser ftp       4096 Aug 19 10:04 nginx_upstream_check_module
drwxr-xr-x 8    1001 1001      4096 Jun 16  2015 nginx-1.9.2.tar.gz
```

 

    2、解压

```
[root@iZ233438q9fZ upload]# tar -zxvf nginx-1.9.2.tar.gz
[root@iZ233438q9fZ upload]# cd nginx-1.9.2 
```

 

    3、nginx补丁安装

```
[root@iZ233438q9fZ nginx-1.9.2]# patch -p0 < /var/ftp/upload/nginx_upstream_check_module/check_1.9.2+.patch
patching file src/http/modules/ngx_http_upstream_hash_module.c
patching file src/http/modules/ngx_http_upstream_ip_hash_module.c
patching file src/http/modules/ngx_http_upstream_least_conn_module.c
patching file src/http/ngx_http_upstream_round_robin.c
patching file src/http/ngx_http_upstream_round_robin.h
```

   

 

    4、编译配置

```
[root@iZ233438q9fZ nginx-1.9.2]# ./configure --add-module=/var/ftp/upload/nginx_upstream_check_module --prefix=/usr/local/server/nginx 
[root@iZ233438q9fZ nginx-1.9.2]# make && make install
```

 

 三、nginx.conf健康检查配置样例

![](http://dl2.iteye.com/upload/attachment/0119/4636/38d37a19-f1e4-3c1f-9277-9214becd0ea7.png)  
   
   
参数说明：

\- check\_status：\[html|csv|json]，默认html

\- check\_http\_send：指定检测的http访问地址，默认/

\- type：\[tcp|http|ssl\_hello|mysql|ajp]，默认tcp

\- interval：向后端发送的健康检查包的间隔，单位（毫秒）

\- fall(fall\_count): 如果连续失败次数达到fall\_count，服务器就被认为是down。

\- rise(rise\_count): 如果连续成功次数达到rise\_count，服务器就被认为是up。

\- timeout: 后端健康请求的超时时间。

 

PS：如果一直显示失败，请检查项目根目录中是否有index.jsp或index.html