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

fenghuoliuxing0 2012-12-24

NGINX负载配置:

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共享   
           }

修改resinserver.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介绍

Thismoduleachievessessionstickinesswiththesessioncookie.IfthesessionisnotinthecookieorURL,themodulewillbeanormalRound-Robinupstreammodule.

INSTALLATION

EXAMPLE

1.Forresin

upstreambackend

{

server192.168.0.100srun_id=a;

server192.168.0.101srun_id=b;

server192.168.0.102srun_id=c;

server192.168.0.103srun_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'specifiesthesessioncookiename(0.7.24+).'session_url'specifiesadifferentsessionnameintheURLwhentheclientdoesnotacceptacookie.Thesessionnameiscase-insensitive.Inthismodule,ifitdoesnotfindthesession_url,itwillusethesessioncookienameinstead.SoifthesessionnameincookieisthenamewithitsinURL,youdon'tneedgivethesession_urlname.

Withscanningthiscookie,themodulewillsendtherequesttorightbackendserver.AsfarasIknow,theresin'ssrun_idnameisintheheadofcookie.Forexample,requestswithcookievalue'a***'arealwayssenttotheserverwiththesrun_idof'a'.Buttomcat'sJSESSIONIDisopposite,whichislike'***.a'.Theparameterof'reverse'specifiesthecookiescannedfromtailtohead.

Iftherequestfailstobesenttothechosenbackendserver,ItwilltryanotherserverwiththeRound-Robinmodeuntilalltheupstreamserverstried.Thedirectiveproxy_next_upstreamcanspecifyinwhatcasestherequestwillbetransmittedtothenextserver.Ifyouwanttoforcethesessionsticky,youcanset'proxy_next_upstreamoff'.

server

Everysyntaxisthesamewiththeofficialdirectiveexcepttheparameterof'srun_id'whichidentifiedthebackendJVM'snamebycookie.Thedefaultsrun_id'svalueis'a';

NOTE

Thisisathird-partymodule.Andyouneedcarefultestbeforeusingthismoduleinyourproductionenvironment.

Questions/patchesmaybedirectedtoWeibinYao,[email protected].

相关推荐

LetonLIU / 0评论 2020-05-29