需求是这样的:比如一个 tomcat 节点 down 掉,其他节点能够替换它。
使用nginx的第三方插件
nginx_upstream_check_module
我的测试环境是:nginx/1.7.2 + tomcat7
1.首先下载nginx_upstream_check_module项目后解压
2.编译安装nginx
在安装前到nginx目录中执行:
patch -p1 < /root/tools/data/healthcheck_nginx_upstreams-master/nginx.patch
注意nginx.patch要对应好自己nginx版本,github那个项目中有说明。一开始就是安装了发现不能使用health check功能发现是用的patch版本造成的。
然后
./configure --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --with-http_realip_module --with-http_addition_module --with-http_gzip_static_module --with-http_random_index_module --with-http_stub_status_module --with-http_sub_module --with-http_dav_module --with-openssl=/usr/local/src/openssl-1.0.1g --add-module=/root/tools/data/nginx_upstream_check_module-master/
make
make install
3.配置nginx.conf
upstream test_server{
server 127.0.0.1:8081;
server 127.0.0.1:8082;
check interval=5000 rise=1 fall=3 timeout=4000 type=http;
}
server {
listen 81;
server_name test.com;
location / {
proxy_pass http://test_server;
proxy_connect_timeout 3;
}
location /status {
check_status;
access_log off;
}
}
4.测试
好了,启动两个tomcat后,一个tomcat服务有问题nginx会检测到并舍弃这个节点。
输入
http://test.com:81/status后查看nginx检测tomcat的运行情况