CentOS7.2 nginx1.10.1 增加后端健康检查upstream_check模�K

Nginx1.10.1增加后端web健康检查upstream_check模�K


因�楣�司的�I�招枨螅�需要�⒁呀ê玫募��中反向代理和��d均衡做成集群,����Ω�瞻l量。

但是做成集群的架��后,後端的�膳_web�C器,需要靠Nginx的upstream_check�碜鼋】�z查。

实验环境:

应用 IP 操作系统 涉及软件

负载均衡层 172.16.22.2 CentOS 7.2 Nginx-1.10.1

后端web01 172.16.22.3 CentOS 7.2 Tomcat-7.0.72

后端web02 172.16.22.4 CentOS 7.2 Tomcat-7.0.72


下列的设定只在负载均衡层进行,且至针对单台进行操作,另外一台负载均衡机器集群成员也按照下列步骤操作即可。

下面呈现的是我大致的安装步骤:

1.已源�a安装Nginx1.10.1版本


2.首先下�d了Nginx_upstream_check_module模�K�a丁

wget https://github.com/yaoweibin/Nginx_upstream_check_module/archive/master.zip


3.把master.zip解��

[root@z soft]#unzip Nginx_upstream_check_module.zip

�M入到Nginx_upstream_check_module��

[root@z Nginx_upstream_check_module]#pwd

/data0/soft/Nginx_upstream_check_module

--主要�榉奖汜崂m打好�a丁做���


4.�M入到Nginx1.10.1的源�a包目�里

[root@z ~]#cd /usr/local/Nginx-1.10.1


5.因要��Nginx打後�_健康�z查的�a丁,需要把打�a丁的命令安�b完��

[root@z Nginx-1.10.1]#rpm -qa | grep patch

patch-2.7.1-8.el7.x86_64


如果�]有安�bpatch,就yum install -y patch


6.打upstream_check�a丁�M入Nginx-1.10.1��

[root@z Nginx-1.10.1]#patch -p0 < /data0/soft/Nginx_upstream_check_module/check_1.11.1+.patch


7.打完�a丁就�M行��g

因�樾枰�添加�Cadd-module=/root/Nginx_upstream_check_module-master

如果其他编译参数和之前保持一致,但又不记得之前的编译参数,

可使用 Nginx -V 命令查看。

[root@z Nginx-1.10.1]# /usr/local/Nginx/sbin/Nginx -V

Nginx version: Nginx/1.10.1

built by gcc 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC)

built with OpenSSL 1.0.1e-fips 11 Feb 2013

TLS SNI support enabled

configure arguments:

--prefix=/usr/local/Nginx

--pid-path=/var/run/Nginx/Nginx.pid

--lock-path=/var/lock/Nginx.lock

--user=Nginx

--group=Nginx

--with-http_ssl_module

--with-http_flv_module

--with-http_stub_status_module

--with-http_gzip_static_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/fcgi/

--http-uwsgi-temp-path=/var/tmp/Nginx/uwsgi

--http-scgi-temp-path=/var/tmp/Nginx/scgi

--with-pcre


所以就�M行��g,只要在後面添加upstream_check_module-master

即如下:

[root@z Nginx-1.10.1]#./configure \

--prefix=/usr/local/Nginx \

--pid-path=/var/run/Nginx/Nginx.pid \

--lock-path=/var/lock/Nginx.lock \

--user=Nginx \

--group=Nginx \

--with-http_ssl_module \

--with-http_flv_module \

--with-http_stub_status_module \

--with-http_gzip_static_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/fcgi/ \

--http-uwsgi-temp-path=/var/tmp/Nginx/uwsgi \

--http-scgi-temp-path=/var/tmp/Nginx/scgi \

--with-pcre \

--add-module=/data0/soft/Nginx_upstream_check_module-master/


[root@z Nginx-1.10.1]# make && make install

[root@z Nginx-1.10.1]# make clean

#注:因�槲沂窃谠��硪寻沧暗陌姹旧习膊�Nginx_upstream_check_module模�K,所以Nginx.conf是在原�淼幕��A上生成的,所以不需要另外�浞荨R�是谨慎点�是把原�淼呐渲�n案�浞菀幌拢�再�M行��g安�b。


8.到了这,就是重�c了,配置Nginx�z�y後端��c健康��r

vim /etc/Nginx.conf

添加upstream模�K


upstream information{

server 172.16.22.3:80 max_fails=2;

server 172.16.22.4:80 max_fails=2;

check interval=3000 rise=2 fall=5 timeout=1000 type=http;

}

--嵌套�Mhttp�燃纯�


#注,指令参数的意义

- interval:向后端发送的健康检查包的间隔ms。

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

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

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

- default_down: 设定初始时服务器的状态,如果是true,就说明认是down的,如果是false,就是up的。

认值是true,也就是一开始服务器认为是不可用,要等健康检查包达到一定成功次数以后才会被认为是健康的。

- type:健康检查包的类型,现在支持以下多种类型

- tcp:简单的tcp连接,如果连接成功,就说明后端正常。

- ssl_hello:发送一个初始的SSL hello包并接受服务器的SSL hello包。

- http:发送HTTP请求,通过后端的回复包的状态来判断后端是否存活。

- MysqL: 向MysqL服务器连接,通过接收服务器的greeting包来判断后端是否存活。

- ajp:向后端发送AJP协议的Cping包,通过接收Cpong包来判断后端是否存活。

- port: 指定后端服务器的检查端口。你可以指定不同于真实服务的后端服务器的端口,

比如后端提供的是443端口的应用,你可以去检查80端口的状态来判断后端健康状况。认是0,表示跟后端server提供真实服务的端口一样。


9.通过访问Nginxstatus�面,查看后端机器是否真的�B接上了的准备工作

vim /etc/Nginx.conf

配置负载均衡层实时连接状态展示页面,在Nginx.conf上添加

location /Nginxstatus{

stub_status on;

access_log /usr/local/Nginx/logs/status.log;

auth_basic "Nginxstatus";

}


查看后端�W�的�B接��,查看upstream check status,即后端web健康状况

#添加Nginx_upstream_check_module模块之后,该项生效

#主要为了测试Nginx_upstream_check_module模块是否好使

location /zstatus{

check_status;

access_log off;

#allow IP;

#deny all;

}


10.配置完��,需要重��Nginx服务

先�z查配置信息是否�o�`

[root@z Nginx-1.10.1]#/usr/local/Nginx/sbin/Nginx -t


平滑重��Nginx服��

[root@z Nginx-1.10.1]#/usr/local/Nginx/sbin/nignx -s reload


可以在�W�上�g�[�L��http://172.16.22.2/Nginxstatus ,查看Nginx的连接状态

wKiom1kVF9mjgN09AAATT-vZ5W0448.png

访问http://172.16.22.2/informationstatus,查看后端web健康状况

wKioL1kVF9rhE4zFAAA9dEs_pig375.png

以上说明后端健康检查模块安装成功!

上述内容纯靠记忆写下,可能存在缺漏,如有错误与遗失,欢迎大家指出,谢谢!

相关文章

Centos下搭建性能监控Spotlight
CentOS 6.3下Strongswan搭建IPSec VPN
在CentOS6.5上安装Skype与QQ
阿里云基于centos6.5主机VPN配置
CentOS 6.3下配置multipah
CentOS安装、配置APR和tomcat-native