---
title: "Tengine主动监测后端服务器状态"
id: "232"
type: "post"
slug: "tengine%e4%b8%bb%e5%8a%a8%e7%9b%91%e6%b5%8b%e5%90%8e%e7%ab%af%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%8a%b6%e6%80%81"
published_at: "2019-10-10T11:20:32+00:00"
modified_at: "2019-10-10T11:20:32+00:00"
url: "https://www.hitsword.org/2019/232.html"
markdown_url: "https://www.hitsword.org/2019/232.md"
excerpt: "Tengine附带了nginx_upstream_check_module模块，用于主动监测后端服务器状态进行 […]"
taxonomy_category:
  - "Nginx"
taxonomy_post_tag:
  - "Nginx"
  - "Tengine"
  - "反向代理"
  - "后端"
---

# Tengine主动监测后端服务器状态

Tengine附带了nginx_upstream_check_module模块，用于主动监测后端服务器状态进行宕机切换。  
 先编译nginx时带上参数

```
--add-module=modules/ngx_http_upstream_check_module
```

  
 官方文档的编译参数有误，最新版编译的时候会出错：  
```
./configure --with-http_upstream_check_module
```

  
 后端配置代码如下,具体参数参考[官方文档](https://www.hitsword.org/goto/aHR0cDovL3RlbmdpbmUudGFvYmFvLm9yZy9kb2N1bWVudF9jbi9odHRwX3Vwc3RyZWFtX2NoZWNrX2NuLmh0bWw).  
```
upstream backend {
        server   192.168.99.2:8888;
        server   192.168.99.3:8888;
        server   192.168.99.4:8888;
        check interval=10000 rise=2 fall=3 timeout=1000 default_down=true type=http;
        check_http_send "GET / HTTP/1.0\r\n HOST test.com\r\n\r\n";
        check_http_expect_alive http_2xx http_3xx http_4xx;
}
```
