First, the premise
Reference Blog : http://blog.csdn.net;
related package download, including the need for Lib jar package : http://pan.baidu.com/;
Environment : CentOS 6.5 (64-bit), Jdk8_8u5, tomcat7.054, nginx1.47, libevent-2.0, memcached-1.4.20
– Two virtual machines
10.1.1.127//tomcat,nginx,memcached
10.1.1.128//Tomcat
Second, the configuration
(1), the configuration of the Tomcat machine
1, uninstall the JDK, using the RPM package installation
Bulk uninstall of your own JDK-related packages
Rpm–qa |grep java | Xargs rpm-e--nodeps
2. RPM Installation
RPM-IVH jdk-8u5-linux-x64.rpm//default installation in/usr/java
MV change to/USR/JAVA/JDK
java-version//Verify Installation success
3. Write the person environment disposition
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. Decompression 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///Open tomcat, test Tomcat installation success
5. Import msm-1.7 packages to tom/lib/(tomcat for each node)
Refer to this Blog
6. Change Tomcat session save mode (Non-sticky,kryo)
– The following is added to the configuration conf/context.xml 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=" 1000 "transcoderfactoryclass=" De.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory "
/>
Parameter Reference Official document
Chapters in Https://code.google.com/p/memcached-session-manager/wiki/SetupAndConfiguration overview over Memcached-session-manager Configuration Attributes
(2) Nginx Installation Configuration
1. Source Package Installation
#yum install pcre*//nginx dependent 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 to implement the two tomcat servers behind the load Balancing agent
nginx.conf Configuration
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;
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;
}
}
(3). Installation of memcached
Install Libevent first (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
Boot-D background run –m memory size –p port –c Maximum concurrent number
/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
Reference Link: http://hxq0506.iteye.com/blog/1388971
Third, testing
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 node
%>
Result: Session remains unchanged
This article turns from: Http://my.oschina.net/u/1791256/blog/283064?fromerr=ZsKHawuG