基于modproxy+Apache 2216+Tomcat 7的负载均衡与集群配置文档格式.docx
- 文档编号:19706821
- 上传时间:2023-01-09
- 格式:DOCX
- 页数:17
- 大小:583.97KB
基于modproxy+Apache 2216+Tomcat 7的负载均衡与集群配置文档格式.docx
《基于modproxy+Apache 2216+Tomcat 7的负载均衡与集群配置文档格式.docx》由会员分享,可在线阅读,更多相关《基于modproxy+Apache 2216+Tomcat 7的负载均衡与集群配置文档格式.docx(17页珍藏版)》请在冰豆网上搜索。
•IfyourTomcatinstancesarerunningonthesamemachine,makesurethetcpListenPortattributeisuniqueforeachinstance,inmostcasesTomcatissmartenoughtoresolvethisonit'
sownbyautodetectingavailableportsintherange4000-4100。
参照四<
Receiver>
中的注释
•Makesureyourweb.xmlhasthe<
distributable/>
elementorsetatyour<
Contextdistributable="
true"
/>
参照四
•Ifyouareusingmod_jk,makesurethatjvmRouteattributeissetatyourEngine<
Enginename="
Catalina"
jvmRoute="
node01"
>
andthatthejvmRouteattributevaluematchesyourworkernameinworkers.properties.用mod_jk的情况,我们可以不管。
•MakesurethatallnodeshavethesametimeandsyncwithNTPservice!
当使用多台机器时,要保证不同机器时间的同步。
原因为tomcatsession复制的一些机制。
具体原因看文档。
•Makesurethatyourloadbalancerisconfiguredforstickysessionmode.保证负载均衡软件设置为sessionsticky模式。
四、详细配置:
1.修改tomcat7_a/conf/server.xml,我们采用的是默认的配置,在<
Engine>
节点下添加:
Java代码
1.<
Cluster
className="
org.apache.catalina.ha.tcp.SimpleTcpCluster"
2.
channelSendOptions="
8"
>
3.
4.
<
Manager
org.apache.catalina.ha.session.DeltaManager"
5.
expireSessionsOnShutdown="
false"
6.
notifyListenersOnReplication="
/>
7.
8.
Channel
org.apache.catalina.tribes.group.GroupChannel"
9.
Membership
org.apache.catalina.tribes.membership.McastService"
10.
address="
228.0.0.4"
11.
port="
45564"
12.
frequency="
500"
13.
dropTime="
3000"
14.
Receiver
org.apache.catalina.tribes.transport.nio.NioReceiver"
15.
auto"
16.<
!
—tcpListenPort如果是同一机器部署两个tomcat7应用,则修改tomcat7_b为4001,以免冲突.
不同机器下,不用更改此项。
—>
17.
[color=red]port="
4000"
[/color]
18.
autoBind="
100"
19.
selectorTimeout="
5000"
20.
maxThreads="
6"
21.
22.
Sender
org.apache.catalina.tribes.transport.ReplicationTransmitter"
23.
Transport
org.apache.catalina.tribes.transport.nio.PooledParallelSender"
24.
/Sender>
25.
Interceptor
org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"
26.
org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"
27.
/Channel>
28.
29.
Valve
org.apache.catalina.ha.tcp.ReplicationValve"
30.
filter="
"
31.
org.apache.catalina.ha.session.JvmRouteBinderValve"
32.
33.
Deployer
org.apache.catalina.ha.deploy.FarmWarDeployer"
34.
tempDir="
/tmp/war-temp/"
35.
deployDir="
/tmp/war-deploy/"
36.
watchDir="
/tmp/war-listen/"
37.
watchEnabled="
38.
39.
ClusterListener
org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"
40.
org.apache.catalina.ha.session.ClusterSessionListener"
41.
/Cluster>
ClusterclassName="
channelSendOptions="
<
ManagerclassName="
expireSessionsOnShutdown="
notifyListenersOnReplication="
ChannelclassName="
MembershipclassName="
address="
port="
frequency="
dropTime="
ReceiverclassName="
—tcpListenPort如果是同一机器部署两个tomcat7应用,则修改tomcat7_b为4001,以免冲突.不同机器下,不用更改此项。
[color=red]port="
[/color]
autoBind="
selectorTimeout="
maxThreads="
SenderclassName="
TransportclassName="
InterceptorclassName="
ValveclassName="
filter="
DeployerclassName="
tempDir="
deployDir="
watchDir="
watchEnabled="
ClusterListenerclassName="
2.<
Connectorport="
8081"
protocol="
HTTP/1.1"
connectionTimeout="
20000"
redirectPort="
8443"
修改,仅为了调试方便。
3.tomcat7_a\webapps\cluster\WEB-INF\web.xml中加入<
4.<
defaultHost="
localhost"
tomcat7_a"
添加jvmRoute属性,此项为后面apache负载均衡用到。
五、复制一份tomcat7_a应用,改名为tomcat7_b.只是为了图方便,实际应该复制的是前面的cluster工程。
注意以下几点配置就ok.
1.修改tomcat7_a/conf/server.xml中的Serverport属性<
Serverport="
8006"
shutdown="
SHUTDOWN"
因为是同一台机器两个tomcat应用,所以改一下。
2.修改<
connectorport="
8082"
onnectionTimeout="
edirectPort="
同理,为了避免同一台机器端口号冲突。
部置在不同的机器是不用管的。
3.修改<
tomcat7_b"
,此项为后面apache负载均衡用到。
4.修改<
:
className="
4001"
5.tomcat7_b\ebapps\cluster\WEB-INF\web.xml中加入<
到此集群配置完成.
第五章.集群测试
1.tomcat7_a和tomcat7_b的cluster工程中分别添加测试文件:
testCluster.jsp
%@
page
contentType="
text/html;
charset=GBK"
%>
import="
java.util.*"
3.<
html>
head>
title>
Test<
/title>
/head>
body>
5.<
%
//HttpSession
session
=
request.getSession(true);
System.out.println(session.getId());
out.println("
br>
SESSION
ID:
+
session.getId()+"
);
//
如果有新的请求,则添加session属性
String
name
request.getParameter("
name"
if
(name
null
&
name.length()
0)
{
value
value"
session.setAttribute(name,
value);
}
out.print("
b>
Session
List:
/b>
16.
Enumeration<
String>
names
session.getAttributeNames();
while
(names.hasMoreElements())
sname
names.nextElement();
session.getAttribute(sname).toString();
out.println(
value+"
System.out.println(
23.%>
form
action="
testCluster.jsp"
method="
post"
名称:
input
type=text
size=20
name="
值:
type=submit
value="
提交"
/form>
31.<
/body>
32.<
/html>
%@pagecontentType="
charset=GBK"
%>
%@pageimport="
ClusterTest<
%
//HttpSessionsession=request.getSession(true);
System.out.println(session.getId());
out.println("
SESSIONID:
+session.getId()+"
//如果有新的请求,则添加session属性
Stringname=request.getParameter("
if(name!
=null&
name.length()>
0){
Stringvalue=request.getParameter("
session.setAttribute(name,value);
}
out.print("
SessionList:
Enumeration<
names=session.getAttributeNames();
while(names.hasMoreElements()){
Stringsname=names.nextElement();
Stringvalue=session.getAttribute(sname).toString();
out.println(sname+"
="
+value+"
System.out.println(sname+"
+value);
}
formaction="
method="
名称:
inputtype=textsize=20name="
值:
inputtype=submitvalue="
2.启动tomcat7_a,启动完毕后,启动tomcat7_b
3.进入http:
//localhost:
8081/cluster/testCluster.jsp对应tomcat7_a(8081),登录几次,可看到
4.另外打开一个浏览器,进入http:
8082/cluster/testCluster.jsp对应tomcat7_b(8082),登录name:
tomcat_b,value:
bvalue可看到
5.刷新tomcat7_a(8081)相关页面,可以看到从tomcat7_b提交的值session同步过来了,说明集群成功。
第六章.Session集群工作步骤
参
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 基于modproxy+Apache 2216+Tomcat 7的负载均衡与集群配置 基于 modproxy Apache 2216 Tomcat 负载 均衡 集群 配置
链接地址:https://www.bdocx.com/doc/19706821.html