我的测试环境
contos:6.7
nginx:1.63
check_module 简介
● 简介: 是由 淘宝技术团队开发的一个 Tengine(nginx 的分支) 的模块,Tengine 自带这个模块, nginx的单独安装模块。
● 作用: 用于提供主动式后端服务器健康检查。通过它可以检测后端 realserver 的健康状态,如果后端 realserver 不可用,则所有的请求就不会转发到该节点上
● 详情:http://tengine.taobao.org/
添加check模块
● 查看当前 nginx 版本
● 下载新模块 nginx_upstream_check_module && 解压
● 进入当前nginx 的源文件, 用 patch 方式打补丁
● 编译 ./configure
● make 生成编译后的 nginx
● 替换现有版本的nginx执行文件
● 检查nginx是否正常
● 配置 nginx 健康检查
● 客户端demo测试
详细步骤
1.我所有的软件源文件都在这个目录下
cd /home/oldboy/tools/
/application/nginx/sbin/nginx -V
2.下载新模块, 解压
wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/master.zip
unzip nginx_upstream_check_module-master.zip
3.进入 nginx 目录, 并用 patch 命令 对源文件打补丁
cd nginx-1.6.3
patch -p1 < ../nginx_upstream_check_module-master/check_1.5.12+.patch
4. 编译 红色是现有模块 蓝色是添加模块
./configure --user=nginx --group=nginx --prefix=/application/nginx-1.6.3/ --with-http_stub_status_module --with-http_ssl_module --add-module=/home/oldboy/tools/nginx-upstream-fair-master --add-module=/home/oldboy/tools/nginx_upstream_hash-master --add-module=../nginx_upstream_check_module-master/
>现有的模块 -user=nginx --group=nginx --prefix=/application/nginx-1.6.3/ --with-http_stub_status_module --with-http_ssl_module --add-module=/home/oldboy/tools/nginx-upstream-fair-master --add-module=/home/oldboy/tools/nginx_upstream_hash-master
> 新加的模块 --add-module=../nginx_upstream_check_module-master/
5. 编译,生成的nginx执行文件
make
6. 替换现有版本的nginx执行文件
mv /application/nginx/sbin/nginx{,.ori}
cp ./objs/nginx /application/nginx/sbin/
7. 检查配置是否正常, 查看nginx现在的模块
/application/nginx/sbin/nginx -t
/application/nginx/sbin/nginx -V
8. nginx 配置 健康检查
节点服务器: 2台
对 www_server_pools 这个负载均衡条目下的所有节点(2个) ,
每隔3秒检测一次,
请求3次正常则标记 realserver 状态为 up,
如果检测 5 次都失败, 则标记 realserver 状态为 down,
超时时间为 1 秒,
检查的协议为 http
upstream www_server_pools {
server 192.168.190.131:80 weight=1;
server 192.168.190.132:80 weight=1;
check interval=3000 rise=3 fall=5 timeout=1000 type=http;
}
#blog
server {
listen 80;
server_name www.blog.com;
location / {
proxy_pass http://www_server_pools;
include proxy.conf;
}
location /status {
check_status;
access_log off;
}
}
我是重点: 配置完成, nginx 必须重启, 不能重新加载
path/sbin/nginx -s stop
path/sbiun/nginx
客户端查看
● 配置2个节点服务器都正常图
● 关闭一个节点服务器图
● 开启关闭的节点服务器图
配置2个节点服务器都正常图配置2个节点服务器都正常图

第一个 down 掉, 5次失败后,标记为down,不在往这台服务器转发关闭一个节点服务器

重启第一个 节点服务器后, 3次检测通过后的截图

命令打包
cd /home/oldboy/tools/
/application/nginx/sbin/nginx -V
wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/master.zip
unzip nginx_upstream_check_module-master.zip
cd nginx-1.6.3
patch -p1 < ../nginx_upstream_check_module-master/check_1.5.12+.patch
./configure --user=nginx --group=nginx --prefix=/application/nginx-1.6.3/ --with-http_stub_status_module --with-http_ssl_module --add-module=/home/oldboy/tools/nginx-upstream-fair-master --add-module=/home/oldboy/tools/nginx_upstream_hash-master --add-module=../nginx_upstream_check_module-master/
make
mv /application/nginx/sbin/nginx{,.ori}
cp ./objs/nginx /application/nginx/sbin/
/application/nginx/sbin/nginx -t
/application/nginx/sbin/nginx -V
注:本文转自https://blog.csdn.net/chenshuai1993/article/details/83107769
Be First to Comment