nginx负载resin,实现session共享-JVM_ROUTE

[b]NGINX负载配置:[/b]


   
upstream backend {#集群服务器
server 127.0 . 0.1 : 8080 srun_id=resinserver1;
server 127.0 . 0.1 : 8081 srun_id=resinserver2;
jvm_route $cookie_JSESSIONID|sessionid;#session共享
}


修改resin server.xml


<server id="a" address="192.168.6.121" port="6800">
<!-- server2 address=192.168.6.162 -->
<http id="" port="8080"/>
</server>
<server id="b" address="192.168.6.121" port="6801">
<!-- server2 address=192.168.6.162 -->
<http id="" port="8081"/>
</server>


tomcat服务器

10.110.5.151修改为
<Engine name=”Catalina” defaultHost=”localhost” jvmRoute=”resinserver1”>

10.110.5.152修改为
<Engine name=”Catalina” defaultHost=”localhost” jvmRoute=”resinserver2”>

jvm_route介绍


This module achieves session stickiness with the session cookie. If the session is not in the cookie or URL, the module will be a normal Round-Robin upstream module.
INSTALLATION
EXAMPLE

1.For resin

upstream backend
{

server 192.168.0.100 srun_id=a;
server 192.168.0.101 srun_id=b;
server 192.168.0.102 srun_id=c;
server 192.168.0.103 srun_id=d;
jvm_route $cookie_JSESSIONID
;


}
DIRECTIVES

jvm_route

syntax: jvm_route $cookie_COOKIE[ |session_url] [ reverse]

default: none

context: upstream

description:

'$cookie_SESSION_COOKIE' specifies the session cookie name(0.7.24+). 'session_url' specifies a different session name in the URL when the client does not accept a cookie. The session name is case-insensitive. In this module, if it does not find the session_url, it will use the session cookie name instead. So if the session name in cookie is the name with its in URL, you don't need give the session_url name.

With scanning this cookie, the module will send the request to right backend server. As far as I know, the resin's srun_id name is in the head of cookie. For example, requests with cookie value 'a* * * ' are always sent to the server with the srun_id of 'a'. But tomcat's JSESSIONID is opposite, which is like '* * * .a'. The parameter of 'reverse' specifies the cookie scanned from tail to head.

If the request fails to be sent to the chosen backend server, It will try another server with the Round-Robin mode until all the upstream servers tried. The directive proxy_next_upstream can specify in what cases the request will be transmitted to the next server. If you want to force the session sticky, you can set 'proxy_next_upstream off'.

server

Every syntax is the same with the official directive except the parameter of 'srun_id' which identified the backend JVM's name by cookie. The default srun_id's value is 'a';
NOTE

This is a third-party module. And you need careful test before using this module in your production environment.

Questions/patches may be directed to Weibin Yao, yaoweibin@gmail.com.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值