Although once done, but often forget, special record it for follow-up review.
Related information:
Linux under the Tomcat run environment build see another blog post: http://blog.csdn.net/xiadi934/article/details/50911175
Tomcat7.0 official cluster documentation, details of the parameters are available here: http://tomcat.apache.org/tomcat-7.0-doc/cluster-howto.html
Linux under the Nginx + tomcat still have problems, please bypass.
Ideas
- Use two machines, native (window,ip:192.168.1.108) + virtual machines (linux,ip:192.168.25.132)
- Deploying Nginx + TOMCAT7 + web,window on Linux: Tomcat7 + Web
- Refer to the Tomcat official cluster example, using Tomcat itself to bring the cluster with session sharing
Realize
- Window on tomcat under Server.xml file configuration, the rest of the configuration is unchanged, only modify the following configuration
<Enginename="Catalina"defaulthost="localhost"jvmroute ="tomcat127"><ClusterclassName="Org.apache.catalina.ha.tcp.SimpleTcpCluster" Channelsendoptions="8"><ManagerclassName="Org.apache.catalina.ha.session.DeltaManager" Expiresessionsonshutdown="false"notifylistenersonreplication="true" / ><ChannelclassName="Org.apache.catalina.tribes.group.GroupChannel"> <membershipclassName="Org.apache.catalina.tribes.membership.McastService" Address= "228.0.0.4"port="45564"frequency=" "droptime" = "/> "
<ReceiverclassName="Org.apache.catalina.tribes.transport.nio.NioReceiver" Address="192.168.1.108"port="4000"autobind=" Selectortimeout="maxthreads" = "6" />
<SenderclassName=" Org.apache.catalina.tribes.transport.ReplicationTransmitter "><TransportclassName=" Org.apache.catalina.tribes.transport.nio.PooledParallelSender " />
Sender
><interceptorclassName=" Org.apache.catalina.tribes.group.interceptors.TcpFailureDetector " /><interceptorclassName=" Org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor " />
Channel
><ValveclassName="Org.apache.catalina.ha.tcp.ReplicationValve"Filter ="" /><ValveclassName="Org.apache.catalina.ha.session.JvmRouteBinderValve" / ><DeployerclassName="Org.apache.catalina.ha.deploy.FarmWarDeployer" tempdir="/tmp/war-temp/"deploydir="/tmp/war-deploy/"Watchdir ="/tmp/war-listen/"watchenabled="false" /><clusterlistenerclassName=" Org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener "/><clusterlistenerclassName="Org.apache.catalina.ha.session.ClusterSessionListener" />
Cluster
>...
Engine
>
- Linux on the Tomcat under Server.xml file configuration, the rest of the configuration is unchanged, plus the same configuration
"Catalina"defaulthost=
"localhost"Jvmroute=
"tomcat132">
"Org.apache.catalina.ha.tcp.SimpleTcpCluster" channelsendopti> "8" >
"Org.apache.catalina.ha.session.DeltaManager" expiresessi> "false" notifylisteners> "true" />
"Org.apache.catalina.tribes.group.GroupChannel" >
"Org.apache.catalina.tribes.membership.McastService" address=
"228.0.0.4" port=
45564 frequency=
"$" droptime=
"All" />
"org.apache.catalina.tribes.transport.nio.NioReceiver" address=
"192.168.25.132" port=
4000 autobind=
"" selectortimeout=
"All" maxthreads=
"6" />!--virtual machine LAN IP-->
...
...
- Modify Nginx configuration, add load Balancer
Upstream backendserver{Ip_hash;#可选, select the Web server based on the source IP, omit the Web server by default round robin modeServer127.0. 0. 1:8080;#虚拟机本机TomcatServer192.168. 1. 108:8080;#Window上Tomcat}Server{#设置监听端口Listen the; CharSet utf-8;#设置服务器域名 (IP access and multi-domain access may not be set)#server_name _*;#server_name www.test.com;#开启shtml支持SSI on; Ssi_silent_errors on; Ssi_types text/shtml;#设置主访问日志#access_log Logs/access.log main;access_log/dev/NULL; Error_page404/404.html Error_page -502503504/ -x.html; Location/{Proxy_pass http://backendserver;Include proxy.conf; }}
- Modify the two Tomcat under Conf/web.xml and add the following code to the tail
<distributable/>
- Add a test page, create a folder test under two Tomcat/webapps, and create a index.jsp with the following code
<%@ page language="java" import="java.util.*" pageencoding= "Utf-8"%><%String path = request. Getcontextpath (); String basepath = request. Getscheme () +"://"+request. getServerName () + ":"+request. Getserverport () +path+"/";%><html><head><basehref="<%=basePath%>"><title>Home
title
><metahttp-equiv="Pragma"content="No-cache"><metahttp-equiv="Cache-control"content="No-cache" ><metahttp-equiv="Expires"content="0"><metahttp-equiv="keywords"content="Keyword1,keyword2, Keyword3 "><metahttp-equiv="description"content="This is my page" >
Head
><body><p>SessionID:<%=session.getid ()%>
P
><p>Session creation Time:<%=session.getcreationtime ()%>
P
><p>Server IP:<%=request. Getremotehost ()%>
P
>
Body
>
HTML
>
Test
Starting two Tomcat, the test results are as follows, which indicates that the configuration load + cluster +session share was successful.
Nginx default is the nearest IP Access native Linux under Tomcat, as follows
Turn off Tomcat under Linux, and after the Refresh, Access window under Tomcat
Please note that viewing the session creation time is consistent and the instructions are successful.
'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
'). Text (i)); }; $numbering. FadeIn (1700); }); });
The above describes the Tomcat cluster and session sharing + Nginx load, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.