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
增加upstreamserver的status模块
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 �Cp1<../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二进制文件,先备份一下原来的启动脚本。
[[email protected]]# cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
6.需要把nginx进程杀掉,不然复制会报错
[[email protected]]# killall nginx
[[email protected]]# killall nginx
nginx: no processkilled
[[email protected]]# 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.修改tomcat的server.xml:
在配置文件中添加:
Tomcat1:<Enginename="Catalina" defaultHost="xjcdata.com"jvmRoute="tomcat610">
Tomcat2:…
.
.
.
Jvmroute=”tomcatxxx”依次类推即可。并且要和nginx的srun_id=tomcatxxx一一对应!
9.启动nginx,并重启所有tomcat