`
nlslzf
  • 浏览: 1026658 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Apache5.5+Tomcat6.0 集群操作手册

阅读更多
http://c-j.iteye.com/blog/364503


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.
分享到:
评论
1 楼 xiejin2008 2009-12-14  
楼主,我tomcat5可以实现集群,和session的复制,但是tomcat6就不能实现session的复制,可以到负载均衡的效果.
帮个忙

相关推荐

Global site tag (gtag.js) - Google Analytics