upstream、health-check模块实现负载均衡、状态检测
拓扑图:
服务器A增加一个网卡,与服务器B和服务器C通信,地址如上图
服务器A:
配置地址,查看如下:
源码安装nginx-1.0.11
yum --disablerepo=\* --enablerepo=c6-media install pcre-devel openssl-devel -y 安装必要的软件包
1.[[email protected] ~]# tar -zxvf nginx-1.0.11.tar.gz -C /usr/local/src/
2.[[email protected] ~]# unzip healthcheck_nginx_upstreams-master.zip
3.[[email protected]gcf1009 ~]# cd /usr/local/src/nginx-1.0.11/
4.[[email protected] nginx-1.0.11]# patch -p1 </root/healthcheck_nginx_upstreams-master/nginx.patch 打补丁
出现下图
5.[[email protected] nginx-1.0.11]# groupadd -r nginx
6.[[email protected] 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.[[email protected] nginx-1.0.11]# make && make install
9.[[email protected] nginx-1.0.11]# vim /etc/profile 编辑如下PATH
10.[[email protected] nginx-1.0.11]# . /etc/profile
11.[[email protected] nginx-1.0.11]# cd /etc/nginx/
12.[[email protected] nginx]# nginx -t 检查语法出现下面错误
13.[[email protected] nginx]# mkdir -pv /var/tmp/nginx/client/
14.[[email protected] nginx]# nginx -t 再进行测试,成功
15.[[email protected] nginx]#nginx 启动成功
16.ping后方的服务器,成功ping通
17.[[email protected] nginx]# vim /etc/nginx/nginx.conf
实现负载均衡以及状态检查
18.测试语法,并重启,关闭防火墙
打开浏览器http://192.168.88.100/stat,探测失败
为服务器B做探测页面
service httpd restart
打开浏览器http://192.168.88.100/stat查看,一个探测OK