Apache Tomcat 集群

本文介绍如何通过Apache2.2.21、Mod_JK1.2.32及Tomcat7.0.23搭建负载均衡集群。通过配置Mod_JK进行负载均衡,并使用AJP协议连接Apache与Tomcat。此外还涉及了Tomcat集群的会话复制配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

经过2天的查资料和实验,在2台机器上完成了集群的配置。
Apache2.2.21,Mod_JK 1.2.32,Tomcat 7.0.23.
用Mod JK,apache 配置load balance。
配置如下:
Apache httpd:
# Load mod_jk module. Specify the filename
# of the mod_jk lib you’ve downloaded and
# installed in the previous section
LoadModule jk_module modules/mod_jk.so

#begin JK config
# Where to find workers.properties
JkWorkersFile conf/workers.properties
# Where to put jk logs
JkLogFile logs/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel info
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"
# Add the jkstatus mount point
<Location /jkmanager/>
JkMount jkstatus
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Location>
JkMount /* loadbalancer
#end JK config

workers.properties:

# Define list of workers that will be used
# for mapping requests
worker.list=loadbalancer,jkstatus

# Define Node1
# modify the host as your host IP or DNS name.
worker.node1.port=8009
worker.node1.host=127.0.0.1
worker.node1.type=ajp13
worker.node1.lbfactor=1

# Define Node2
# modify the host as your host IP or DNS name.
worker.node2.port=8109
worker.node2.host=127.0.0.1
worker.node2.type=ajp13
worker.node2.lbfactor=1

worker.node3.port=8009
worker.node3.host=192.168.0.3
worker.node3.type=ajp13
worker.node3.lbfactor=1

# Load-balancing behaviour
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=node1,node2,node3
worker.loadbalancer.sticky_session=1
#worker.list=loadbalancer

# Status worker for managing load balancer
worker.jkstatus.type=status

关于反向代理,Tomcat AJP已经支持.[url]http://tomcat.apache.org/connectors-doc/generic_howto/proxy.html[/url]
AJP配置[url]http://tomcat.apache.org/connectors-doc/index.html[/url]
下面关于Http Session的复制:
Tomcat Catalina Tribes提供了复制功能,这个也能在官方文档上找到。当然,可以考虑使用Jgroups等实现。配置详细说明[url]http://tomcat.apache.org/tomcat-7.0-doc/cluster-howto.html[/url].
完全按照官方文档可以实现。具体其他详细的配置,在需要的时候,去查看Tribes的配置信息。
集群测试用列见附件.
注意在webapp中web.xml需要加上<distributable/>.
在本地已经测试成功!
另外,Tribes使用IP广播在集群节点之间传输信息。在本地配置集群时, Receiver:className="org.apache.catalina.tribes.transport.nio.NioReceiver"的port不能与另外一个相同!
并且要关闭本地的firewall。
使用tomcat-replication.jar[url]http://cvs.apache.org/~fhanik/tomcat-replication.jar[/url]测试IP广播。
java -cp tomcat-replication.jar MCaster 228.0.0.4 45564 Terminal1

在Tribes中,对于使用静态的成员配置,见[url]https://issues.apache.org/bugzilla/show_bug.cgi?id=52263[/url].
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值