设为首页 收藏本站
查看: 680|回复: 0

[经验分享] apache+多tomcat集群配置过程记录

[复制链接]

尚未签到

发表于 2017-1-3 10:25:48 | 显示全部楼层 |阅读模式
  1.下载所需的文件
  apache
  http://labs.renren.com/apache-mirror/httpd/binaries/win32/httpd-2.2.20-win32-x86-no_ssl.msi

  tomcat
  http://labs.renren.com/apache-mirror/tomcat/tomcat-6/v6.0.33/bin/apache-tomcat-6.0.33.zip

  connectors
  http://labs.renren.com/apache-mirror/tomcat/tomcat-connectors/jk/binaries/windows/tomcat-connectors-1.2.32-windows-i386-httpd-2.2.x.zip

  2.例子安装目录
  tomcatA
  F:\cluster\tomcatA
  tomcatB
  F:\cluster\tomcatB
  apachex
  F:\cluster\Apache2.2
  connectors放到F:\cluster\Apache2.2\modules
  3.修改F:\cluster\Apache2.2\conf\httpd.conf,添加
  include "F:\cluster\Apache2.2\conf\mod_jk.conf"
  4.新建F:\cluster\Apache2.2\conf\mod_jk.conf,内容如下
  #加载mod_jk Module
  LoadModule jk_module modules/mod_jk.so
  #指定 workers.properties文件路径
  JkWorkersFile conf/workers.properties
  #指定那些请求交给tomcat处理,"controller"为在workers.propertise里指定的负载分配控制器
  JkMount /*.jsp controller
  5.新建workers.properties,内容如下
  worker.list = controller,tomcat1,tomcat2  #server 列表
  #========tomcat1========
  worker.tomcat1.port=8009         #ajp13 端口号,在tomcat下server.xml配置,默认8009
  worker.tomcat1.host=localhost  #tomcat的主机地址,如不为本机,请填写ip地址
  worker.tomcat1.type=ajp13
  worker.tomcat1.lbfactor = 1   #server的加权比重,值越高,分得的请求越多
  #========tomcat2========
  worker.tomcat2.port=9009       #ajp13 端口号,在tomcat下server.xml配置,默认8009
  worker.tomcat2.host=localhost  #tomcat的主机地址,如不为本机,请填写ip地址
  worker.tomcat2.type=ajp13
  worker.tomcat2.lbfactor = 1   #server的加权比重,值越高,分得的请求越多
  #========controller,负载均衡控制器========
  worker.controller.type=lb
  worker.controller.balanced_workers=tomcat1,tomcat2   #指定分担请求的tomcat
  worker.controller.sticky_session=1
  6.修改两个tomcat的server.xml,端口部分为了简便,保留tomcatA为默认端口,tomcatB的端口加1000,修改F:\cluster\tomcatA\conf\server.xml
  engine最后添加jvmRoute="tomcatB",修改后:
  <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcatB">
  engine标签下添加

<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
channelSendOptions="8">
<Manager className="org.apache.catalina.ha.session.DeltaManager"
expireSessionsOnShutdown="false"
notifyListenersOnReplication="true"/>
<Channel className="org.apache.catalina.tribes.group.GroupChannel">
<!--
<Membership className="org.apache.catalina.tribes.membership.McastService"
address="192.168.1.105"
port="45564"
frequency="500"
dropTime="3000"/>
-->
<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
address="auto"
port="4000"
autoBind="100"
selectorTimeout="5000"
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"/>
</Channel>
<Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
filter=""/>
<Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>
<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.JvmRouteSessionIDBinderListener"/>
<ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
</Cluster>
  tomcatB的server.xml需要修改的部分:
  Server port="9005"
  <Connector port="9080" protocol="HTTP/1.1" 
  connectionTimeout="20000" 
  redirectPort="8443" />
  <Connector port="9009" protocol="AJP/1.3" redirectPort="8443" />
  <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcatB">
  <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
  channelSendOptions="8">
  <Manager className="org.apache.catalina.ha.session.DeltaManager"
  expireSessionsOnShutdown="false"
  notifyListenersOnReplication="true"/>
  <Channel className="org.apache.catalina.tribes.group.GroupChannel">
  
 <!--
  <Membership className="org.apache.catalina.tribes.membership.McastService"
  address="192.168.1.105"
  port="45564"
  frequency="500"
  dropTime="3000"/>
  
-->
  <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
  address="auto"
  port="5000"
  autoBind="100"
  selectorTimeout="5000"
  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"/>
  </Channel>
  <Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
  filter=""/>
  <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>
  <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.JvmRouteSessionIDBinderListener"/>
  <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
  </Cluster>
  7.放入测试文件,F:\cluster\tomcatA\webapps\test\test.jsp,F:\cluster\tomcatB\webapps\test\test.jsp

<%
System.out.println(new java.util.Date().toLocaleString());
out.println(new java.util.Date().toLocaleString());
out.println(session.getId());
%>
  新建F:\cluster\tomcatA\webapps\test\WEB-INF\web.xml,F:\cluster\tomcatB\webapps\test\WEB-INF\web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>Tomcat Documentation</display-name>
<description>
Tomcat Documentation.
</description>
<distributable/>
</web-app>

   注意web.xml的<distributable/>

  8.搞定,测试http://localhost/test/test.jsp可以看到两个tomcat都可以正常工作
  
DSC0000.gif

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-323156-1-1.html 上篇帖子: org.apache.axis2.AxisFault: Read timed out 下篇帖子: Apache配置多个站点(非虚拟目录)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表