Tomcat 負載均衡
Step 1 Download 3 software
?
??? 1, Apache2.0.xx
??? 2,Tomcat
??? 3,mod_jk, it is connector of? tomcat
Step 2 Install Apache2.0 at d:\Apache2, start service, then browse http://localhost for testing, you can see welcome page of apache.
Step 3 Install 2?Tomcats at d:\tomcat1 and d:\tomcat2, set JAVA_HOME, PATH, start tomcat service, then browse http://localhost:8080 for test, you can see welcome page of tomcat.
Step 4 Config apache:?
?????? Copy mod_jk.so to d:\apache2\modules.
??????
?????? Add “include D:\Apache2\conf\mod_jk.conf” in the end of d:\apache2\conf\httpd.conf
?????? Add a new file: d:\Apache2\conf\mod_jk.conf, the content is as following:
# Load mod_jk module LoadModule jk_module modules/mod_jk.so
# Where to find workers.properties JkWorkersFile conf/workers.properties
# Where to put jk logs JkLogFile logs/mod_jk.log
# Set the jk log level [debug/error/info] JkLogLevel info
# Select the log format JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# JkOptions indicate to send SSL KEY SIZE , JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format JkRequestLogFormat "%w %V %T"
# Send servlet for context /examples to worker named ajp13 #JkMount /servlet/* ajp13
# Send JSPs for context /examples to worker named ajp13 JkMount /*.jsp loadbalancer
JkMount /*.htm loadbalancer |
??? Add a new file d:\Apache2\conf\ workers.properties, the content is as following:
# # workers.properties #
# In Unix, we use forward slashes: ps=/
# list the workers by name
worker.list=tomcat1, tomcat2, loadbalancer
# ------------------------ # First tomcat server # ------------------------ worker.tomcat1.port=11009 worker.tomcat1.host=localhost worker.tomcat1.type=ajp13
# Specify the size of the open connection cache. #worker.tomcat1.cachesize
# # Specifies the load balance factor when used with # a load balancing worker. # Note: #? ----> lbfactor must be > 0 #? ----> Low lbfactor means less work done by the worker. worker.tomcat1.lbfactor=100
# ------------------------ # Second tomcat server # ------------------------ worker.tomcat2.port=12009 worker.tomcat2.host=localhost worker.tomcat2.type=ajp13
# Specify the size of the open connection cache. #worker.tomcat2.cachesize
# # Specifies the load balance factor when used with # a load balancing worker. # Note: #? ----> lbfactor must be > 0 #? ----> Low lbfactor means less work done by the worker. worker.tomcat2.lbfactor=100
# ------------------------ # Load Balancer worker # ------------------------
# # The loadbalancer (type lb) worker performs weighted round-robin # load balancing with sticky sessions. # Note: #? ----> If a worker dies, the load balancer will check its state #??????? once in a while. Until then all work is redirected to peer #??????? worker. worker.loadbalancer.type=lb worker.loadbalancer.balanced_workers=tomcat1, tomcat2
# # END workers.properties # |
Step 5 Config Tomcat
?????? Modify conf/server.xml file
??? 1 Add a unique jvmRoute to the Catalina engine
Near line 100, replace:
?? ?<Engine name="Standalone" defaultHost="localhost" debug="0">
with:
??? <Engine jvmRoute="tomcat1" name="Standalone" defaultHost="localhost" debug="0">
For tomcat2, put jvmRoute="tomcat2".
2 Change the control port
At line 13, replace:
??? <Server port="8005"
with:
??? <Server port="11005"
For the tomcat2 server, replace port 8005 with 12005. This will prevent the two servers from conflicting.
3 Change the AJP13 port
At line 75, in the AJP 13 connector definition, replace:
??? port="8009"
with:
??? port="11009"
For the tomcat2 server, replace port 8009 with 12009.
4 Disable the standalone HTTP port
We don't want or need our tomcat servers to directly respond to HTTP requests. So we comment out the HttpConnector section between lines and
Example:
<!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
<!--
??? <Connector className="org.apache.catalina.connector.http.HttpConnector"
?????????????? port="8080" minProcessors="5" maxProcessors="75"
??????????? ???enableLookups="true" redirectPort="8443"
?????????????? acceptCount="10" debug="0" connectionTimeout="60000"/>
-->???
NOTE: If you don't comment this out, you will need to change the port numbers so they don't conflict between tomcat instances.
Step 6 Test??
????????????1 Create a file named index.jsp and put it in the /usr/local/tomcat1/webapps/ROOT directory:
<html> <body bgcolor="red"> <center> <%= request.getSession().getId() %> <h1>Tomcat 1</h1> </body> </html>
|
2 Create a file named index.jsp and put it in the /usr/local/tomcat2/webapps/ROOT directory:
<html> <body bgcolor="blue"> <center> <%= request.getSession().getId() %> <h1>Tomcat 2</h1> </body> </html> |
?????? 3 Browse http://localhost/index.jsp
posted on 2006-12-12 18:14 MingIsMe 閱讀(117) 評論(0) 編輯 收藏 所屬分類: 06 J2EE