安装插件
下载
链接:https://pan.baidu.com/s/1iTPEmu_hCHYhDyaVDDTsVg?pwd=vaw8
提取码:vaw8
安装依赖
yum install pcre pcre-devel
yum -y install make gcc-c++ gcc
编译安装
$ nginx -V #此处省略了很多模块,只是为了看清而已
...
configure arguments: --prefix=/usr/local/nginx --add-module=../lua-nginx-module-0.10.8
$ cd /usr/local/src/nginx-1.12.2
#给nginx打补丁(根据nginx版本号选择补丁包),打补丁这步操作不可少,否则会出出"[error] 29841#0: *23 http upstream check module can not find any check server, make sure you've added the check servers," 错误
$ patch -p1 < /usr/local/nginx_upstream_check_module-master/check_1.12.1+.patch
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
Hunk #1 succeeded at 9 with fuzz 2.
Hunk #2 succeeded at 95 (offset 4 lines).
Hunk #3 succeeded at 159 (offset 4 lines).
Hunk #4 succeeded at 227 (offset 4 lines).
Hunk #5 succeeded at 339 (offset 4 lines).
Hunk #6 succeeded at 381 (offset 4 lines).
Hunk #7 succeeded at 443 (offset 4 lines).
Hunk #8 succeeded at 541 (offset -1 lines).
patching file src/http/ngx_http_upstream_round_robin.h
$ ./configure --prefix=/usr/local/nginx --add-module=/usr/local/nginx_upstream_check_module-master
....
$ make
$ make install
$ /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
$ /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
配置说明
upstream cluster {
server 192.168.20.12:80;
server 192.168.20.3:80; #未启动web服务,默认为down
check interval=3000 rise=2 fall=3 timeout=1000 type=http;
check_http_send "GET /index.html HTTP/1.0\r\n\r\n"; #获取后端资源,资源变动后,经历三次检查周期后立即将状态改为down
check_http_expect_alive http_2xx http_3xx ; #check_http_send 返回状态码,2xx和3xx为默认值。
}
server {
listen 80;
location / {
proxy_pass http://cluster;
}
location = /status {
check_status;
#allow xxx;
#deny all;
}
}