Apache5.5+Tomcat6.0 Cluster Configuration in 2008

本文详细介绍如何通过Apache和Tomcat搭建集群环境,包括下载安装、配置Apache与Tomcat、保持Session同步等步骤,并提供了测试及常见问题解答。
1、下载和安装。
下载安装apache2.2.3,tomcat6.0.(注意设置环境变量)
2、配置Apache
修改Apache安装目录下conf/httpd.conf文件.

#LoadModule proxy_module modules/mod_proxy.so
#LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
#LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
#LoadModule proxy_connect_module modules/mod_proxy_connect.so
#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
#LoadModule proxy_http_module modules/mod_proxy_http.so
修改为:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
填加以下内容(注意此配置是在1台PC开多TOMCAT进程,并注意注释的格式):
# ProxyRequests Off
#
ProxyPass / balancer://tomcatcluster/ lbmethod=byrequests stickysession=JSESSIONID nofailover=Off timeout=3 maxattempts=3
###################################################################
#
# IBmethod:
# Balancer load-balance method. Select the load-balancing scheduler method to use. Either byrequests, to perform weighted request counting or bytraffic, to perform weighted traffic byte #count balancing. Default is byrequests.
#
# stickysession:
# Balancer sticky session name. The value is usually set to something like JSESSIONID or #PHPSESSIONID, and it depends on the backend application server that # support sessions.
#
# nofailover:
# If set to On the session will break if the worker is in error state or disabled. Set this value #to On if backend servers do not support session
# replication.
#
# timeout:
# Balancer timeout in seconds. If set this will be the maximum time to wait for a free worker. #Default is not to wait.
#
# maxattempts:
# Maximum number of failover attempts before giving up.
####################################################################################

ProxyPassReverse / balancer://tomcatcluster/

<Proxy balancer://tomcatcluster>
BalancerMember ajp://localhost:8109 smax=10 route=jvm1
BalancerMember ajp://localhost:8209 smax=10 route=jvm2
BalancerMember ajp://localhost:8309 smax=10 route=jvm3
BalancerMember ajp://localhost:8409 smax=10 route=jvm4
BalancerMember ajp://localhost:8509 smax=10 route=jvm5
</Proxy>
# smax:
# Upto the Soft Maximum number of connections will be created on demand. Any connections above smax are subject to a time to live or ttl.
# route:
# Route of the worker when used inside load balancer. The route is a value appended to seesion id.
注意端口号和TOMCAT配置保持一致,并避免冲突,否则启动TOMCAT将失败.
3、配置Tomcat
安装多个TOMCAT(ZIP版本,不要安装"安装版本")

修改TOMCAT安装目录下conf/server.xml
如修改tomcat_1配置
修改:
<Server port="8105" shutdown="SHUTDOWN">
修改:
<Connectorport="8081" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8143" />
修改:
<Connectorport="8109" protocol="AJP/1.3" redirectPort="8143" />
修改:
<Engine name="Standalone" defaultHost="localhost" jvmRoute="jvm1">

修改另外几个tomcat文件,并避免端口冲突.如果多个TOMCAT安装在多个服务器则只要注意IP地址的正确.
4、保持Session同步
在TOMCAT安装目录conf/server.xml下的
<Engine>... </Engine>标签下填加如下内容:
- <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="4">
<ManagerclassName="org.apache.catalina.ha.session.DeltaManager" expireSessionsOnShutdown="false" notifyListenersOnReplication="true" />
- <!--For clustering, please take a look at documentation at:
/docs/cluster-howto.html (simple how to)
/docs/config/cluster.html (reference documentation) -->
- <!-- <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
-->
- <Channel className="org.apache.catalina.tribes.group.GroupChannel">
<MembershipclassName="org.apache.catalina.tribes.membership.McastService" address="228.0.0.4" port="45564" frequency="500" dropTime="3000" />
<ReceiverclassName="org.apache.catalina.tribes.transport.nio.NioReceiver" address="auto" port="4001" autoBind="100" selectorTimeout="5000" maxThreads="6" />
- <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
<TransportclassName="org.apache.catalina.tribes.transport.nio.PooledParallelSender" />
</Sender>
<InterceptorclassName="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector" />
<InterceptorclassName="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor" />
</Channel>
<ValveclassName="org.apache.catalina.ha.tcp.ReplicationValve" filter="" />
<ValveclassName="org.apache.catalina.ha.session.JvmRouteBinderValve" />
<DeployerclassName="org.apache.catalina.ha.deploy.FarmWarDeployer" tempDir="/tmp/war-temp/" deployDir="/tmp/war-deploy/" watchDir="/tmp/war-listen/" watchEnabled="false" />
<ClusterListenerclassName="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener" />
<ClusterListenerclassName="org.apache.catalina.ha.session.ClusterSessionListener" />
</Cluster>
#注意port="4001" 是否与其他TOMCAT进程冲突.
配置详细解释见文档"Clustering-Session Replication HOW-TO.htm"
5、修改WEB项目Web.xml
在工程项目中修改web.xml;
填加如下标签:
<distributable/>

