tomcat集群配置

Tomcat 6.0.29 集群配置
1 准备工具:
(1) Apache Httped 前置服务器
版本:apache_2.2.14
文件名:apache_2.2.14-win32-x86-openssl-0.9.8k.msi
下载地址:[url]http://httpd.apache.org/download.cgi[/url]

(2) Apache Tomcat Connectors
版本:Apache Tomcat Connectors 1.2.28 for WIN32
文件名:mod_jk-1.2.28-httpd-2.2.3.so
下载地址:[url]http://apache.deathculture.net/tomcat/tomcat-connectors/jk/binaries/win32/jk-1.2.28/[/url]
(3) Apache Tomcat 6.0.29
版本:Tomcat 6.0.29
2 配置前置服务器(Apache 2.2)
(1) 安装apache_2.2.14-win32-x86-openssl-0.9.8k.msi,其中有选择服务端口的配置,默认为80
(2) 将mod_jk-1.2.28-httpd-2.2.3.so拷贝到已经安装的Apache 2.2 目录下的modules 目录,并重命名为:mod_jk.so

[img]http://dl.iteye.com/upload/attachment/404211/39d54761-9bb4-314a-96c2-c96921136281.jpg[/img]

图1
(3) 在Apache 2.2 目录下的 conf 目录下,新建workers.properties文件,用于配置集群点的IP、监听端口……

[img]http://dl.iteye.com/upload/attachment/404213/c5ce9984-55c5-36dc-8532-6ed224ece466.jpg[/img]

图2

一般配置如下:
worker.list=loadBalancer
#定义一个集群节点 ,分发名为tomcat1,IP地址为18.0.0.170
worker.tomcat1.port=8009
worker.tomcat1.host=18.0.0.170#这个地方根据情况写比如写的是localhost
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor=1 #加权比重,值越高,分得的请求越多
#定义一个集群节点,分发名为tomcat2,IP地址为18.0.0.110
worker.tomcat2.port=9009
worker.tomcat2.host=18.0.0.110#这个地方根据情况写比如写的是localhost
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor=1 #加权比重,值越高,分得的请求越多
#指定分担请求的tomcat,及session复制
worker.loadBalancer.type=lb
worker.loadBalancer.balance_workers=tomcat1,tomcat2
worker.loadBalancer.sticky_session=true或1
其他常见配置,可选:
# worker "worker2" uses connections, which will
#stay no more than 10mn in the connection pool
worker.worker2.connection_pool_timeout=600
# worker "worker2" ask operating system to send #KEEP-ALIVE signal #on the connection
worker.worker2.socket_keepalive=1
worker.worker2.connection_pool_size=10

[img]http://dl.iteye.com/upload/attachment/404215/ed28ca11-d45b-3295-bd98-d57129c76b7a.jpg[/img]

图3


(4) 打开安装Apache 2.2 目录下的 conf 目录,打开httpd.conf文件,

[img]http://dl.iteye.com/upload/attachment/404217/69ec3173-2003-369e-88d9-1126afab16f7.jpg[/img]

图4

将下面内容拷贝到文件里面:
# 加载 mod_jk 模块
LoadModule jk_module modules/mod_jk.so
# 引入workers.peroperties文件配置
JkWorkersFile conf/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel info
#指定那些请求交给tomcat处理," loadBalancer "为在workers.propertise里指定#的负载分配控制器
JkMount /*.jsp loadBalancer
JkMount /* loadBalancer


[img]http://dl.iteye.com/upload/attachment/404219/10260315-23ad-371b-a4fc-e4ea3ebaac7f.jpg[/img]


图5

注意:(3) 和(4) 的文件配置中的属性有版本限制,具体可以参考:

[url]http://tomcat.apache.org/connectors-doc/reference/workers.html[/url]

[url]http://tomcat.apache.org/connectors-doc/generic_howto/workers.html[/url]

(5) 配置集群节点tomcat server.xml文件(这个每个tomcat都要集群点都要修改的)

[img]http://dl.iteye.com/upload/attachment/404221/c78bbb37-ad54-3d94-999a-8863b91ae460.jpg[/img]

图6

.找到<Engine />节点,加入属性 jvmRoute:
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">
其中tomcat1,就是前面workers.properties 配置中的分发节点名称
.找到<Cluster /> 节点,用下面内容替换:
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="6"> 
<Manager className="org.apache.catalina.ha.session.BackupManager"
expireSessionsOnShutdown="false"
notifyListenersOnReplication="true"
mapSendOptions="6"/>
<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="5001"
selectorTimeout="100"
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"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>
</Channel>
<Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"/>
<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.ClusterSessionListener"/>
</Cluster>

[img]http://dl.iteye.com/upload/attachment/404223/695e9772-eeb1-3e57-a88d-85691cf80771.jpg[/img]

图7

Apche 官方文档:[url]http://tomcat.apache.org/tomcat-6.0-doc/cluster-howto.html[/url]
介绍很清楚,当然只有这些配置还不够,官方文档里有这么一句:
(6)就是端口配置了还是在上面的server.xml中修改
第一处:

[img]http://dl.iteye.com/upload/attachment/404225/59d8f4ec-d9f7-3ba9-b032-5596bd44defb.jpg[/img]

图8

第二处

[img]http://dl.iteye.com/upload/attachment/404227/5823f07a-d846-3aa6-9abe-9bf1c112d714.jpg[/img]

图9

第三处:下图中文字讲诉work.properties 指的是workers.properties

[img]http://dl.iteye.com/upload/attachment/404229/1f031a7c-dcb5-33e3-ad25-89b47f0c0262.jpg[/img]

图10


(7)在自己的项目web.xml里面要有<distributable />属性,或是在context.xml 中的<Context />属性里加入 distributable=”true”, 这样才能分发!

先启动一个tomcat,完成后再启动另一个,依次启动完成后,再启动Apache2.2

(8)新建一个测试项目TestProject
在里面新建一个index.jsp代码如下:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'seesionTest.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>

<body>
<%
System.out.println("tomcat1-----");
System.out.println(request.getParameter("sessionAttrKey")+"--"+request.getParameter("sessionAttrValue"));
if(request.getParameter("sessionAttrKey")!=null){

session.setAttribute(request.getParameter("sessionAttrKey"),request.getParameter("sessionAttrValue")+"-----"+new Date());
}
Enumeration names= session.getAttributeNames();
while(names.hasMoreElements()){
String name=names.nextElement().toString();
%>

key:<%=name %> value:<%=session.getAttribute(name)%><br/>

<%
}
%>
<br/>
localhost:<%=request.getLocalAddr() %> 111
<form action="sessionTest.jsp" method="post">
key <input name="sessionAttrKey"/>
value<input name="sessionAttrValue"/>
<input type="submit" value="提交"/>
</form>
</body>
</html>

[url]http://localhost/TestPrtoject/index.jsp[/url] 在地址栏里面访问

这个时候在控制台看到


[img]http://dl.iteye.com/upload/attachment/404231/eaf60ffe-755b-3ac5-b28e-59e3adf60d85.jpg[/img]


图11

看到这个画面就说明你的配置成功了!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值