NGINX + TOMCAT7 + MEMCACHED for session sharing

Source: Internet
Author: User
Tags memcached nginx reverse proxy

tomcat7.0+ NGINX + MEMCACHED + Memcached-session-manager for session sharing

http://blog.csdn.net/nerissa/article/details/18961361; Reference Blog

Http://pan.baidu.com/s/1pJlZ0mB//related package download, including the required Jar package Lib

Environment: CentOS 6.5 (64-bit), Jdk8_8u5, tomcat7.054, nginx1.47, libevent-2.0, memcached-1.4.20

10.1.1.127//tomcat,nginx,memcached

10.1.1.128//Tomcat

Tomcat machine configuration

1. Uninstall your own JDK with RPM package installation

Rpm–qa |grep java | Xargs rpm-e--nodeps//Bulk uninstall of your own JDK-related packages

2, RPM installation

RPM-IVH jdk-8u5-linux-x64.rpm//default installation in/usr/java

Change the MV name to/USR/JAVA/JDK

Java-version//Verify the installation was successful

3. Write Environment

Vim/etc/profile

Java_home=/usr/java/jdk

Jre_home=/usr/java/jdk/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

Source/etc/profile//Environment effective

4. Unzip the Tomcat test run

TAR–ZXF apache-tomcat-7.0.54.tar.gz& #160; -c/usr/local

MV apache-tomcat-7.054 Tomcat

Vim/etc/sysconfig/iptables//Firewall open 8080 port

-A rh-firewall-1-input-m state--state new-m tcp-p TCP--dport 8080-j ACCEPT

Service Iptables Restart

http://10.1.1.127:8080///Turn on Tomcat to test the Tomcat installation success

5. Import the msm-1.7 package to tom/lib/(the Tomcat node should be put

http://chenzhou123520.iteye.com/blog/1650212//reference Blog

6. Change the Tomcat session Save method (Non-sticky,kryo

The following contents are added to the configuration file.

Vim Conf/context.xml

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

Memcachednodes= "n1:10.1.1.217:11211"

Sticky= "false"

Lockingmode= "Auto"

Sessionbackupasync= "false"

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

sessionbackuptimeout= "transcoderfactoryclass=" de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory "

/>

Parameter Usage official documentation

Https://code.google.com/p/memcached-session-manager/wiki/SetupAndConfiguration

Section overview over Memcached-session-manager configuration attributes

Nginx Installation Configuration

1. Source Package Installation

#yum Install pcre*//nginx relies on Pcre class library

#useradd Nginx

#tar xf/share/soft/lamp/nginx/nginx-1.4.7.tar.gz-c/usr/src/

#cd/usr/src/nginx-1.4.7

#./configure--prefix=/usr/local/nginx--user=nginx--group=nginx--with-http_gzip_static_module--with-http_stub_ Status_module

# Make && make install

2.nginx reverse proxy, implement load balancer agent behind two tomcat servers

User Nginx Nginx;

Worker_processes 5;

Error_log Logs/error.log;

#error_log Logs/error.log Notice;

#error_log Logs/error.log Info;

PID Logs/nginx.pid;

Events {

Worker_connections 1024;

Use Epoll;

}

HTTP {

Upstream Session {

Server 10.1.1.217:8080 weight=1 max_fails=2 fail_timeout=30s;

Server 10.1.1.218:8080 weight=1 max_fails=2 fail_timeout=30s;

}

server {

Listen 80;

server_name 10.1.1.217;

root/nginxroot/;

Location ~ \. (txt|jsp) $ {

Proxy_pass http://session;

}

Proxy_set_header X-real-ip $remote _addr;

Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;

Proxy_set_header Host $http _host;

}

}

mkdir/nginxroot/

The above is a simple implementation of the JSP access to the balanced scheduling, the experiment casually changed

memcached installation//installation Libevent (memcached dependent libevent)

1. Installation

#tar ZXVF libevent-2.0.21-stable.tar.gz

#cd & #160; ZXVF libevent-2.0.21-stable

#./configure--PREFIX=/USR

#make && make Install

# tar ZXVF memcached-1.4.20.tar.gz

#cd memcached-1.4.20

#./configure--WITH-LIBEVENT=/USR

#make && make Install

2. Start, Close command

Start-D background run –m memory size –p port –c max concurrency

/usr/local/bin/memcached-d-M 128-u root-p 11211-c 256-p/var/run/memcached.pid

Kill ' Cat/var/run/memcached1.pid ' & #160; Shut down

http://hxq0506.iteye.com/blog/1388971//reference links

Test:

Boot order tomcat–nginx–memcached

Test page test.jsp, put webapps/root:

Server Info:

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

<br>

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

<br>

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

<br>

<%

OUT.PRINTLN ("127"); Mark Back-end nodes

%>

Result: Session remains unchanged

NGINX + TOMCAT7 + MEMCACHED for session 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.