After two days finally put apache+tomcat load balanced well, write a blog to share with you.
1. Preparatory work
Download Tomcat7 and Apache2.4 first
Then install Apache, after installation, enter localhost access in IE, if it works means Apache installed, and then extracted to TOMCAT1 and Tomcat2 two directories.
Start TOMCAT1 and TOMCAT2 respectively to see if it starts properly.
2. Configure Apache2.4
① Open the conf/httpd.conf file and load the following module.
#---------------------Start------------------------
LoadModule Proxy_module modules/mod_proxy.so
LoadModule Proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule Rewrite_module modules/mod_rewrite.so
LoadModule Proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule Proxy_connect_module modules/mod_proxy_connect.so
LoadModule Proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule Proxy_http_module modules/mod_proxy_http.so
LoadModule Slotmem_shm_module modules/mod_slotmem_shm.so
LoadModule Speling_module modules/mod_speling.so
LoadModule Ssl_module modules/mod_ssl.so
#----------------------End---------------------
② If you want to see the kitten page,
<ifmodule dir_module>
DirectoryIndex index.html
</IfModule>
Add index.jsp to the index.html below.
③ Remove the comment tag # of the include conf/extra/httpd-vhosts.conf.
④ reverse proxy at end of file
Proxyrequests OFF
<proxy balancer://cluster>
Balancermember ajp://127.0.0.1:8009 loadfactor=1 route=jvm1
Balancermember ajp://127.0.0.1:9009 loadfactor=1 route=jvm2
</proxy>
⑤ Modify the conf/extra/httpd-vhosts.conf file.
Comment out all the dummy-host, add the following content
<virtualhost *:80>
ServerAdmin [email protected]
ServerName localhost
Serveralias localhost
Proxypass/balancer://cluster/stickysession=jsessionid Nofailover=on
proxypassreverse/balancer://cluster/
Errorlog "Logs/lbtest-error.log"
Customlog "Logs/lbtest-access.log" common
</VirtualHost>
2. Configure Tomcat
TOMCAT2 Modification of Conf/server.xml
①<server port= "8005" shutdown= "Shutdown" > modified to 9005
② Modify <service name= "Catalina" >
<connector port= "8080" protocol= "http/1.1"
connectiontimeout= "20000"
redirectport= "8443"/> in 8080 for 9080
③<connector port= "8009" protocol= "ajp/1.3" redirectport= "8443"/> Modified to 9009
④<engine name= "Catalina" defaulthost= "localhost" > Add jvmroute= "jvm2" at the end
This label for TOMCAT1 is also modified to jvmroute= "JVM1"
⑤<cluster classname= "Org.apache.catalina.ha.tcp.SimpleTcpCluster"/> instead
<cluster classname= "Org.apache.catalina.ha.tcp.SimpleTcpCluster" >
<valve classname= "Org.apache.catalina.ha.tcp.ReplicationValve" filter= ". *\.gif;. *\.js;. *\.jpg;. *\.png;. *\.htm;. *\.html;. *\.css;. *\.txt; " />
</Cluster>
After the configuration is complete, start two Tomcat tests to see if Tomcat can start normally
If you can start normally, follow the steps below
Add the test directory below WebApps and add test.jsp
<%@ page contenttype= "text/html; CHARSET=GBK "%>
<%@ page import= "java.util.*"%>
<body>
Server Info:
<%
Out.println (REQUEST.GETLOCALADDR () + ":" + request.getlocalport () + "<br>");%>
<%
Out.println ("<br> ID" + session.getid () + "<br>");
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>");
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>
Create the Web-inf directory and create the Web. xml
? xml version= "1.0" encoding= "Utf-8"?>
<web-app xmlns= "Http://java.sun.com/xml/ns/javaee"
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
Xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee
Http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd "
version= "3.0"
Metadata-complete= "true" >
<distributable/>
</web-app>
Finally, start Apache2.4 and enter localhost\test\test.jsp on the page to test.
Note: Apache may not boot up, then the solution is to view the Apache installation directory under the logs directory of the Error.log file,
Resolve possible issues based on the log file. Until Apache can start normally, Apache can start normally.
The above is just one way to apache+tomcat the cluster configuration. There are two other ways. After the test will write blog.
Apache 2.4 + TOMCAT7 cluster configuration