Tomcat combined with memcached for Sessio sharing

Source: Internet
Author: User
Tags memcached session id tomcat server

Tomcat uses memcached for session sharing


System environment:

Centos6.5 x86_64

Use of two Tomcat instances on the same server


Installing jdk1.7

Installing tomcat8.0.27

Installing memcached

Yum install yum install java-1.7.0-openjdk.x86_64 java-1.7.0-openjdk-devel.x86_64 memcached-y


Download and install Tomcat8

wget http://mirrors.hust.edu.cn/apache/tomcat/tomcat-8/v8.0.27/bin/apache-tomcat-8.0.27.tar.gz Installation: Tar zxvf Apache-tomcat-8.0.27.tar.gzcp-r Apache-tomcat-8.0.27/usr/local/tomcat1cp-r apache-tomcat-8.0.27/usr/local/ Tomcat2


Use Nginx as an agent


Download and install:

wget Http://tengine.taobao.org/download/tengine-2.1.1.tar.gztar zxvf TENGINE-2.1.1.TAR.GZCD tengine-2.1.1./ Configuremakemake Install

The default directory for installation is:/usr/local/nginx

Configuration Nginx Here is not a lot of introduction, before the file is also described in detail, please refer to ^_^


Below to configure the next Tomcat connection memcached, store session ID


The files that need to be downloaded are the latest versions of this blog post, and the downloaded files correspond to the Tomcat version. I use the tomcat8 here so download is TC8 version

Memcached-session-manager-1.8.3.jar

Memcached-session-manager-tc8-1.8.3.jar

Msm-javolution-serializer-1.8.3.jar


Three files above: http://repo1.maven.org/maven2/de/javakaffee/msm/


Javolution-5.5.1.jar

: Http://central.maven.org/maven2/javolution/javolution/5.5.1/javolution-5.5.1.jar


Spymemcached-2.10.3.jar

: Https://spymemcached.googlecode.com/files/spymemcached-2.10.3.jar #这个可能需要翻墙,,, ^_^ in nearby pieces


After the download is complete, these jar packages are placed in the/usr/local/tomcat1/lib directory, which is the Lib directory under your Tomcat directory.


Modifying a configuration file Server.xml

Approximately in the following location:


<engine name= "Catalina" defaulthost= "localhost" >


Unpackwars= "true" autodeploy= "true"

Xmlvalidation= "false" Xmlnamespaceaware= "false" >

<!--Add the following labeled Red--! >

<context reloadable= "false" Path= "" > here can also be set to alias address similar to the following: <context reloadable= "true" path= "/virtual Address" Docbase= "True path" >

<manager classname= "De.javakaffee.web.msm.MemcachedBackupSessionManager"

memcachednodes= "N1:memcache Address: 11211"

sticky= "false"

sessionbackupasync= "false"

lockingmode= "Auto"

requesturiignorepattern= ". *\. (ICO|PNG|GIF|JPG|CSS|JS) $ "

transcoderfactoryclass= "De.javakaffee.web.msm.JavaSerializationTranscoderFactory"

/>

</Context>


<valve classname= "Org.apache.catalina.valves.AccessLogValve" directory= "Logs"

prefix= "Localhost_access_log" suffix= ". txt"

pattern= "%h%l%u%t &quot;%r&quot; %s%b "/>


</Host>

</Engine>


This is the same configuration on another tomcat.

Here is a test file test.jsp placed under Tomcat's web path,

The contents are as follows:


Sessionid:<%=session.getid ()%>

<BR>

Sessionip:<%=request.getservername ()%>

<BR>

Sessionport:<%=request.getserverport ()%>

<%

Out.println ("This is Tomcat Server 111111!   "); #这里区别两个tomcat的内容需要做下相应的修改

%>




After testing the Tomcat session ID has been shared, temporarily not a piece,,,,, ...

This article from the "Linux Learning" blog, declined reprint!

Tomcat combined with memcached for Sessio sharing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.