我的运行环境:Windows2003 Server SP4 + J2SDK1.5.0 +Tomcat5.5.
准备软件
Tomcat 5.5.9 JDK1.5.0
一.配置过程
1、 安装JDK1.5.0。采用默认安装就可以。
2、 安装tomcat到C: tomcat 50,采用完全安装,该程序用于实现负载均衡功能。
3、 将tomcat50的内容进行完全复制,生成C: tomcat 51、C: tomcat 52、C: tomcat 53,分别用做集群中的节点。
4、 修改负载均衡规则,使其遵循轮循算法(RoundRobin)。
4.1将testLB.jsp复制到c:tomcat50webappsbalancer文件夹中
4.2将文件夹classes复制到c:tomcat50webappsbalancerWEB-INF文件夹中
4.3修改c:webtomcat50webappsbalancerWEB-INFweb.xml文件如下:
< filter-mapping>
< filter-name>BalancerFilter< /filter-name>
< url-pattern>/LoadBalancer< /url-pattern>
< /filter-mapping>
5、 在集群中每个节点下,部署clusterapp应用。Clusterapp包含sessiondata.jsp,test.jsp,脚本。test.jsp是用来验证节点状态的页面;sessiondata.jsp是用来响应用户所发送的请求,同时记录会话ID,会话的起始和最后时间,提供用户增加、修改、删除会话的属性字段和属性值,可以通过此来判断会话的持续与否。
6、 将log4j的log4j-1.2.9.jar复制到每个%tomcat%/common/ lib下,使其将会话日志统一存储到指定的文件中。
7、 修改每个tomcat的server.xml配置文件,参数如下表所示。
配置 Instance 1 Instance 2 Instance 3 Instance 4
Instance Type Load Balancer Node 1 Node 2 Node 3
Code name TC-LB TC01 TC02 TC03
Home Directory c:/tomcat50 c:/tomcat51 c:/tomcat52 c:/tomcat53
Server Port 8005 9005 10005 11005
Connector 8080 9080 10080 11080
JK2 AJP Connector 8009 9009 10009 11009
Cluster mcastAddr 228.0.0.4 228.0.0.4 228.0.0.4 228.0.0.4
Cluster mcastPort 45564 45564 45564 45564
tcpListenAddress 127.0.0.1 127.0.0.1 127.0.0.1 127.0.0.1
Cluster tcpListenPort 4000 4001 4002 4003
8、修改c:webtomcat50webappsbalancerWEB-INFconfigruler.xml文件如下:
< ?xml version=”1.0″ encoding=”UTF-8″?>
< rules>
< !– Redirect to server instance based on RoundomRobinRule –>
< rule className=”org.apache.webapp.balancer.rules.RandomRedirectRule”
serverInstance=”1″
maxServerInstances=”3″
tcpListenAddress=”127.0.0.1″
tcpListenPort=”4001″
testWebPage=”http://localhost:9080/clusterapp/test.jsp”
redirectUrl=”http://localhost:9080/clusterapp/sessiondata.jsp” />
< rule className=”org.apache.webapp.balancer.rules.RandomRedirectRule”
serverInstance=”2″
maxServerInstances=”3″
tcpListenAddress=”127.0.0.1″
tcpListenPort=”4002″
testWebPage=”http://localhost:10080/clusterapp/test.jsp”
redirectUrl=”http://localhost:10080/clusterapp/sessiondata.jsp” />
< rule className=”org.apache.webapp.balancer.rules.RandomRedirectRule”
serverInstance=”3″
maxServerInstances=”3″
tcpListenAddress=”127.0.0.1″
tcpListenPort=”4003″
testWebPage=”http://localhost:11080/clusterapp/test.jsp”
redirectUrl=”http://localhost:11080/clusterapp/sessiondata.jsp” />
< !– Default redirect if none of the above rules match –>
< rule className=”org.apache.webapp.balancer.rules.AcceptEverythingRule”
redirectUrl=”http://localhost:8080/balancer/testLB.jsp” />
< /rules>
9、启动tomcat的应用。手动双击每个tomcat/bin的startup.bat程序。
二.Web请求集群环境下流程
1、 启动访问起始页(http://localhost:8080/balancer/testLB.jsp)
2、 JSP重定向请求到负载均衡过滤文件(http://localhost:8080/balancer/LoadBalancer)
3、 负载均衡的tomcat接受请求,根据制定的负载均衡算法,重定向到可用的集群节点(TC01、TC02、TC03)
4、 对应集群中节点的sessiondata.jsp(位于clusterapp应用下)页面将启动。
5、 sesiondata.jsp将在web上显示会话的详细信息(如会话ID,最后访问时间)
在测试的过程中采用RoundRobin算法,通过对Instance 1发起多个http://localhost:8080/balancer/testLB.jsp测试请求,发现每个请求返回页面的端口号不完全一致,在9080、10080、11080端口不规则的出现,即客户端的访问请求按照RoundRobin算法被重定向到不同的服务器上进行处理,说明该负载均衡规则在这个测试中得到正确的体现。在关闭集群中一个节点后再启用它,能够自动发现该节点,并为该节点分配请求。
我们一直都在努力坚持原创.......请不要一声不吭,就悄悄拿走。
我原创,你原创,我们的内容世界才会更加精彩!
【所有原创内容版权均属TechTarget,欢迎大家转发分享。但未经授权,严禁任何媒体(平面媒体、网络媒体、自媒体等)以及微信公众号复制、转载、摘编或以其他方式进行使用。】
微信公众号

TechTarget
官方微博

TechTarget中国
相关推荐
-
无服务计算就不需要服务器吗?
在云计算基础架构即服务(IaaS)中,你不需要管理你的物理基础架构;而在云计算的无服务计算中,你甚至不需要管理任何虚拟机、操作系统或者容器……
-
为私有云实施做准备:调整你的服务器
为了向私有云服务迈进,IT团队首先需要评估其当前的数据中心基础设施,从服务器处理器、内存和存储支持开始。
-
提高IT效率:利用自动化系统和服务器文档
服务器和系统文档是IT管理的关键一环,但是对于很多小型的IT企业来说文档本身可以能会涉及乏味的、容易出错的手动流程。
-
“拒燃”?小心数据中心热点
冷却故障和服务器温度过高造成的结果往往比绝大多数关键任务数据中心断电还糟糕。那么,热点是如何发生的呢?又如何预防其发生呢?