Configure memcached in tomcat, share session

Memcached Session Manager

referred to as msm

memcached installation and use

1. Compile and install, you must first have gcc (yum -y install gcc)
2. Install libevent: ./configure --prefix=/opt/libevent; make && make install
3. Install memcached : ./configure --prefix=/opt/memcached --with-libevent=/opt/libevent/; make && make install

start memcached: /opt/memcached/bin/memcached -d -u root -m 128 -p 11211 -c 1024
-d background process
-u start user
-m use memory size
-p use port
-c maximum number of connections
   

msm configuration

1. Copy the jar package to the tomcat/lib directory, the jar is divided into three categories

1) spymemcached.jar memcached java client End
       
2) msm related packages
memcached-session-manager-{version}.jar core package
        memcached-session-manager-tc{tomcat-version}-{version}.jar Tomcat version related packages


        3) Serialization toolkit, there are a variety of options, use jdk's own serialization if not set, other optional msm-
{tools}-serializer-{version}.jar
other sequences such as kryo, javolution, xstream, flexjson Generally, third-party serialization tools do not need to implement the serializable interface

. 2. Configure the Context and add the Manager MemcachedBackupSessionManager
Context that processes the session. Context configuration search order:
1) conf/context.xml global configuration, which applies to all applications
        2) conf/[ enginename]/[hostname]/context.xml.default Global configuration, applied to all applications under the specified host
        3) conf/[enginename]/[hostname]/[contextpath].xml Only applied to the applications specified by contextpath
        4) Apply META -INF/context.xml only applies to this application
        5) conf/server.xml <Host> applies to the application specified by Context docBase.
   Therefore, I only want session management to apply to a specific application. It is best to set it in 3, 4 ways. I hope The overall effect can be set by 1, 2, and 5.





3. Find <Context></Context> in the server.xml file, and put the following configuration into this tag:

        <!-- Frequently used production environment sticky mode configuration- ->
            <Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
                    memcachedNodes="n1:(memcached1),n2:(memcached2)"
                    failoverNodes="n1"   #在另一个tomcat中改为n2,
                    requestUriIgnorePattern=".*\.(jpg|png|css|js)$"
                    memcachedProtocol="binary"
                    transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"
        />

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326537513&siteId=291194637