tomcat 之 httpd session stiky

# Comment center console 

[root @ nginx ~] # vim / etc / httpd / conf / the httpd.conf 
#DocumentRoot " / var / the WWW / HTML " 


#: Configuring virtual hosts 

[root @ nginx ~] # vim / etc / httpd / conf.d / tomcat.conf
 <VirtualHost *: 80 > 
ServerName node1.magedu.com 
ProxyRequests Off 
ProxyVia the On 
ProxyPreserveHost the On 
ProxyPass        / Balancer: // lbtomcats / 
ProxyPassReverse / Balancer: // lbtomcats / 
</ VirtualHost> 

<Proxy Balancer: / / lbtomcats> 
BalancerMember HTTP: //node1.magedu.com:8080 loadfactor=1
BalancerMember http://node2.magedu.com:8080 loadfactor=2
</Proxy>

#:分别配置tomcat
[root@node1 ~]# vim /usr/local/tomcat/conf/server.xml
<Engine name="Catalina" defaultHost="node1.magedu.com" jvmRoute="Tomcat1">
[root@node2 ~]# vim /usr/local/tomcat/conf/server.xml
<Engine name="Catalina" defaultHost="node2.magedu.com" jvmRoute="Tomcat2"> 



# Observation is polled
#:使用session粘性

[root@nginx ~]# vim /etc/httpd/conf.d/tomcat.conf
Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
<VirtualHost *:80>
ServerName      node1.magedu.com
ProxyRequests   Off
ProxyVia        On
ProxyPreserveHost On
ProxyPass       / balancer://lbtomcats/
ProxyPassReverse / balancer://lbtomcats/
</VirtualHost>

<Proxy balancer://lbtomcats>
BalancerMember http://loadFactor = 1 route = node1.magedu.com:8080 tomcat1 
BalancerMember HTTP: // node2.magedu.com:8080 loadFactor = 2 route = tomcat2 
ProxySet stickysession = the routeID
 </ Proxy> 
#
find Session unchanged, and has been looking for the same a Tomcat server

 

#:api

[root@nginx ~]# vim /etc/httpd/conf.d/tomcat.conf 
<VirtualHost *:80>
ServerName      node1.magedu.com
ProxyRequests   Off
ProxyVia        On
ProxyPreserveHost On
ProxyPass       / balancer://lbtomcats/
ProxyPassReverse / balancer://lbtomcats/
</VirtualHost>

<Proxy balancer://lbtomcats>
BalancerMember ajp://node1.magedu.com:8009 loadfactor=1 route=Tomcat1
BalancerMember ajp://node2.magedu.com:8009 loadfactor=2 route=Tomcat2
ProxySet stickysession=ROUTEID
</Proxy>

Although the above approach to achieve the client to find the same period of time Tomcat , so as to avoid after switching caused Session loss. but if

Tomcat node hang up, then the Session is still missing.

Suppose A , B two nodes are Session persistence. If Tomcat A user offline during a service switching to Tomcat B , the gained the Tomcat B 's Session , even if persistence Session of Tomcat A on the line, is useless.

Guess you like

Origin www.cnblogs.com/maxuebin/p/11447555.html