Simulate a tomcat cluster on a host

Source: Internet
Author: User

1. How to run two Tomcat instances on a host

2. httpd + Tomcat Load Balancing Integration

3. Download and references

<1>. How to run two Tomcat examples on a host

1.1 download the Tomcat package and decompress it twice. Name it work2 and work3 respectively, as shown below:


If you do not set any settings, it is obviously unable to run successfully. On the one hand, Tomcat needs to run with the environment variable catalina_home. On the other hand, if you enable the First tomcat instance and then start another tomcat, jvm_bind errors may occur. The modification settings are as follows:

1.1.1 modify the startup. BAT file and set the catalina_home environment variable at the beginning of the file:

Set catalina_home = "E: \ tomcatcluster \ work2" (set this to the Tomcat decompressed directory) + ++ startup. BAT file body

1.1.2 modify the Tomcat server. xml file:

<Connector Port ="8080& Quot; Protocol = & quot; http/1.1 & quot"

Connectiontimeout = "20000" redirectport = "8443"/>

Change the 8080 port number to a port number that is not used in the computer.

1.1.3 modify the shutdown port number

<Server port ="8000"Shutdown =" shutdown ">

Change "8000" to the occupied port number (only one Tomcat instance needs to be modified ).

Follow the two steps above to modify the configuration files of work2 and work3, and enable two Tomcat examples at the same time to ensure that work2 and work3 can be enabled properly. The preceding steps enable both Tomcat servers on one host.

<2>. httpd + Tomcat Load Balancing Integration

2.1 install httpd and downloadHttp://,The installation process is omitted. After the installation is complete, if you need to modify the httpd port number, you can modify CONF/httpd. conf:


# Listen: allows you to bind Apache to specific IP addresses and/or # ports, instead of the default. see also the <virtualhost> # directive. # change this to listen on specific IP addresses as shown below to # prevent Apache from glomming onto all bound IP addresses. # Listen 80 listen 8081.

If you do not need to modify the port number, open httpd.exe directly, open the browser, and enter http: // 8081/(the port number in the address must be consistent with the port number modified above). If it works appears, httpd is successfully installed.

2.2 modify the HTTP listening port of work2. The port number can be any. Here is my Configuration:

<Connector Port ="8079& Quot; Protocol = & quot; http/1.1 & quot"

Connectiontimeout = "20000" redirectport = "8443"/>

2.3 modify the AJP Port Number:

<! -- Define an AJP 1.3 connector on port 8009 -->

<Connector Port = "8077" protocol = "AJP/1.3" redirectport = "8443"/>

2.4 Configure the server ID

<Engine name = "Catalina" defaulthost = "localhost" Jvmroute = "worker2"> <! -- For clustering, please take a look at documentation at:/docs/cluster-howto.html (simple how to)/docs/config/cluster.html (reference documentation) --> <Cluster classname = "org. Apache. Catalina. Ha. tcp. simpletcpcluster"/>

2.5 implement session replication and modify context. xml:

<Context distributable = "true"> ++ context. xml remaining default configurations

2.6 set work3 in the same way. My settings are as follows:

<Connector Port =" 8099 "Protocol =" HTTP/1.1 "connectiontimeout =" 20000"

Redirectport = "8443" type = "regxph" text = "yourobjectname"/>

<Connector Port ="9999"Protocol =" AJP/1.3 "redirectport =" 8443 "/>

<Engine name = "Catalina" defaulthost = "localhost" Jvmroute = "worker3"> <! -- For clustering, please take a look at documentation at:/docs/cluster-howto.html (simple how to)/docs/config/cluster.html (reference documentation) -->

<Cluster classname = "org. Apache. Catalina. Ha. tcp. simpletcpcluster"/>

2.7 Add the test directory to the webapp of the two Tomcat instances above and add the test. jsp file:

< Html >
< Head >
< Title > Helloapp </ Title >
</ Head >
< Body >
System. Out. println ( " Call test. jsp " );

Sessionid:<%=Session. GETID ()%>

Access the test. JSP page to ensure access. The address on my machine is: http: // localhost: 8079/test. JSP and http: // localhost: 8099/test. JSP.

2.8 integrate httpd + Tomcat in JK Mode

Download the, please download the appropriate mod_jk version, renamed into the modules folder, modify the httpd. conf file, add the following content:

############################## Add by Qiang. xu ###### loadmodule jk_module modules/mod_jk.sojkworkersfile CONF/workers. propertiesjklogfile logs/mod_jk.logjkloglevel debugjkmount /*. do loadbalancerjkmount /*. JSP loadbalancer

######################################## ########

Add the workers. properties file:

Worker. List = loadbalancerworker. worker2.port = 8077 # AJP listening port worker. = localhost # = ajp13 # Load banlance factorworker. worker2.lbfactor = 1 Worker. worker2.reply _ timeout = 0 Worker. worker3.port = 9999worker. = localhostworker. worker3.type = ajp13worker. worker3.lbfactor = 1worker. worker3.reply _ timeout = 0 # Here, worker2 and worker3 must be the same as the alias set by Tomcat above. Worker. loadbalancer. balance_workers = worker2, worker3
Worker. loadbalancer. sticky_session = 1

Finally, complete the httpd + Tomcat configuration. If everything is normal, try to open this http: // 8081/test. JSP link, and then close one of the servers, the other server will be able to accept the request.

<3>. Download and references

Download work2, work3, httpd






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: 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.