Linux tomcat cluster configuration case

  

Pre-configuration preparation Before configuring the cluster application, you must have a good design for the cluster configuration information. The following is the cluster information we configured this time: Different machines in the same network segment Configure the cluster on the following, the following is a cluster of 2 machines, machine type operating system
hardware configuration role notes ordinary PC Linux as 4 IP: 10.3.15.85 PORT: 9080 Managed Server Pc1 ordinary PC Linux as 4 IP: 10.3.15.84 PORT: 9080 Managed Server Pc2 Normal PC Linux as 4 IP: 10.3.15.85 PORT: 80 Balancer Server Pc1

1 Operating System RedHat Linux as4 2 Required Software Apache 2.0.54 Download Address upload/201106071159522828 .gif;.*\\.js;.*\\.jpg;.*\\.htm;.*\\.html;.*\\.txt;”/> <Deployer className=”org.apache.catalina .cluster.deploy.FarmWarDeployer” tempDir=”/tmp/war-temp/” deployDir=”/tmp/war-deploy/” watchDir=”/tmp/war-listen/” watchEnabled=” False”/> </Cluster>

At this point, the system has been completely started ap Ache and tomcat services # /usr/local/apache/bin/apachectl start #/usr/local/tomcat/bin/catalina.sh start Add the following to the end of the /etc/rc.d/rc.local file for the system Start apache after startup, tomcat service /usr/local/tomcat/bin/catalina.sh start /usr/local/apache/bin/apachectl start

5 test cluster

after all the above steps A tomcat cluster with 2 nodes has been configured, but sometimes session replication between nodes may not be possible because tcpListenAddress=”auto” in all nodes' server.xml is changed to tcpListenAddress=”10.3. 15.85 & rdquo;, that is to change to the real ip address. If you start up, the following message appears: skipping state transfer. No members active in cluster group. You also need to modify the above information. Otherwise, the session cannot copy the session between multiple tomcats.

5.1 Write a simple web application with the following contents: Write one of the following 2 jsp pages. The contents of test.jsp are as follows: <%@ page contentType=”text/html; charset=GBK” %> <%@ page import =”com.WorkerBean”%> <%@ page import=&rdquo ;java.net.*” %> <html> <head> <title> test </title> </head>

<body bgcolor=”#ffffff” > <%= request.getSession().getId() %>

<% int i=0; WorkerBean test = new WorkerBean(); //HttpSession tsession=request.getSession() ; test.setWorker_no(request.getSession().getId()+i); session.setAttribute(“worker_no”,test.getWorker_no());

System.out.println(“OK” System.out.println(“session.getAttribute()==”+session.getAttribute(“worker_no”)); out.println(“session.getAttribute()==”+session.getAttribute (“worker_no”)); out.println(“OK”);

%> <a href=”testResult.jsp”> testResult.jsp</a> <h1> ;Tomcat </h1> </body> </html>

testResult.jsp is as follows: <%@ page contentType=”text/html; charset=GBK” %> <%@ page import =”com.WorkerBean”%> <%@ page Import=”java.net.*” %> <html> <head> <title> test </title> </head>

<body bgcolor=” #ffffff”>

<%

System.out.println(“OK”); System.out.println(“session.getAttribute()==”+ session.getAttribute(“worker_no”)); out.println(“OK”); out.println(“session.getAttribute()==”+session.getAttribute(“worker_no”)); %> ; <h1>Tomcat </h1> </body> </html>

5.2 Write the javaBean class for this jsp call.

WorkerBean.java public class WorkerBean implements java.io.Serializable { String worker_no;

/**  @return returns worker_no. */public String getWorker_no() { return worker_no; }

/**  @param worker_no The worker_no to be set. */public void setWorker_no(String worker_no) { this.worker_no = worker_no; }

} Note: This class must be serialized in order to have the session object in this class, the session is in the cluster Copyed, otherwise the session object cannot be copied in the cluster. 5.3 Configuring the web.xml file Note: Be sure to add <distributable/>, the other is the same as the normal application. <?xml version=”1.0” encoding=”UTF-8”?> <!DOCTYPE web-app PUBLIC “-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN” <;http://java.sun.com/dtd/web-app_2_3.dtd”> <web-app> <display-name>web</display-name> <distributable/> </Web-app> 5.4 Make sure that server.xml is as shown in Appendix 1 and Appendix 2: Slightly 5.5 Publish the web application, and test all the above files to the tomcat webapps/ROOT directory, overwriting the original files. 5.6 Testing the web application Start apache and tomcat1 and tomcat2. Enter http://10.3.15.85/in the address bar of the browser and you will see the following page.

Copyright © Windows knowledge All Rights Reserved