合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
健康状态检测案例: 1)安装nginx_upstream_check_module模块模块 [root@proxy01 opt]# git clone https://github.com/yaoweibin/nginx_upstream_check_module.git 或者 http://soft.51yuki.cn/nginx_upstream_check_module-master.zip 2)nginx加载该模块 [root@proxy01 nginx-1.9.2]# patch -p1 < /opt/nginx_upstream_check_module/check_1.9.2+.patch [root@proxy01 nginx-1.9.2]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --error-log-path=/var/log/nginx/error_log --http-log-path=/var/log/nginx/access_log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --with-http_ssl_module --with-http_stub_status_module --with-http_image_filter_module --with-http_gzip_static_module --with-http_flv_module --with-http_mp4_module --http-client-body-temp-path=/var/tmp/nginx/client --http-proxy-temp-path=/var/tmp/nginx/proxy --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi --add-module=/opt/ngx_cache_purge-master --add-module=/usr/local/src/nginx-upstream-fair --add-module=/opt/nginx-sticky-module-ng/ --add-module=/opt/nginx_upstream_check_module/ && make^C [root@proxy01 nginx-1.9.2]# cp objs/nginx /usr/local/nginx/sbin/ cp: overwrite `/usr/local/nginx/sbin/nginx'? y [root@proxy01 nginx-1.9.2]# /usr/local/nginx/sbin/nginx 参数: - interval:向后端发送的健康检查包的间隔。 - fall(fall_count): 如果连续失败次数达到fall_count,服务器就被认为是down。 - rise(rise_count): 如果连续成功次数达到rise_count,服务器就被认为是up。 - timeout: 后端健康请求的超时时间。 - - type:健康检查包的类型,现在支持以下多种类型 - tcp:简单的tcp连接,如果连接成功,就说明后端正常。 - ssl_hello:发送一个初始的SSL hello包并接受服务器的SSL hello包。 - http:发送HTTP请求,通过后端的回复包的状态来判断后端是否存活。 - mysql: 向mysql服务器连接,通过接收服务器的greeting包来判断后端是否存活。 - ajp:向后端发送AJP协议的Cping包,通过接收Cpong包来判断后端是否存活。 - port: 指定后端服务器的检查端口。你可以指定不同于真实服务的后端服务器的端口,比如后端提供的是443端口的应用,你可以去检查80端口的状态来判断后端健康状况。默认是0,表示跟后端server提供真实服务的端口一样。该选项出现于Tengine-1.4.0。 check_http_expect_alive 这些状态码指示上游服务器的http 响应是可以的,后端是活着的。 check_http_send default: *"GET / HTTP/1.0\r\n\r\n"* https://github.com/yaoweibin/nginx_upstream_check_module 案例: upstream StaticServer { server 10.100.100.105:80; server 10.100.100.104:80; check interval=5000 rise=1 fall=3 timeout=4000; #check_http_send "HEAD /status HTTP/1.1\r\n\r\n"; } server { listen 80; server_name test.51yuki.cn; #charset koi8-r; #access_log logs/host.access.log main; location / { proxy_pass http://StaticServer; } location /status { check_status; #access_log off; allow 10.100.100.0/24; deny all; } 案例2: http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; upstream server { server 10.2.11.233:80; server 10.2.11.232:80; check interval=5000 rise=2 fall=3 timeout=5000 type=http; check_http_send "HEAD /health.html HTTP/1.0\r\n\r\n"; } server { listen 80; server_name test.a.com; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } location /bbs { proxy_pass http://server/bbs; proxy_set_header host $Host; } location /status { check_status; access_log off; allow 10.2.18.0/24; deny all; } ![](https://box.kancloud.cn/139269b051bf66d5c246492df6f7840b_806x325.png) 模拟后端服务器node2,故障 [root@node2 html]# service httpd stop Stopping httpd: [ OK ] 然后在查看 ![](https://box.kancloud.cn/bcbaf16ad1804418b9907aa7a622e223_812x317.png) 注意: 后端服务器是http,让其不记录对/health.html的访问日志 [root@node2 conf]# vim httpd.conf SetEnvIf Remote_Addr "10\.2\.11\.207" dontlog SetEnvIf Remote_URL "^/health\.html$" dontlog CustomLog logs/access_log combined env=!dontlog 然后重启http服务器