Linux under Nginx+tomcat+msm+memcached Implementation session sharing (test) __linux

Source: Internet
Author: User
Tags memcached tomcat server
Test machine: 192.168.18.207, 192.168.18.208,192.168.18.209
Software configuration:
192.168.18.207 nginx/1.9.4
192.168.18.208 tomcat-7.0.64 memcached-1.2.0
192.168.18.209 tomcat-7.0.64 memcached-1.2.0

System version:

Click (here) to collapse or open [root@localhost ~]# cat/proc/version Linux version 3.10.0-229.el7.x86_64 (builder@kbuilder.dev.centos.org (gcc version 4.8.2 20140120 (Red Hat 4.8.2-16) (gcc)) #1 SMP Fri Mar 6 11:36:42 UTC 2015
1. Install Nginx
server:192.168.18.207
Download nginx-1.9.4.tar.gz

Click (here) to collapse or open TAR-ZXVF nginx-1.9.4.tar.gz
./configure--prefix=/usr/local/nginx--user=nginx--group=nginx--with-http_stub_status_module--with-pcre=/tools/ pcre-8.36/
Make && make install modify configuration file nginx.conf, add upstream, Proxy_pass, etc.
Proxy_set_header X-real-ip $remote _addr; --This can get the real IP address of the client via%{x-real-ip}i in Tomcat Server.xml

Click (here) to collapse or open upstream tomcat{
Server 192.168.18.208:8080;
Server 192.168.18.209:8080;
}
server {
Listen 80;
server_name localhost;
#charset Koi8-r;

Location/{
root HTML;
Index index.html index.htm;
Proxy_pass Http://tomcat;
Proxy_set_header X-real-ip $remote _addr;
Access_log Logs/test.log;
}
Error_page 502 503 504/50x.html;
Location =/50x.html {
root HTML;
}
Start Nginx
./nginx
2. Install memcached
server:192.168.18.208/192.168.18.209
Download libevent-1.4.14b-stable.tar.gz, memcached-1.2.0.tar.gz
Libevent-1.4.14b-stable.tar.gz

Click (here) to collapse or open./configure--prefix=/usr
Make && make INSTLL configuration environment variable export ld_library_path=/usr/lib
Memcached-1.2.0.tar.gz

Click (here) to collapse or open./configure--prefix=/usr/local/memcached
Make && make install start memcached
./memcached-d-uroot-p 11211-m 20-l 192.168.18.208-c 200-p/usr/local/memcached/mem.pid

3. Install Tomcat
server:192.168.18.208/192.168.18.209
Download apache-tomcat-7.0.64.tar.gz

Click (here) to collapse or open TAR-ZXVF apache-tomcat-7.0.64.tar.gz
MV Apache-tomcat-7.0.64/usr/local/tomcat
Modify configuration file Conf/contex.xml
Add to

Click (here) to collapse or open <manager classname= "De.javakaffee.web.msm.MemcachedBackupSessionManager"
Memcachednodes= "n1:192.168.18.208:11211,n2:192.168.18.209:11211"
failovernodes= "N1"
Requesturiignorepattern= ". *\. (ICO|PNG|GIF|JPG|CSS|JS) $ "
Transcoderfactoryclass= "De.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory"
/> Here use viscous session, Failovernodes = "N1" refers to the priority of the sessions stored in the N2. 209 Configuration Failovernodes= "N2"
Download MSM
Memcached-session-manager-1.6.1.jar
Memcached-session-manager-tc7-1.6.1.jar
Spymemcached-2.7.3.jar
Due to the Javolution method of serialization, it is also necessary
Msm-javolution-serializer-1.6.1.jar
Javolution-5.4.3.1.jar
Copy all to Tomcat Lib
Start Tomcat
4. Test
Test.jsp put it under the webapps/root.
192.168.18.208

Click (here) to collapse or open sessionid:<%=session.getid ()%>
<BR>
Sessionip:<%=request.getservername ()%>
<BR>
Sessionport:<%=request.getserverport ()%>
<%
Out.println ("This is Tomcat Server 1");
%> 192.168.18.209 changed to Server 2

Test results:
1. The first visit to the Http://192.168.18.207/test.jsp page appears as follows:
Sessionid:4cfbdb9cd9e7e19790f1567dd0ba84e7-n2
Sessionip:tomcat
Sessionport:80 This is Tomcat Server 1
Description Nginx will request forward to the N2 (209), the session exists on the continuous refresh, just server change, SessionID unchanged
2. Close 209 Network Systemctl stop Network.service
Sessionid:4cfbdb9cd9e7e19790f1567dd0ba84e7-n1
Sessionip:tomcat
Sessionport:80 This is Tomcat Server 1
As above SessionID has not changed, but has been cut to N1
Other tests:
(1) When all memcached are turned off, the SessionID remains unchanged, and no test lasts for much time.
(2) Start Tomcat First, do not start memcached, view the log will find that there is a persistent request connection memcached error, start memcached back to normal.

Installation issues:
The 1.CENTOS7 firewall uses the firewall to shut down the firewall.
Systemctl Stop Firewalld
Systemctl Stop Iptables
2. Install memcached need to configure environment variables
Ld_library_path=/usr/lib

This test refers to the following information:
http://chenzhou123520.iteye.com/blog/1650212
http://blog.csdn.net/shimiso/article/details/8979044

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.