日期:2014-05-17 浏览次数:20757 次
环境说明
??????? Apache: httpd-2.2.17
??????? Tomcat:?apache-tomcat-6.0.18(zip版)
??????? mod_jk: mod_jk-1.2.31-httpd-2.2.3.so
第一部分:负载均衡
??? 负载均衡,就是apache将客户请求均衡的分给tomcat1,tomcat2....去处理
??? 1.安装apche,tomcat
??? 2.修改Apache配置文件http.conf
??????? 在apache安装目录下conf目录中找到http.conf
??????? 在文件最后加上下面一句话就可以了:
# 加入下面一句话指定mod_jk配置文件路径 Include conf/mod_jk.conf
??? 2. http.conf 同目录下新建mod_jk.conf文件,内容如下
#加载mod_jk Module LoadModule jk_module modules/mod_jk-apache-2.0.55.so #指定 workers.properties文件路径 JkWorkersFile conf/workers.properties #指定那些请求交给tomcat处理,"controller"为在workers.propertise里指定的负载分配控制器 JkMount /*.jsp controller
#server列表 worker.list=controller,tomcat1,tomcat2 #========tomcat1======== #ajp13端口号,在tomcat下server.xml配置,默认8009 worker.tomcat1.port=8009 #tomcat的主机地址,如不为本机,请填写ip地址 worker.tomcat1.host=localhost worker.tomcat1.type=ajp13 #server的加权比重,值越高,分得的请求越多 worker.tomcat1.lbfactor=1 #========tomcat2======== worker.tomcat2.port=9009 worker.tomcat2.host=localhost worker.tomcat2.type=ajp13 worker.tomcat2.lbfactor=1 #========controller,负载均衡控制器======== worker.controller.type=lb worker.controller.balanced_workers=tomcat1,tomcat2 #全局 session 复制,此处值要设置成 false ,策略会话 ,此处值要设置成 true worker.controller.sticky_session=false
??? 4.修改tomcat配置文件server.xml
??????? 如果你在不同电脑上安装tomcat,tomcat的安装数量为一个,可以不必修改tomcat配置文件
<% System.out.println("==========================="); %>??? 把test放到tomcat1,tomcat2的webapps下
<!-- You should set jvmRoute to support load-balancing via AJP ie : <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1"> <Engine name="Catalina" defaultHost="localhost"> --> <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1"> <!--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"/>?
<%@ page contentType="text/html; charset=GBK"%> <%@ page import="java.util.*"%> <h