Tomcat cluster and Server Load balancer in Windows

Source: Internet
Author: User
Tags tld
In enterprise applications, Tomcat is used as an application. Service But tomcat, as a lightweight application server, has limited load capacity and is overwhelmed after the system is launched. At this time, people will think of clusters, unfortunately, it is inconvenient to start a cluster in previous versions.
Tomcat5.5 has made great improvements in this regard. We can first implement the tomcat5.5 cluster.
 
1. Configure Tomcat
1. directly extract the downloaded apache-tomcat-5.5.17.zip file to the root directory of the drive and change the directory name to atat5517_s1, which serves as the first Tomcat server in the cluster.
2. Delete all content under tomcat5517_s1/webapps and tomcat5517_s1/temp.
3. Create a root. xml file under tomcat5517_s1/CONF/Catalina/localhost (Note: you must use the root. xml file name ). Add content:
<Context Path = "" docbase = "Release path" displayname = "tomcat_1"
DEBUG = "0" privileged = "true">
 
<! -- Default set of monitored resources -->
<Watchedresource> WEB-INF/Web. xml </watchedresource>
</Context>
 
4. Run startup. BAT in tomcat5517_s1/bin if your application release is normal.
5. Access in a browser: Http: // localhost: 8080Your application can be successfully released in Tomcat.
Note the following:
If your system uses taglib, especially c.tld, download the latest jakarta-taglibs-standard-1.1.2.zip, get standard. jar, jstl. jar, and C. TLD, put them in the appropriate directory, and modify web. xml:
<! 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 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">
</Web-app>
 
All
<Taglib>
<Taglib-Uri>/WEB-INF/struts-html.tld </taglib-Uri>
<Taglib-location>/WEB-INF/struts-html.tld </taglib-location>
</Taglib>
 
To be placed in the <JSP-config> element, like this:
<JSP-config>
<Taglib>
<Taglib-Uri>/WEB-INF/struts-template.tld </taglib-Uri>
<Taglib-location>/WEB-INF/struts-template.tld </taglib-location>
</Taglib>
<Taglib>
<Taglib-Uri>/WEB-INF/C. TLD </taglib-Uri>
<Taglib-location>/WEB-INF/C. TLD </taglib-location>
</Taglib>
</JSP-config>

2. Configure the Tomcat cluster on the same machine
1. Rename the tomcat5517_s1/Catalina folder to atat5517_s1/standalone, and then open tomcat5517_s1/CONF/server. XML to modify several key points.
★ Remote Disable the Tomcat service port, which is 8005 and changed to 10005.
★Port Number of the two external service ctor INS: the http port is 8080, changed to 10001; The ajp1.3 protocol port is 8009, changed to 10009. (It should be noted that at the beginning of the debugging phase, we should keep the http port open and use the browser to directly connect to Tomcat. After the debugging is successful, all clients are only allowed to access through Apache. We need to disable the HTTP ctor that provides the HTTP protocol .) The redirectport is changed to 10043.
★Comment out the original: <engine name = "Catalina" defaulthost = "localhost"> and open the above: <engine name = "standalone" defaulthost = "localhost" jvmroute = "tomcat1"> and change the value of jvmroute to tomcat1.
★Open the comment of the cluster element, and change the listening port tcplistenport of the worker Er element to 10011.
2. modify web. xml and add <distributable/> as follows:
<! 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 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">
<Distributable/>
</Web-app>
 
Start Tomcat and you will see the following prompt:
13:33:57 org. Apache. Catalina. Cluster. tcp. simpletcpcluster start
Information: Cluster is about to start
13:33:57 org. Apache. Catalina. Cluster. tcp. replicationtransmitter start
Information: Start clustersender at cluster standalone: TYPE = cluster, host = localhost with name standalone: TYPE = clustersender, host = localhost
2006-6-28 13:33:57 org. Apache. Catalina. Cluster. MCAST. mcastservice start
Information: sleeping for 2000 milliseconds to establish cluster membership
13:33:59 org. Apache. Catalina. Cluster. MCAST. mcastservice registermbean
Information: Membership mbean registered (standalone: TYPE = clustermembership, host = localhost)
2006-6-28 13:33:59 org. Apache. Catalina. Cluster. Deploy. farmwardeployer start
Information: Cluster farmwardeployer started.
2006-6-28 13:34:30 org. Apache. Coyote. http11.http11baseprotocol start
Information: Starting coyote HTTP/1.1 on http-10001
2006-6-28 13:34:30 org. Apache. JK. Common. channelsocket init
Information: JK: ajp13 listening on/0.0.0.0: 10009
2006-6-28 13:34:30 org. Apache. JK. server. jkmain start
Description: JK running id = 0 time = 0/141 Config = NULL
 
This indicates that the Tomcat cluster is started normally.
3. Copy the tomcat5517_s1 folder and rename it tomcat5517_s2. Then modify tomcat5517_s1/CONF/server. xml. The modification content is the same as above. Note the port modification:
★Remotely shut down the Tomcat service port, which is 8005 and changed to 20005.
★Port Number of the two external service ctor INS: the http port is 8080, changed to 20001; The ajp1.3 protocol port is 8009, changed to 20009. The redirectport is changed to 20043.
★Comment out the original: <engine name = "Catalina" defaulthost = "localhost"> and open the above: <engine name = "standalone" defaulthost = "localhost" jvmroute = "tomcat2"> and change the value of jvmroute to tomcat2.
★Open the comment of the cluster element, and change the listening port tcplistenport of the worker Er element to 20011.
Start Tomcat 2 and you will see the following prompt:
In limit at1:
14:25:46 org. Apache. Catalina. Cluster. tcp. simpletcpcluster memberadded
Information: Replication member added: org. Apache. Catalina. Cluster. MCAST. mcastmember [TCP: // 192.168.1.192: 20011, Catalina, 192.168.1.192, 20011, alive = 40]
 
In Tomcat 2:
14:25:44 org. Apache. Catalina. Cluster. tcp. simpletcpcluster memberadded
Information: Replication member added: org. Apache. Catalina. Cluster. MCAST. mcastmember [TCP: // 192.168.1.192: 10011, Catalina, 192.168.1.192, 10011, alive = 3105085]
 
This indicates that two Tomcat clusters have been created and the session is synchronized.

3. Configure Apache

Apache2.2 provides the latest mod_proxy_balancer module, which is a powerful tool for load balancing in this practice. After installing Apache, open the conf/httpd. conf file:

★Open necessary modules:
Loadmodule proxy_module modules/mod_proxy.so
Loadmodule proxy_ajp_module modules/mod_proxy_ajp.so
Loadmodule proxy_balancer_module modules/mod_proxy_balancer.so
Loadmodule proxy_http_module modules/mod_proxy_http.so

★Add the following at the end of httpd. conf:

Proxyrequests off

Proxypass/balancer: // mycluster/
<Proxy balancer: // mycluster/>
Balancermember AJP: // localhost: 10009 route = route at1
Balancermember AJP: // localhost: 20009 route = tomcat2
</Proxy>

Start Apache and test the performance of your application in the cluster environment!

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.