开始打算用cep21-healthcheck_nginx_upstreams-16d6ae7.zip来做的,但是发现有版本错误,参考 http://www.linuxidc.com/Linux/2012-08/67742.htm ,可以在1.2.1以上使用了,结合了healthcheck_nginx_upstreams的来做
https://github.com/yaoweibin/nginx_upstream_check_module 下载软件
需要打补丁,并且重新编译
- # unzip yaoweibin-nginx_upstream_check_module-v0.1.6-17-gdfee401.zip
- # cd nginx-1.2.3
- # patch -p1 < /root/yaoweibin-nginx_upstream_check_module-dfee401/check_1.2.1+.patch
- (如果nginx版本不是1.2.1以上的,用patch -p1 < /usr/local/yaoweibin-nginx_upstream_check_module-dfee401/check.patch打补丁)
- # ./configure \
- --prefix=/usr \
- --sbin-path=/usr/sbin/nginx \
- --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/yaoweibin-nginx_upstream_check_module-dfee401/
- # make && make install
修改配置文件:
- # egrep -v "^$|#" /etc/nginx/nginx.conf
- worker_processes 1;
- events {
- worker_connections 1024;
- }
- http {
- include mime.types;
- default_type application/octet-stream;
- upstream peace {
- server 192.168.80.143 weight=1; //指定节点web1
- server 192.168.80.144 weight=2; //指定节点web2
- check interval=1000 rise=2 fall=2 timeout=1000; //interval检测间隔时间,rsie请求2次正常的话为up,fail请求2次失败的话为down,timeout检查超时时间(毫秒)
- check_http_send "GET /.test.html HTTP/1.0"; //所发送的检测请求
- }
- sendfile on;
- keepalive_timeout 65;
- server {
- listen 80;
- server_name localhost;
- location / {
- proxy_pass http://peace; //引用
- }
- location /status { //定义一个类似stub_status的方式输出检测信息
- check_status;
- }
- error_page 500 502 503 504 /50x.html;
- location = /50x.html {
- root html;
- }
- }
- }
- # service nginx restart
下面访问下192.168.80.146/status可以看到两台都up,并且页面正常:
之后关闭一台web2,可以看到已经down,并且访问都是web1工作:
至此Nginx的相关扩展就结束了,如有错误请指出,非常感谢!


