1)下载nginx_upstream_check_module模块,并部署到nginx中。
[root@localhost ~]
# cd /usr/local/src
[root@localhost src]
# wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/master.zip
[root@localhost src]
# unzip unzip master.zip
[root@localhost src]
# ls
master.zip nginx_upstream_check_module-master
[root@localhost src]
# ls nginx_upstream_check_module-master/
CHANGES check_1.2.6+.patch check.patch ngx_http_upstream_check_module.c upstream_fair.patch
check_1.11.1+.patch check_1.5.12+.patch config ngx_http_upstream_check_module.h util
check_1.11.5+.patch check_1.7.2+.patch doc ngx_http_upstream_jvm_route_module.patch
check_1.2.1.patch check_1.7.5+.patch nginx-sticky-module.patch README
check_1.2.2+.patch check_1.9.2+.patch nginx-tests
test
[root@localhost src]
# wget http:///download/nginx-1.8.0.tar.gz
[root@localhost src]
# tar -zxvf nginx-1.8.0.tar.gz
[root@localhost src]
# cd nginx-1.8.0
[root@localhost nginx-1.8.0]
# patch -p1 < ../nginx_upstream_check_module-master/check_1.9.2+.patch
[root@localhost nginx-1.8.0]
# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --add-module=../nginx_upstream_check_module-master/
[root@node1 src]
# make && make install
2)nginx配置
[root@master-node ~]
# vim /usr/local/nginx/conf/vhosts/LB.conf
upstream LB-WWW {
server 192.168.1.101:80;
server 192.168.1.102:80;
check interval=3000 rise=2 fall=5 timeout=1000
type
=http;
check_keepalive_requests 100;
check_http_send
"HEAD / HTTP/1.1\r\nConnection: keep-alive\r\n\r\n"
;
check_http_expect_alive http_2xx http_3xx;
}
server {
listen 80;
server_name www.wangshibo.com;
access_log
/usr/local/nginx/logs/www-access
.log main;
error_log
/usr/local/nginx/logs/www-error
.log;
location / {
proxy_pass http:
//LB-WWW
;
proxy_redirect off ;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 600;
proxy_buffer_size 256k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_temp_file_write_size 256k;
proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
proxy_max_temp_file_size 128m;
proxy_cache mycache;
proxy_cache_valid 200 302 60m;
proxy_cache_valid 404 1m;
}
location
/nstatus
{
check_status;
access_log off;
#allow IP;
#deny all;
}
}