Apache2.2 TOMCAT7 cluster session sharing [Windows]

Source: Internet
Author: User

Apache2.2 TOMCAT7 Cluster session sharing

Download:

Apache2.2, Apache-tomcat-7.0.42.zip, tomcat-connectors-1.2.37-windows-i386-httpd-2.2.x.zip "MOD_JK"

Decompress Apache2.2, Apache-tomcat-7.0.42.zip, Tomcat-connectors-1.2.37-windows-i386-httpd-2.2.x.zip respectively

Here: C:\Apache2.2, C:\tomcat\tomcat71, C:\tomcat\tomcat72

Copy the extracted files from Comcat-connectors-1.2.37-windows-i386-httpd-2.2.x.zip mod_jk.so to C:\Apache2.2\modules.

Under C:\Apache2.2\conf, create a new file workers.properties with the following content:

#server list worker.list = controller,tomcat1,tomcat2 #========tomcat1========worker.tomcat1.port=8009 #注意这是 ajp1.3 port number, Under Tomcat server.xml configuration, default 8009. Not tomcat Web Port Worker.tomcat1.host=localhost #tomcat的主机地址, if not native, please fill in the IP address worker.tomcat1.type= Ajp13worker.tomcat1.lbfactor = 1   #server的加权比重, the higher the value, the more requests to be divided #========tomcat2========worker.tomcat2.port= 9009worker.tomcat2.host=localhostworker.tomcat2.type=ajp13worker.tomcat2.lbfactor = 1#========controller, Load balancer Controller ========worker.controller.type=lbworker.controller.balanced_workers=tomcat1,tomcat2  

Under C:\Apache2.2\conf, create a new file mod_jk.conf with the following content:

#加载mod_jk moduleloadmodule jk_module modules/mod_jk.so# Specify workers.properties file path Jkworkersfile conf/ workers.properties# Specifies that those requests be given to Tomcat processing, "controller" for the load assignment controller name specified in Workers.propertise jkmount/*.jsp Controller

Modify C:\Apache2.2\conf\httpd.conf, in the last line, add:

Include "C:\Apache2.2\conf\mod_jk.conf"

At this point, Apache modification is complete;

Next modify Tomcat, modify TOMCAT1 's C:\tomcat\tomcat71\conf\server.xml

    <name= "Catalina"  defaulthost= "localhost"  jvmroute = "TOMCAT1" > ...       <  className= "Org.apache.catalina.ha.tcp.SimpleTcpCluster"/>


Modify TOMCAT2 's Server.xml file

<ServerPort= "9005"shutdown= "SHUTDOWN">..... <ConnectorPort= "9090"Protocol= "http/1.1"ConnectionTimeout= "20000"Redirectport= "8443" />..... <ConnectorPort= "9009"Protocol= "ajp/1.3"Redirectport= "8443" />..... <Enginename= "Catalina"Defaulthost= "localhost"Jvmroute= "Tomcat2">..... <ClusterClassName= "Org.apache.catalina.ha.tcp.SimpleTcpCluster"/>

The main is to modify the port, so that it with the TOMCAT1 port to avoid conflict.

Create the Test folder, under which you created a new test.jsp, with the following content:

<%@ Page ContentType="text/html; CHARSET=GBK"%><%@ Page Import="java.util.*"%><HTML><Head><title>Cluster App Test</title></Head><Body>Server Info:<%out.println (request.getlocaladdr ()+ " : " +Request.getlocalport ()+ "<br>");%>    <%Out.println ("<br> ID" +Session.getid ()+ "<br>"); // if haveNewSession attrSet        StringDataname=Request.getparameter ("Dataname"); if(dataname! )= NULL &&dataname.length ()> 0) {            StringDataValue=Request.getparameter ("DataValue");        Session.setattribute (Dataname, DataValue); } out.println ("<b>session list</b><br>"); System.out.println ("=============tomcat 1==============="); Enumeration e=Session.getattributenames ();  while(E.hasmoreelements ()) {Stringname= (String) e.nextelement (); Stringvalue=Session.getattribute (name). toString (); OUT.PRINTLN (Name+ " = " +value+ "<br>"); SYSTEM.OUT.PRINTLN (Name+ " = " +value); }    %>    <formAction= "test.jsp"Method= "POST">Name:<inputtype=textsize=20name= "Dataname"> <BR>Value:<inputtype=textsize=20name= "DataValue"> <BR> <inputtype=submit>    </form></Body></HTML>

Copy the test folder to C:\tomcat\tomcat71\webapps, C:\tomcat\tomcat72\webapps, respectively.

Start or restart TOMCAT1, TOMCAT2, Apache, and no order respectively.

Browser input:

http://localhost/test/test.jsp

Observe the effect.

Done.

-----------------

Apache2.2 TOMCAT7 cluster session sharing [Windows]

Related Article

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.