nginx 负载均衡web查看状态nginx_upstream_check_module
最近在做nginx负载均衡的时候发现nginx本身没有界面的管理工具,也没有发现其他的文本的管理工具。希望知道的朋友可以留言告诉我. 发现taobao在开源了自己的nginx 定制版本里面,有一个模块(nginx_upstream_check_module),这个模块就是用来查看nginx 负载均衡时候的realserver的状态的. 经过实验已经成功加入nginx 再此做个记录和分享。
lnmp 环境的安装请参照我的生产环境的lnmp 的安装,在安装nginx的时候参照下面的安装:
下载nginx_upstream_check_module:
cd /usr/local/src/wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/master.zipunzip master.zip
安装nginx的支持:pcre
tar-zxvf pcre-8.21.tar.gzcd pcre-8.21./configure && make && makeinstall
安装nginx-1.3.0
tar -zxvf nginx-1.3.0.tar.gzcd nginx-1.3.0
给nginx打上nginx_upstream_check_module-master
的包
(注:因nginx版本更新,1.2以上版本的nginx,补丁为check_1.2.1+.patch)
patch -p1 < /usr/local/src/nginx_upstream_check_module-master/check_1.2.1.patch
开始编译安装nginx:
### 注意下面的--with-pcre=pcre的安装包路径千万不要搞错了。
./configure --user=www --group=www --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.21 --lock-path=/var/run/nginx.lock --pid-path=/var/run/nginx.pid --add-module=/usr/local/src/nginx_upstream_check_module-master
make && make install
添加nginx配置:
因为篇幅大小原因,这个配置文件是省略了部分常用内容,但是并不代表其他不需要.(以下为需要特别注意的地方)
upstream www { #ip_hash; server 192.168.100.11:80; #多个realserver服务器在此添加 server 192.168.100.12:80; check interval=3000 rise=2 fall=5 timeout=1000;}server { listen 80; server_name www.etiantian.org; #charset koi8-r; access_log logs/host.access.log main; root /data0/www; location / { proxy_pass http://www; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /status { check_status; access_log off; #allow SOME.IP.ADD.RESS; #deny all; } }
※ 附件会发上来我的nginx 配置文件,希望对大家有帮助.
1 upstream 后面的www不是域名.可以根据需要自己起。
2
upstream 后面的www 要和proxy_pass http://www; 里面的www相互对应.
3 注解:check interval=3000 rise=2 fall=5 timeout=1000;
interval检测间隔时间,单位为毫秒。
rsie请求2次正常的话,标记此realserver的状态为up。
fall表示请求5次都失败的情况下,标记此realserver的状态为down。
timeout为超时时间,单位为毫秒。
测试nginx:
/usr/local/nginx/sbin/nginx -tnginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
启动nginx:
/usr/local/nginx/sbin/nginx &
测试截图: