CentOS 6.5 Tomcat7.0.57 session sharing through msm

Source: Internet
Author: User
Tags couchbase i18n

CentOS 6.5 Tomcat7.0.57 session sharing through msm

CentOS 6.5 Tomcat7.0.57 session sharing through msm

Generally, session sharing is implemented. The most common method is through memcached-session-manager. Next, let's talk about how to share sessions through memcached-session-manager.

Download the jar package required for tomcat7 session sharing:

------------------------------------------ Split line ------------------------------------------

Free in http://linux.bkjia.com/

The username and password are both www.bkjia.com

The specific download directory is in the/June/27th/CentOS 6.5 system and tomcat 7.0.57 is built. session sharing is achieved through msm/

For the download method, see

------------------------------------------ Split line ------------------------------------------

First, create a directory for storing software and enter the directory.

[Root @ node1 ~] # Mkdir-p/taokey/tools
[Root @ node1 ~] # Cd/taokey/tools/

2.upload the downloaded apache-tomcat-7.0.57.tar.gzand jdk-7u71-linux-x64.gz packages to the server.
[Root @ node1 tools] # ls
Apache-tomcat-7.0.57.tar.gz jdk-7u71-linux-x64.gz
[Root @ node1 tools] # tar-zxf apache-tomcat-7.0.57.tar.gz
[Root @ node1 tools] # tar-zxf jdk-7u71-linux-x64.gz
[Root @ node1 tools] # ls
Apache-tomcat-7.0.57 jdk1.7.0 _ 71

3. Create the/data directory, rename tomcat, and move tomcat and jdk to the data directory.
[Root @ node1 tools] # mv apache-tomcat-7.0.57 node1
[Root @ node1 tools] # mkdir/data
[Root @ node1 tools] # cp-r jdk1.7.0 _ 71 node1/data

4. Configure the jdk environment variable of the system.
[Root @ node1 data] # tail-7/etc/profile
JAVA_HOME =/data/jdk1.7.0 _ 71
JRE_HOME =/data/jdk1.7.0 _ 71/jre
PATH = $ PATH: $ JAVA_HOME/bin: $ JRE_HOME/bin
CLASSPATH =: $ JAVA_HOME/lib/dt. jar: $ JAVA_HOME/lib/tools. jar: $ JRE_HOME/lib
Export JAVA_HOME JRE_HOME PATH CLASSPATH
Export PATH = $ PATH: JAVA_HOME/bin
Export JAVA_HOME
[Root @ node1 data] # source/etc/profile

5. Modify the default project path.
[Root @ node1 data] # vim node1/conf/server. xml + 125
<Host name = "localhost" appBase = "/data/" # The default value is webapps. I changed it to the/data/directory.

6. Add execution permissions to the tomcat startup and closing scripts by default.
[Root @ node1 data] # cd node1/bin/
[Root @ node1 bin] # chmod + x startup. sh
[Root @ node1 bin] # chmod + x shutdown. sh

7. start tomcat and check whether it runs successfully.
[Root @ node1 bin] #./startup. sh
Using CATALINA_BASE:/data/node1
Using CATALINA_HOME:/data/node1
Using CATALINA_TMPDIR:/data/node1/temp
Using JRE_HOME:/data/jdk1.7.0 _ 71/jre
Using CLASSPATH:/data/node1/bin/bootstrap. jar:/data/node1/bin/tomcat-juli.jar
Tomcat started.
[Root @ node1 bin] # ps-ef | grep java
Root 2036 1 83 00:00:04 pts/1/data/jdk1.7.0 _ 71/jre/bin/java-Djava. util. logging. config. file =/data/node1/conf/logging. properties-Djava. util. logging. manager = org. apache. juli. classLoaderLogManager-Djava. endorsed. dirs =/data/node1/endorsed-classpath/data/node1/bin/bootstrap. jar:/data/node1/bin/tomcat-juli.jar-Dcatalina. base =/data/node1-Dcatalina. home =/data/node1-Djava. io. tmpdir =/data/node1/temp org. apache. catalina. startup. bootstrap start
Root 2050 1907 0 00:00:00 pts/1 grep java

8. Check the default listening port of tomcat.
[Root @ node1 bin] # netstat-anpt | grep java
Tcp 0 0: 8080: * LISTEN 2036/java
Tcp 0 0: ffff: 127.0.0.1: 8005: * LISTEN 2036/java
Tcp 0 0: 8009: * LISTEN 2036/java

9. Create a test webpage under the project path and test whether the webpage can be opened.
[Root @ node1 bin] # mkdir/data/ROOT
[Root @ node1 bin] # touch/data/ROOT/test.html
[Root @ node1 bin] # echo "hello world">/data/ROOT/test.html
[Root @ node1 bin] # cat/data/ROOT/test.html
Hello world
[Root @ node1 ~] # Curl-I 192.168.1.15: 8080/test.html
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Accept-Ranges: bytes
ETag: W/"12-1421038003000"
Last-Modified: Mon, 12 Jan 2015 04:46:43 GMT
Content-Type: text/html
Content-Length: 12
Date: Mon, 12 Jan 2015 04:48:16 GMT
[Root @ node1 ~] # Wget 192.168.1.15: 8080/test.html
[Root @ node1 ~] # Cat test.html
Hello world

Tomcat7.0.57 is built.

The First tomcat instance node1 has been set up, and the tomcat instance node2. Tomcat is easy to build and will not be described here. After the two tomcat instances (node1 and node2) are set up, the following uses memcache and msm for session sharing.

10. Install memcahce.
Cd/taokey/tools/
Curl-O http://www.monkey.org /~ Provos/libevent-2.0.13-stable.tar.gz
Tar-zxvf libevent-2.0.13-stable.tar.gz
Cd libevent-2.0.13-stable
./Configure -- prefix =/usr
Make & make install
Curl-O http://www.danga.com/memcached/dist/memcached-1.4.0.tar.gz
Tar-zxvf memcached-1.4.0.tar.gz
Cd memcached-1.4.0
./Configure -- with-libevent =/usr/
Make
Make install
/Usr/local/bin/memcached-d-m 200-u root-c 256-p 11211-P/tmp/memcache. pid

Test whether Node 1 and node 2 connect to memcache normally.
[Root @ node1 ~] # Telnet to 192.168.1.84 11211
Trying 192.168.1.84...
Connected to 192.168.1.84.
Escape character is '^]'.

[Root @ node2 ~] # Telnet to 192.168.1.84 11211
Trying 192.168.1.84...
Connected to 192.168.1.84.
Escape character is '^]'.

After testing, the memcache service is normal.

To achieve session sharing, You need to upload the memcached-session-manager jar package required by Tomcat 7.

11. All jar packages including tomcat built-in and shared session are listed here:
[Root @ node1 ~] # Cd/data/node1/lib/
[Root @ node1 lib] # ls
Annotations-api.jar jasper-el.jar minlog-1.2.jar tomcat-dbcp.jar
Catalina-ant.jar jasper. jar msm-kryo-serializer-1.6.5.jar tomcat-i18n-es.jar
Catalina-ha.jar javolution-5.4.3.1.jar reflectasm-0.9.jar tomcat-i18n-fr.jar
Catalina. jar jsp-api.jar servlet-api.jar tomcat-i18n-ja.jar
Catalina-tribes.jar kryo-1.03.jar spymemcached-2.10.2.jar tomcat-jdbc.jar
Couchbase-client-1.2.2.jar kryo-serializers-0.10.jar tomcat7-websocket.jar tomcat-util.jar
Ecj-4.4.jar memcached-session-manager-1.6.5.jar tomcat-api.jar websocket-api.jar
El-api.jar memcached-session-manager-tc7-1.6.5.jar tomcat-coyote.jar
[Root @ node1 lib] # du-sh.
8.2 M.

[Root @ node2 ~] # Cd/data/node2/lib/
[Root @ node2 lib] # ls
Annotations-api.jar jasper-el.jar minlog-1.2.jar tomcat-dbcp.jar
Catalina-ant.jar jasper. jar msm-kryo-serializer-1.6.5.jar tomcat-i18n-es.jar
Catalina-ha.jar javolution-5.4.3.1.jar reflectasm-0.9.jar tomcat-i18n-fr.jar
Catalina. jar jsp-api.jar servlet-api.jar tomcat-i18n-ja.jar
Catalina-tribes.jar kryo-1.03.jar spymemcached-2.10.2.jar tomcat-jdbc.jar
Couchbase-client-1.2.2.jar kryo-serializers-0.10.jar tomcat7-websocket.jar tomcat-util.jar
Ecj-4.4.jar memcached-session-manager-1.6.5.jar tomcat-api.jar websocket-api.jar
El-api.jar memcached-session-manager-tc7-1.6.5.jar tomcat-coyote.jar
[Root @ node2 lib] # du-sh.
8.2 M.

12. modify the configuration file context. xml of two tomcat servers.
The modified tomcat node1 configuration file
[Root @ node1 ~] # Cd/data/node1/conf/
[Root @ node1 conf] # tail context. xml
<! --
<Valve className = "org. apache. catalina. valves. CometConnectionManagerValve"/>
-->
<Manager className = "de. javakaffee. web. msm. MemcachedBackupSessionManager"
MemcachedNodes = "n1: 192.168.1.84: 11211"
RequestUriIgnorePattern = ". * \. (png | gif | jpg | css | js | ico | jpeg | htm | html) $"
SessionBackupTimeout = "1800000"
TranscoderFactoryClass = "de. javakaffee. web. msm. serializer. kryo. KryoTranscoderFactory"
/>
</Context>

The modified tomcat node2 configuration file
[Root @ node2 ~] # Cd/data/node2/conf/
[Root @ node2 conf] # tail context. xml
<! --
<Valve className = "org. apache. catalina. valves. CometConnectionManagerValve"/>
-->
<Manager className = "de. javakaffee. web. msm. MemcachedBackupSessionManager"
MemcachedNodes = "n1: 192.168.1.84: 11211"
RequestUriIgnorePattern = ". * \. (png | gif | jpg | css | js | ico | jpeg | htm | html) $"
SessionBackupTimeout = "1800000"
TranscoderFactoryClass = "de. javakaffee. web. msm. serializer. kryo. KryoTranscoderFactory"
/>
</Context>

