下载apache
http://apache.mirror.phpchina.com/httpd/httpd-2.2.9-win32-src.zip
下载mod_jk-1.2.26-httpd-2.2.4.so
http://apache.mirror.phpchina.com/tomcat/tomcat-connectors/jk/binaries/win32/jk-1.2.26/
下载tomcat6
下载JDK6
然后配置好环境。
步骤1:
安装apache,然后测试http://localhost:80/,可以显示的话表示apache安装成功。
把mod_jk-1.2.26-httpd-2.2.4.so 改名为mod_jk,并复制到apache的安装目录的modules下。
步骤2:
修改apache,conf目录下的httpd文件,增加以下内容(根据自己的情况增减)
LoadModule jk_module modules/mod_jk.so
JkWorkersFile "C:\Program Files/Apache Software Foundation/Apache2.2/conf/workers.properties"
JkLogFile "C:\Program Files/Apache Software Foundation/Apache2.2/logs/mod_jk.log"
JkLogLevel severe
JkMount /*.do controller
JkMount /*.jsp controller
JkMount /WEB-INF/* controller
JkMount /lzj1/*.do controller
步骤3:
在conf目录下增加uriworkermap.properties文件
再增加workers.properties文件,增加或修改以下内容(根据自己的情况而定)
workers.tomcat_home="E:\java\apache-tomcat-6.0.16\apache-tomcat-6.0.16"
workers.java_home="C:\Program Files\Java\jdk1.6.0_06"
worker.list=controller,tomcat1,tomcat2
worker.tomcat1.host=192.168.10.55
worker.tomcat1.port=8009
worker.tomcat2.port=8009
worker.tomcat2.host=localhostworker.controller.type=lb
worker.controller.balanced_workers=tomcat1,tomcat2
worker.controller.sticky_session=1
worker.ajp13.lbfactor=1
worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp13.type=ajp13
worker.ajp13.lbfactor=1
这样就完成了均衡负载的配置。
步骤4:
配置tomcat6
<Engine name="Standalone" defaultHost="localhost" jvmRoute="tomcat2">
再配置tomcat6集群的session复制。打开tomcat6,conf目录下的server.xml文件。把集群配置的注释去掉。变成
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
channelSendOptions="8">
<Manager className="org.apache.catalina.ha.session.DeltaManager"
expireSessionsOnShutdown="false"
notifyListenersOnReplication="true"/>
<Channel className="org.apache.catalina.tribes.group.GroupChannel">
<Membership className="org.apache.catalina.tribes.membership.McastService"
address="228.0.0.4"
port="45564"
frequency="500"
dropTime="3000"/>
<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
address="auto"
port="4000"
autoBind="100"
selectorTimeout="5000"
maxThreads="6"/>
<Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
<Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
</Sender>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
</Channel>
<Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
filter=""/>
<Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>
<Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
tempDir="/tmp/war-temp/"
deployDir="/tmp/war-deploy/"
watchDir="/tmp/war-listen/"
watchEnabled="false"/>
<ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>
<ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
</Cluster>
步骤5:
建立一个页面index.jsp:
/*<%
System.out.println("===========================");
%>
*/
<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="java.util.*" %>
<html><head><title>Cluster App Test</title></head>
<body>
Server Info:
<%
out.println(request.getLocalAddr() + " : " + request.getLocalPort()+"<br>");%>
<%
out.println("<br> ID " + session.getId()+"<br>");
// 如果有新的 Session 属性设置
String dataName = request.getParameter("dataName");
if (dataName != null && dataName.length() > 0) {
String dataValue = request.getParameter("dataValue");
session.setAttribute(dataName, dataValue);
}
out.print("<b>Session 列表</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="index.jsp" method="POST">
名称:<input type=text size=20 name="dataName">
<br>
值:<input type=text size=20 name="dataValue">
<br>
<input type=submit>
</form>
</body>
</html>
其web.xml配置
<distributable/>
步骤6:
最后使用jmeter运行一下简单测试,设置40个并发用户,测试的IP地址是192.168.10.66(apache)、192.168.10.66(tomcat2)、192.168.10.55(tomcat1)其中tomcat2是有线接入,tomcat2是无线接入。测试页面为/lzj1/index.jsp。
可以看看结果:
tomcat1:
Thread Name: 线程组 1-1
Sample Start: 2008-07-13 22:32:42 CST
Load time: 2532
Latency: 2532
Size in bytes: 401
Sample Count: 1
Error Count: 0
Response code: 200
Response message: OK
Response headers:
HTTP/1.1 200 OK
Date: Sun, 13 Jul 2008 14:32:42 GMT
Server: Apache/2.2.9 (Win32) mod_jk/1.2.26
Set-Cookie: JSESSIONID=6A15C0175A2E1EC8E0930FAF0C28ADC9.tomcat1; Path=/lzj1
tomcat2:
Thread Name: 线程组 1-3
Sample Start: 2008-07-13 22:32:44 CST
Load time: 4
Latency: 4
Size in bytes: 401
Sample Count: 1
Error Count: 0
Response code: 200
Response message: OK
Response headers:
HTTP/1.1 200 OK
Date: Sun, 13 Jul 2008 14:32:44 GMT
Server: Apache/2.2.9 (Win32) mod_jk/1.2.26
Set-Cookie: JSESSIONID=2FF347B788690651E7DADE1A040EE94C.tomcat2; Path=/lzj1
可以从结果看到检测到的服务器是Apache/2.2.9 (Win32) ,使用了mod_jk/1.2.26,并且tomcat1的反应时间明显慢于tomcat2,这是由于这里的tomcat1的网络是使用的是无线接入的缘故。
posted on 2008-07-13 22:11
lzj520 阅读(951)
评论(0) 编辑 收藏 所属分类:
个人学习日记