Two Tomcat nodes: 172.16.100.7 (tomcatA.magedu.com), 172.16.100.8 (tomcatB.magedu.com)
Two x memcached nodes: 172.16.100.9, 172.16.100.10
One load Balancer node: 172.16.100.6
Clients-->172.16.100.6--> (Tomcata, TOMCATB)
Combined with Tomcat, the session exists in memcached
1 Installing memcached
Yum Install Memcached-y
Start the memcached service
2 Configuring Tomcat
1 Installing Tomcat and JDK
2 Copy the corresponding class file into the Tomcat class file
Download the following jar file to the Lib directory in the Tomcat installation directory of each tomcat node, where ${version} is replaced with the version number you need, tc${6,7,8} to be the same version number as the Tomcat version.
Memcached-session-manager-${version}.jar 2.1.1
Memcached-session-manager-tc${6,7,8}-${version}.jar tc7-2.1.1
Spymemcached-${version}.jar 2.1.1
Msm-javolution-serializer-${version}.jar 2.1.1
Javolution-${version}.jar
Put it in/usr/share/java/tomcat/.
Memcached-session-manager Project Address,
http://code.google.com/p/memcached-session-manager/,
Https://github.com/magro/memcached-session-manager
Define a context container for testing on a host on two Tomcat, and create a session manager in it, as follows:
<context path= "/test" docbase= "/usr/local/tomcat/webapps/test" reloadable= "true" >
<manager classname= "De.javakaffee.web.msm.MemcachedBackupSessionManager"
Memcachednodes= "n1:172.16.100.9:11211,n2:172.16.100.10:11211"
failovernodes= "N1"
Requesturiignorepattern= ". *\. (ICO|PNG|GIF|JPG|CSS|JS) $ "
Transcoderfactoryclass= "De.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory"
/>
</Context>
Provide test pages for two, respectively
Tomcata:
# Mkdir-pv/usr/local/tomcat/webapps/test/web-inf/{classes,lib}
# vim/usr/local/tomcat/webapps/test/index.jsp
<%@ page language= "java"%>
<body>
<table align= "centre" border= "1" >
<tr>
<td>session id</td>
<% Session.setattribute ("magedu.com", "magedu.com"); %>
<td><%= Session.getid ()%></td>
</tr>
<tr>
<td>created on</td>
<td><%= session.getcreationtime ()%></td>
</tr>
</table>
</body>
TOMCATB:
# Mkdir-pv/usr/local/tomcat/webapps/test/web-inf/{classes,lib}
# vim/usr/local/tomcat/webapps/test/index.jsp,
<%@ page language= "java"%>
<body>
<table align= "centre" border= "1" >
<tr>
<td>session id</td>
<% Session.setattribute ("magedu.com", "magedu.com"); %>
<td><%= Session.getid ()%></td>
</tr>
<tr>
<td>created on</td>
<td><%= session.getcreationtime ()%></td>
</tr>
</table>
</body>
Configure the reverse proxy load balancing content on 172.16.100.6, similar to the following: HTTP
Add vim to the configuration file./conf.d/ilinux.conf
<proxy balancer://tomcat>
Balancermember http://172.16.100.7:8080 loadfactor=1
Balancermember http://172.16.100.8:8080 loadfactor=1
Proxyset lbmethod=byrequests
</Proxy>
Proxyvia OFF
Proxyrequests OFF
proxypass/balancer://tomcat/
proxypassreverse/balancer://tomcat/
<proxy *>
Order Allow,deny
Allow from all
</Proxy>
<location/>
Order Allow,deny
Allow from all
</Location>
Start the HTTP service
Access: Test results, Access http://172.16.100.6/test in the browser, the result is as follows, and its session ID remains unchanged in the load balancing environment.
http--tomcat--memcached Configuration