In this paper, the basic reference from the easy implementation of APACHE,TOMCAT cluster and load balancing, through the actual experience recorded, encountered some discrepancies, as well as individual places according to personal habits, so to a certain extent failed to maintain the integrity of the original, but also hope that the original Haihan.
Because there are more stickers in the original text, if you do not want to personally do not want to see the configuration effect, you can view the original text.
One: Software Environment
1. Apache:apache 2.0.55 (Download by http://httpd.apache.org/) (Click to download Apache 2.0.55)
2. Tomcat:tomcat 5.5.25 (Download by http://tomcat.apache.org/) (Click to download Tomcat 5.5.25 zip version)
3. MOD_JK: Find the Tomcat connectors link under the page http://tomcat.apache.org/Download header (click Download mod_jk-apache-2.0.55.so) and look like a Unix /linux under the dynamic library, the actual should be a Win32 DLL dynamic library, presumably to maintain the consistency of the different platform configuration, only use this extension.
Second: Load balancer with Apache shunt, the request according to weight and then load tomcat1,tomcat2 ... To deal with
1. Install Apache,tomcat I have Apache installed in D:/apache Group/apache2 extract two points tomcat, respectively, in D:/apache Group/tomcat5_1,d:/apache Gr Oup/tomcat5_2 if you cluster different versions of Tomcat, the directory will be available Tomcat4_3 (third Tomcat server with version 4.x), Tomcat6_4 (third Tomcat server version 6.x), which is the custom of Unmi.
2. Modify the Apache configuration file http.conf in the Apache installation directory conf directory to find http.conf, at the end of the file add the following sentence on it
include conf/mod_jk.conf
3. http.conf The new mod_jk.conf file in the same directory as the following
#加载mod_jk Module LoadModule jk_module modules/mod_jk-apache-2.0.55.so #指定 workers.properties file path jkworkersfile con F/workers.properties #指定那些请求交给tomcat处理, "controller" Jkmount/*.jsp Controller for the load distribution controller specified in Workers.propertise
If you want to specify *.do, you can also divert it by adding a line Jkmount/*.do controller
If you want to divert all your requests, just write the Jkmount/* Controller
4. Create a new workers.properties file in the http.conf directory with the following content (you may want to remove comments that do not start at the beginning)
worker.list = controller,tomcat1,tomcat2 #server list #======= =tomcat1======== worker.tomcat1.port=8009 #ajp13 port number, server.xml configuration under Tomcat, default 8009 worker.tomcat1.host=localhost #tomcat的主机地址, if not for this machine, please fill in the IP address worker.tomcat1.type=ajp13 worker.tomcat1.lbfactor = 1 #server的加权比重, the higher the value, the more requests to be divided #========tomcat2======== worker.tomcat2.port=8109 #ajp13 port number, server.xml configuration under Tomcat, default 8009 worker.tomcat2.host= localhost #tomcat的主机地址, if not for this machine, please fill in the IP address worker.tomcat2.type=ajp13 worker.tomcat2.lbfactor = 2 #server的加权比重, the higher the value, please More #========controller, Load Balancer controller ======== worker.controller.type=lb worker.controller.balanced_workers=tomcat1,t OMCAT2 #指定分担请求的tomcat worker.controller.sticky_session=1
5. Modify the Tomcat configuration file Server.xml If you are a horizontal cluster, that is, install Tomcat,tomcat on different PCs with a number of installs, you can avoid having to modify the Tomcat configuration file. I am here to install two Tomcat on the same computer, to achieve a vertical cluster mode, so you must modify one of the settings to avoid port conflicts, according to the reference article is the original 9 port number to start with 9 port number, but on my machine if the port number starting with 9, for example, 9080, 9082 will conflict with my WebSphere Application server configuration, so the strategy I'm taking here is to change the third bit of the original port number to 1, such as 8080 to 8180.
Open Tomcat2/conf/server.xml File
1) Turn off Tomcat's listening port to change from 8005 to 8105<server port= "8005" shutdown= "Shutdown" >Switch<server port= "8105" shutdown= "Shutdown" >
2) Change the HTTP service port number from 8080 to 8180<!--Define a non-ssl http/1.1 Connector on port 8080--<connector port= "8080"Change the 8080 here to8180
3) Change the AJP port number from 8009 to 8109.<!--Define an AJP 1.3 Connector on port 8009--<connector port= "8009"Change the 8009 here to81094) Change the HTTP proxy port from 8082 to 8182 (This configuration is commented out by default, you can skip this step) to find<connector port= "8082"Change the 8082 here to81825) write a test JSP to create a directory testcluster, a new test.jsp inside, the content is
<% System.out.println ("==========================="); %> put Testcluster under Tomcat1,tomcat2 WebApps.
6) Start Apache,tomcat1,tomcat2, test through http://localhost/TestCluster/test.jsp access, refresh several times on the page, view Tomcat1 and Tomcat2 windows, You will see a line of "===========================" printed, and statistically, approximately twice times the number of TOMCAT2 printed in TOMCAT1, you can see that the request is TOMCAT1, TOMCAT2 load Balancing According to the different weights of the shunt processing.
For the following cluster configuration, please change the weight of TOMCAT1 and tomcat2 to the same as the workers.properties, so that the request is evenly distributed, it will be easy to see the effect of the experiment.
Three: Configure the cluster to configure only load balancing not yet, but also to copy the session, that is, any one of the Tomcat added session is to be replicated to other Tomcat, the cluster of Tomcat has the same session
1. Modify the TOMCAT1, Tomcat2 Server.xml, the cluster part of the configuration, that is, the <Cluster> node in the comment box, and change the TOMCAT2 4001 port to 4002 to avoid conflict with Tomcat , of course, if it is two computers, you do not have to change the port, remove the comment symbol can be canceled to the following
<textarea class="xml" style="width: 100%;" name="codec" rows="3"><cluster classname= "Org.apache.catalina.cluster.tcp.SimpleTcpCluster" Managerclassname= " Org.apache.catalina.cluster.session.DeltaManager "expiresessionsonshutdown=" false "...... <clusterlis Tener classname= "Org.apache.catalina.cluster.session.ClusterSessionListener"/></cluster></textarea>Before and after the comment mark <!----, enable the configuration to achieve session replication between servers.
2. Increased jvmroute for TOMCAT1 and Tomcat2(Skip this step first and have the energy to experiment) in TOMCAT1 and Tomcat2 of the Server.xml file, locate<engine name= "Catalina" defaulthost= "localhost" >respectively, replace<engine name= "Catalina" defaulthost= "localhost" jvmroute= "Tomcat1" >And<engine name= "Catalina" defaulthost= "localhost" jvmroute= "Tomcat2" >However, the actual configuration of the time I can not add jvmroute properties, configuration, but there is a problem. Refreshing the browser window is always in one of the Tomcat console output shapes such as
SESSIONID:154678FA6D4D0ABD57658B750E7A3532.TOMCAT1(In the TOMCAT1 window) orSESSIONID:3800571A532AECEA7280F45361861AD4.TOMCAT2(in Tomcat2 window)
The results from the console print show that the SessionID is generated on which Tomcat, and subsequent requests for that session will always be handled by this tomcat.
and notice that the form of SessionID is a suffix more than usual. Tomcat1 or. TOMCAT2, it's unclear why.
The configuration is subject to your choice.
3. Modify the test project TestclusterTo modify the test.jsp, the contents are as follows<%@ page contenttype= "text/html; CHARSET=GBK "%> <%@ page import=" java.util.* "%> <ptml><pead><title>cluster App Test</ti Tle></pead> <body> <% System.out.println ("SessionID:" + Session.getid ()); %> Server Info: <% out.println (Request.getservername () + ":" + request.getserverport () + "<br>");%> <% out.println ("<br> ID" + session.getid () + "<br>"); If there is a new Session property set String Dataname = Request.getparameter ("Dataname"); if (dataname! = null && dataname.length () > 0) {String DataValue = Request.getparameter ("DataValue"); Session.setattribute (Dataname, DataValue); } out.print ("<b>session list </b><br>"); Enumeration E = Session.getattributenames (); while (E.hasmoreelements ()) {String name = (string) e.nextelement (); String value = Session.getattribute (name). toString (); Out.println (name + "=" + value+ "<br>"); SYSTEM.OUT.PRINTLN (name + "=" + value); }%> <form action= "test.jsp" method= "POST" > Name: <input type=text size=20 name= "Dataname" > <br> value: <input type=text size=20 name= "DataValue" > <br> <input type=submit> </form> </body> </ptml>
4. Configure session replication in the Testcluster directory to create a new Web-inf directory, Web-inf under the new Web. XML, the contents are as follows
<web-app xmlns= "Http://java.sun.com/xml/ns/j2ee" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation= "Http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version= "2.4" > <display-name>TomcatClusterDemo</display-name> <distributable/> <we B-app>
That is, adding attributes to Web. XML for applications that require clustering, which indicates that the application can be used for multiple shunt processing to replicate the session.
Copy the Testcluster to the WebApps directory of TOMCAT1, TOMCAT2, and restart APACHE,TOMCAT1,TOMCAT2
5. Test session of the replication through http://localhost/TestCluster/test.jsp access, enter the name named name, the value is Unmi, submit the query, more than a few times to refresh the browser window, You will see that the same SessionID and values are printed in the two tomcat windows, and the results are the same after each refresh.
If you do not add to the application's Web. XML, and also test the test.jsp page above, each refresh stream to different Tomcat will produce a different sessionid, on the same Tomcat is also a gap between the SessionID.
A more personal experience is to be sure to configure it yourself and carefully observe the output of the two Tomcat controls. Because this article is a reference to the easy implementation of APACHE,TOMCAT cluster and load balancing practice experience, there are more stickers in this book.
PostScript: The WebSphere application Server ND version is configured with vertical and horizontal clusters, but the application of its own test cluster environment does not want to albeit this behemoth. What is eager to experience now is how Quartz adapts to the cluster environment, the focus of the problem is: Quartz timed tasks are launched with the Web application, and Web applications are deployed in a clustered environment to ensure that only one task instance with the same name runs at the same time.
So consider configuring a lightweight Web application cluster with Apache+tomcat, which is typically done using Apache, including the was cluster, and rarely with IIS. While the simple use of Tomcat's balancer application can be configured for offload, the performance should be no better.
A Web application cluster configured with Apache+tomcat is a hassle to deploy, always keeping a double copy of the application, and the was cluster does not need to know how JBoss does the Web application cluster.
OK, the next thing to do, and finally hope to write a tool can be completed from download to installation configuration, start, stop, restart the full automation, as well as the user interface.
Resources:
1. Easily implement Apache,tomcat clustering and load balancing
2. Apache+tomcat cluster practice (with some unusual configuration methods for the above method)
3. Tomcat cluster and load balancing (explanation of cluster and load balancing)
4. How to prepare the cluster/session replication (Tomcat5 the Chinese translation of the documentation)
5. How to configure load balancing (Chinese translation of TOMCAT5 's own documents)
Combining Apache and Tomcat for cluster and load Balancing JK mode