upstream、health-check模块实现负载均衡、状态检测

拓扑图:

nginx实现负载均衡、状态检测_upstream

服务器A增加一个网卡,与服务器B和服务器C通信,地址如上图

服务器A

配置地址,查看如下:

nginx实现负载均衡、状态检测_health-check_02

源码安装nginx-1.0.11

yum --disablerepo=\* --enablerepo=c6-media install pcre-devel openssl-devel -y   安装必要的软件包

1.[root@wangcf1009 ~]# tar -zxvf nginx-1.0.11.tar.gz  -C /usr/local/src/

2.[root@wangcf1009 ~]# unzip healthcheck_nginx_upstreams-master.zip 

3.[root@wangcf1009 ~]# cd /usr/local/src/nginx-1.0.11/

4.[root@wangcf1009 nginx-1.0.11]# patch -p1 </root/healthcheck_nginx_upstreams-master/nginx.patch    打补丁

出现下图

nginx实现负载均衡、状态检测_upstream_03

5.[root@wangcf1009 nginx-1.0.11]# groupadd -r nginx

6.[root@wangcf1009 nginx-1.0.11]# useradd -r  -g nginx nginx

7.编译:

./configure \

--conf-path=/etc/nginx/nginx.conf \

--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 \

--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/ \

--with-pcre \

--add-module=/root/healthcheck_nginx_upstreams-master

8.[root@wangcf1009 nginx-1.0.11]# make && make install

9.[root@wangcf1009 nginx-1.0.11]# vim /etc/profile 编辑如下PATH

nginx实现负载均衡、状态检测_health-check_04

10.[root@wangcf1009 nginx-1.0.11]# . /etc/profile

11.[root@wangcf1009 nginx-1.0.11]# cd /etc/nginx/

12.[root@wangcf1009 nginx]# nginx -t  检查语法出现下面错误

nginx实现负载均衡、状态检测_health-check_05 

13.[root@wangcf1009 nginx]# mkdir -pv /var/tmp/nginx/client/

14.[root@wangcf1009 nginx]# nginx -t 再进行测试,成功

nginx实现负载均衡、状态检测_upstream_06

15.[root@wangcf1009 nginx]#nginx  启动成功

nginx实现负载均衡、状态检测_health-check_07

16.ping后方的服务器,成功ping

nginx实现负载均衡、状态检测_upstream_08

17.[root@wangcf1009 nginx]# vim /etc/nginx/nginx.conf

实现负载均衡以及状态检查

nginx实现负载均衡、状态检测_upstream_09

18.测试语法,并重启,关闭防火墙

nginx实现负载均衡、状态检测_health-check_10

打开浏览器http://192.168.88.100/stat,探测失败

nginx实现负载均衡、状态检测_upstream_11

为服务器B做探测页面

nginx实现负载均衡、状态检测_upstream_12

service httpd restart

打开浏览器http://192.168.88.100/stat查看,一个探测OK

nginx实现负载均衡、状态检测_health-check_13