6、Testing
打开浏览器,写一个简单的JSP,测试
http://localhost/mytest/index.jsp
http://localhost/mytest:8109/index.jsp
http://localhost/mytest:8209/index.jsp
http://localhost/mytest:8309/index.jsp
http://localhost/mytest:8409/index.jsp
http://localhost/mytest:8509/index.jsp
7、QA
问:如何配置多个服务器?
答:修改Apache 下httpd.conf文件;

<Proxy balancer://tomcatcluster>
BalancerMember ajp://localhost:8109 smax=10 route=jvm1
BalancerMember ajp://localhost:8209 smax=10 route=jvm2
BalancerMember ajp://localhost:8309 smax=10 route=jvm3
BalancerMember ajp://localhost:8409 smax=10 route=jvm4
BalancerMember ajp://localhost:8509 smax=10 route=jvm5
</Proxy>
中的localhost改成内部服务器IP地址就OK了.

问:为什么启动多个TOMCAT进程失败?
答:注意配置的TOMCAT服务各个端口是否有冲突.

问:为什么session不能保持一致?
答:需要注意以下几点:
All your session attributes must implement java.io.Serializable
If you have defined custom cluster valves, make sure you have the ReplicationValve defined as well under the Cluster element in server.xml
If your Tomcat instances are running on the same machine, make sure the tcpListenPort attribute is unique for each instance, in most cases Tomcat is smart enough to resolve this on it's own by autodetecting available ports in the range 4000-4100
Make sure your web.xml has the <distributable/> element or set at your <Context distributable="true" />
Make sure that all nodes have the same time and sync with NTP service!
Make sure that your loadbalancer is configured for sticky session mode.
学生社团系统-学生社团“一站式”运营管理平台-学生社团管理系统-基于SSM的学生社团管理系统-springboot学生社团管理系统.zip-Java学生社团管理系统开发实战-源码 更多学生社团系统: SpringBoot+Vue学生社团“一站式”运营管理平台源码(活动管理+成员考核+经费审批) Java学生社团管理系统开发实战:SSM升级SpringBoot(招新报名+场地预约+数据看板) 基于SpringSecurity的社团管理APP(移动端签到+权限分级+消息推送) 企业级社团数字化平台解决方案(SpringBoot+Redis缓存+Elasticsearch活动搜索) 微信小程序社团服务系统开发(活动直播+社团文化墙+成员互动社区) SpringBoot社团核心源码(多角色支持+工作流引擎+API接口开放) AI赋能社团管理:智能匹配兴趣标签+活动热度预测+成员贡献度分析(附代码) 响应式社团管理平台开发(PC/移动端适配+暗黑模式+无障碍访问) 完整学生社团系统源码下载(SpringBoot3+Vue3+MySQL8+Docker部署) 高校垂直领域社团平台:百团大战系统+社团星级评定+跨校活动联盟 适用对象:本代码学习资料适用于计算机、电子信息工程、数学等专业正在做毕设的学生,需要项目实战练习的学习者,也适用于课程设计、期末大作业。 技术栈:前端是vue,后端是springboot,项目代码都经过严格调试,代码没有任何bug! 核心管理:社团注册、成员管理、权限分级 活动运营:活动发布、报名签到、场地预约 资源服务:经费申请、物资管理、文档共享 数据分析:成员活跃度、活动效果评估、社团影响力排名
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值