1. Build the Environment
192.168.29.128 (luxh-01.com) installation Nginx, reference http://www.cnblogs.com/luxh/p/4067038.html
192.168.29.129 (luxh-02.com) installs Tomcat and memcached
192.168.29.130 (luxh-03.com) installs Tomcat and memcached
2, installation memcached
1) install directly with Yum
[Email protected]yuminstall memcached
2) Start memcached, the default boot port is 11211
[Email protected] ~]# memcached-u memcached
-U Specify user
3) test whether the start is successful
[Email protected]127.0. 0.1 11211
3, Installation Tomcat7
Reference: http://www.cnblogs.com/luxh/p/3188736.html
4. Add Memcached-session-manager related jar to Tomcat
Place the following jar in the Lib directory of the Tomcat installation path
memcached-session-manager-1.8.2. jarmemcached-session-manager-tc7-1.8.2. jarspymemcached- 2.11.1.jar
Note that the version of Tomcat is different, the jar version is also different, specifically refer to Http://code.google.com/p/memcached-session-manager/wiki/SetupAndConfiguration
5. Add serializers related jars to the web App
The serialization is implemented here using Kryo-serializer.
The project uses MAVEN to add dependencies directly
<dependency> <groupId>de.javakaffee.msm</groupId> <artifactId> msm-kryo-serializer</artifactid> <version>1.8.0</version> <scope> Runtime</scope></dependency>
If you do not use MAVEN, add the following jar to the project yourself
msm-kryo-serializer-1.8.0. jarkryo-serializers-0.11. jarkryo-1.04.jarasm-3.2. jarreflectasm-1.01. jarminlog-1.2.jarjsr305-1.3.9. jarannotations-1.3.9. Jar
6. Configuring Memcached-session-manager in Tomcat
Include the following in the Tomcat context.xml file (<Context></Context> tag).
Non-sticky session configuration, two memcached servers.
<className= "De.javakaffee.web.msm.MemcachedBackupSessionManager" Memcachednodes= "n1:luxh-02.com:11211,n2:luxh-03.com:11211" sticky= "false" sessionbackupasync= "false" requesturiignorepattern= ". *\. ( ICO|PNG|GIF|JPG|CSS|JS) $ " transcoderfactoryclass=" De.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory " />
7. Configure Nginx
1) Add the contents of the HTTP node in the nginx.conf file
Upstream luxh-01.com { server luxh-02.com:8080; Server luxh-03.com:8080; }
2) Add the contents of the server node in the nginx.conf file
Location/{ Proxy_pass http://luxh-01.com; Proxy_set_header X-real-ip $remote _addr; }
8. Deploy the application separately to the Tomcat server.
1) Start memcached service
2) Start Tomcat
3) Start Nginx
9. Direct access to Http://luxh-01.com/webapp (the project I deployed is accessed through WebApp)
Nginx+tomcat+memcached-session-manager compose a simple cluster