I. Required Software
1.jdk1.5 or more
2.tomcat6 or more
3.apache2.2 above, address http://apache.dataguru.cn//httpd/binaries/win32/, name: Httpd-2.2.25-win32-x86-no_ssl.msi
4.JK, address http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/win32/jk-1.2.31/, name Mod_ Jk-1.2.31-httpd-2.2.3.so
Two. Install Apache, remember the installed directory
Three. Copy the mod_jk-1.2.31-httpd-2.2.3.so file into Apache's D:\Apache software foundation\apache2.2\modules directory
Four. Open the Apache httpd.conf file, add the external profile introduction, and add it to the last side of the file.
Include "D:\Apache software foundation\apache2.2\conf\mod_jk.conf"
Five. Create the mod_jk.conf file and write the configuration
1 #加载mod_jk Module 2 LoadModule jk_module modules/mod_jk-1.2.31-httpd-2.2.3.so34#指定 Workers.properties file path 5conf/workers.properties67 #指定那些请求交给tomcat处理 , "Controller" is the name of the load-allocating director named 8/*specified in Workers.propertise. JSP Controllers
Six. Create the workers.properties file in the Apache configuration file directory and write the configuration
#serverworker. List=controller,tomcat1,tomcat2#========TOMCAT1========worker. tomcat1. Port=8009#ajp13 port number, server.xml configuration under Tomcat, 8009 worker by default. tomcat1. Host=localhost Tomcat host address, if not for this machine, 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=localhost worker. tomcat2. Type=Ajp13worker. tomcat2. Lbfactor= 1 #========controller, Load Balancer controller ========Worker.controller.type=lbworker.controller.balanced_workers=tomcat1,tomcat2 #指定分担请求的tomcat worker.controller.sticky_session=false#粘性会话worker. Controller.sticky_session_force=1#worker. Controller.sticky_session=1
Seven. Configure Tomcat
1. The first Tomcat does not need to modify the port, but needs to release
<cluster classname= "Org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
<engine name= "Catalina" defaulthost= "localhost" jvmroute= "tomcat1" >
Where the engine label is already open just need to add the name jvmroute= "" The name in this need to be up, like the name in Worker.properties
2. The second tomcat needs to be changed to port, and the purpose is to make Tomcat run without conflict on the same machine, then open the top two tabs.
Eight. Test project
Create a Dynamic Web project that creates a new index.jsp file with the contents of
<%@ page contenttype= "text/html; Charset=utf-8 "%><%@ pageImport= "java.util.*"%>Server Info:<%out.println (request.getlocaladdr ()+ ":" + request.getlocalport () + "<br>");%><%Out.println ("<br> ID" + session.getid () + "<br>"); //If there is a new Session property setString dataname = Request.getparameter ("Dataname"); if(Dataname! =NULL&& dataname.length () > 0) {String DataValue= Request.getparameter ("DataValue"); Session.setattribute (Dataname, DataValue); } out.println ("<b>session list </b><br>"); System.out.println ("============================"); 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= "index.jsp" method= "POST" >Name:<input type=text size=20 name= "Dataname" > <br>values:<input type=text size=20 name= "DataValue" > <br> <input type=submit> </form></body>& Lt;/html>
Nine. Add a label to the Web. xml file to indicate that the item is assignable
<distributable/>
If all tomcat projects need to be shared, you can add them to Tomcat's Conf/context.xml
10. Deploy the test project to Tomcat separately, launch the Apache service, boot two Tomcat, and start the sequence arbitrarily.
1. On the native access address: http://localhost/project name/index.jsp
2. Successful results, regardless of refresh page SessionID are unchanged, committed values will not disappear
ID F219C85735A0F7DE958ED3431BF4BEA1.TOMCAT2
ID F219C85735A0F7DE958ED3431BF4BEA1.TOMCAT1
11. Software Interpretation
1.Apache
Support for the latest http/1.1 communication protocols
Have a simple and powerful file-based configuration process
Support for Universal Gateway Interface
Support for IP-based and domain-based virtual hosts
Support for HTTP authentication in multiple ways
Integrated Perl processing Module
Integrated Proxy Server Module
Supports real-time monitoring of server status and custom server logs
Support for server-side include directives (SSI)
Secure Socket Layer (SSL) support
Provides tracking of user session processes
Support FastCGI
Javaservlets can be supported through third-party modules
2.jk
MOD_JK abbreviated JK is an pluggable module of the Apache server that provides the ability to handle jsp/servlet for Apache or IIS servers.
Tomcat itself can also be used as a Web server, but its functionality is far less powerful than Apache, so Tomcat is often used as a jsp/servlet container
MOD_JK is essentially a connector for Apache and Tomcat, with the ability to provide clustering and load balancing.
3.TOMCAT+APACHE+MOD_JK Integration
Load balancing is achieved.
Cross-platform.
Advantages: Simple configuration, avoid the trouble of compiling webapp.so,
Cons: It's not easy to find mod_jk under Linux, MOD_JK is no longer updated
APACHE+TOMCAT+MOD_JK Load Balancing