首页 > 其他 > 详细

nginx+tomcat session共享 以及nginx upstream中realserver状态监控

时间:2014-03-11 19:35:55      阅读:471      评论:0      收藏:0      [点我收藏+]

1.查看nginx前期的安装模块:

[root@jyfxapp1 tomcat610]#/usr/local/nginx/sbin/nginx -V

nginx version: nginx/1.2.9

built by gcc 4.4.7 20120313 (Red Hat4.4.7-4) (GCC)

TLS SNI support enabled

configure arguments: --user=www --group=www--prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module--with-http_flv_module --with-http_gzip_static_module--with-google_perftools_module

2.下载nginx-upstream-jvm-route-0.1.tar.gz模块

nginx_upstream_jvm_route 是一个Nginx的扩展模块,用来实现基于 Cookie 的 SessionSticky 的功能。

Wget https://nginx-upstream-jvm-route.googlecode.com/files/nginx-upstream-jvm-route-0.1.tar.gz

增加upstreamserverstatus模块

wget https://nodeload.github.com/yaoweibin/nginx_upstream_check_module/zip/master


3.将此模块补丁打到nginx

Tar xzvf nginx-upstream-jvm-route-0.1.tar.gz

Cd nginx-XXXXX

patch -p0<../nginx_upstream_jvm_route/jvm_route.patch

patching file src/http/ngx_http_upstream.c

Hunk #1 succeeded at 4135 (offset 398lines).

Hunk #2 succeeded at 4227 (offset 398lines).

Hunk #3 succeeded at 4267 (offset 398lines).

Hunk #4 succeeded at 4320 (offset 398lines).

Hunk #5 succeeded at 4366 (offset 398lines).

patching file src/http/ngx_http_upstream.h

Hunk #1 succeeded at 90 (offset 5 lines).

Hunk #2 succeeded at 103 (offset 5 lines).

Hunk #3 succeeded at 118 (offset 5 lines).

成功

Status模块补丁:

patch –p1<../nginx_upstream_check_module-master/check_1.2.6+.patch

patching filesrc/http/modules/ngx_http_upstream_ip_hash_module.c

patching filesrc/http/modules/ngx_http_upstream_least_conn_module.c

patching filesrc/http/ngx_http_upstream_round_robin.c

Hunk #8 succeeded at 572 (offset 2 lines).

patching file src/http/ngx_http_upstream_round_robin.h

成功

4.使用原来的参数重新编译nginx,并添加jvm-route模块

./configure --user=www --group=www--prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module--with-http_flv_module --with-http_gzip_static_module--with-google_perftools_module  --add-module=/usr/local/src/nginx_upstream_jvm_route           --add-module=/usr/local/src/nginx_upstream_check_module-master


Make (只需要make即可,不用makeinstall否则为覆盖安装)


5.需要替换nginx二进制文件,先备份一下原来的启动脚本。

[root@vmware1nginx-1.2.9]# cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak


6.需要把nginx进程杀掉,不然复制会报错

[root@vmware1nginx-1.3.1]# killall nginx

[root@vmware1nginx-1.3.1]# killall nginx

nginx: no processkilled

[root@vmware1nginx-1.3.1]# cp ./objs/nginx /usr/local/nginx/sbin/

cp: overwrite`/usr/local/nginx/sbin/nginx‘? yes

7.修改nginx配置文件

       upstream T1{

               server 192.168.133.20:8010srun_id=tomcat610;

               server 192.168.133.20:8020srun_id=tomcat620;

               server 192.168.133.20:8030srun_id=tomcat630;

               server 192.168.133.20:8040srun_id=tomcat640;

               server 192.168.133.20:8050srun_id=tomcat650;

               jvm_route$cookie_JSESSIONID|sessionid reverse;

checkinterval=3000 rise=2 fall=5 timeout=1000;

               }


增加status:

location /status{

    check_status;

    access_log  off;

    #allowSOME.IP.ADD.RESS;

    #denyall;

      }

注解:check interval=3000 rise=2 fall=5 timeout=1000;

interval检测间隔时间,单位为毫秒。

rsie请求2次正常的话,标记此realserver的状态为up。

fall表示请求5次都失败的情况下,标记此realserver的状态为down。

timeout为超时时间,单位为毫秒

8.修改tomcatserver.xml

在配置文件中添加:

Tomcat1:<Enginename="Catalina" defaultHost="xjcdata.com"jvmRoute="tomcat610">

Tomcat2:…

.

.

.

Jvmroute=”tomcatxxx”依次类推即可。并且要和nginxsrun_id=tomcatxxx一一对应!


9.启动nginx,并重启所有tomcat



本文出自 “石头蛐蛐” 博客,请务必保留此出处http://shitouququ.blog.51cto.com/24569/1372486

nginx+tomcat session共享 以及nginx upstream中realserver状态监控,布布扣,bubuko.com

nginx+tomcat session共享 以及nginx upstream中realserver状态监控

原文:http://shitouququ.blog.51cto.com/24569/1372486

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!