13. After the modification, create an index. jsp document to test session sharing and restart two tomcat instances.
Restart instance node1.
[Root @ node1 ROOT] # cat index. jsp
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> Tomcat + memcached shared session test </title>
</Head>
<Body>
SessionID: <% = session. getId () %>
<BR>
SessionIP: <% = request. getServerName () %>
<BR>
SessionPort: <% = request. getServerPort () %>
<BR>
<%
Out. println ("This is Tomcat Server 8081 .");
%>
% </Body>
% </Html>
/Data/node1/bin/shutdown. sh
[Root @ node1 ~] # Ps-ef | grep java
Root 9063 1907 0 00:00:00 pts/1 grep java
/Data/node1/bin/startup. sh
[Root @ node1 ~] # Netstat-anpt | grep 8080
Tcp 0 0: 8080: * LISTEN 9072/java
Tcp 0 0: ffff: 127.0.0.1: 8080: ffff: 127.0.0.1: 40496 TIME_WAIT-

14. Restart the instance tomcat node2.
[Root @ node2 ROOT] # cat index. jsp
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> Tomcat + memcached shared session test </title>
</Head>
<Body>
SessionID: <% = session. getId () %>
<BR>
SessionIP: <% = request. getServerName () %>
<BR>
SessionPort: <% = request. getServerPort () %>
<BR>
<%
Out. println ("This is Tomcat Server 8081 .");
%>
% </Body>
% </Html>
[Root @ node2 ~] #/Data/node2/bin/shutdown. sh
[Root @ node2 ~] # Ps-ef | grep java
Root 2830 2081 0 00:00:00 pts/0 grep java
[Root @ node2 ~] #/Data/node2/bin/startup. sh
[Root @ node2 ~] # Netstat-anpt | grep 8080
Tcp 0 0: 8080: * LISTEN 2840/java

15. Access the nginx Proxy Server IP address, 192.168.1.15

16. Stop node1 and test 192.168.1.15.
[Root @ node1 ~] #/Data/node1/bin/shutdown. sh
Using CATALINA_BASE:/data/node1
Using CATALINA_HOME:/data/node1
Using CATALINA_TMPDIR:/data/node1/temp
Using JRE_HOME:/data/jdk1.7.0 _ 71/jre
Using CLASSPATH:/data/node1/bin/bootstrap. jar:/data/node1/bin/tomcat-juli.jar
[Root @ node1 ~] # Ps-ef | grep java
Root 9132 1907 0 00:00:00 pts/1 grep java

17. The session information is still the original one. Now let's enable node1 and disable node2. In the test, the session information,
[Root @ node1 ~] #/Data/node1/bin/startup. sh
Using CATALINA_BASE:/data/node1
Using CATALINA_HOME:/data/node1
Using CATALINA_TMPDIR:/data/node1/temp
Using JRE_HOME:/data/jdk1.7.0 _ 71/jre
Using CLASSPATH:/data/node1/bin/bootstrap. jar:/data/node1/bin/tomcat-juli.jar
Tomcat started.
[Root @ node1 ~] # Netstat-anpt | grep java
Tcp 0 0: 8080: * LISTEN 9144/java
Tcp 0 0: ffff: 127.0.0.1: 8005: * LISTEN 9144/java
Tcp 0 0: 8009: * LISTEN 9144/java
Tcp 0 0: ffff: 192.168.1.15: 58421: ffff: 192.168.1.84: 11211 ESTABLISHED 9144/java
Tcp 0 0: ffff: 192.168.1.15: 58418: ffff: 192.168.1.84: 11211 ESTABLISHED 9144/java
Tcp 0 0: ffff: 192.168.1.15: 58419: ffff: 192.168.1.84: 11211 ESTABLISHED 9144/java
Tcp 0 0: ffff: 192.168.1.15: 58420: ffff: 192.168.1.84: 11211 ESTABLISHED 9144/java
[Root @ node2 ~] #/Data/node2/bin/shutdown. sh
Using CATALINA_BASE:/data/node2
Using CATALINA_HOME:/data/node2
Using CATALINA_TMPDIR:/data/node2/temp
Using JRE_HOME:/data/jdk1.7.0 _ 71/jre
Using CLASSPATH:/data/node2/bin/bootstrap. jar:/data/node2/bin/tomcat-juli.jar
[Root @ node2 ~] # Ps-ef | grep java
Root 2896 2081 0 00:00:00 pts/0 grep java

Session sharing is successful.

Install JDK + Tomcat in RedHat Linux 5.5 and deploy Java Projects

Tomcat authoritative guide (second edition) (Chinese/English hd pdf + bookmarks)

Tomcat Security Configuration and Performance Optimization

How to Use Xshell to view Tomcat real-time logs with Chinese garbled characters in Linux

Install JDK and Tomcat in CentOS 64-bit and set the Tomcat Startup Procedure

Install Tomcat in CentOS 6.5

Tomcat details: click here
Tomcat: click here

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.