tomcat集群

1】 下载安装

       httpd-2.2.15-win32-x86-no_ssl.msi    网页服务器

       32-bit Windows zip                            tomcat

       mod_jk-1.2.30-httpd-2.2.3.so             Apache/IIS 用来连接后台Tomcat的模块,支持集群和负载均衡

       JK 分为两个版本 1,x 和 2.x ,其中 2.x 并不是最新的版本,它是 JK 的另外一个分支,后不知何因没有继续开发,因此2.x 版本已经废弃

       安装httpd-2.2.15-win32-x86-no_ssl.msi 到指定目录,我安装的是C:\Program Files\Apache2.2,以后这个目录将用Apache_Home代替

       安装tomcat,我是将两个tomcat进行集群,所以安装两个tomcat,路径分别为:F:\tomcat\tomcat1,F:\tomcat\tomcat2,以后这两个目录将用tomcat1_Home,tomcat2_Home代替

2】 配置Apache_Home\conf\httpd.conf

      在httpd.conf文件的最后一行写入include "C:\Program Files\Apache2.2\conf\mod_jk.conf"

3】 配置mod_jk.conf文件

      在Apache_Home\conf下建立mod_jk.conf文件

      配置内容:

      #加载mod_jk Module
         LoadModule jk_module modules/mod_jk-1.2.30-httpd-2.2.3.so

         将下载的 mod_jk-1.2.30-httpd-2.2.3.so 文件放入到Apache_Home\modules下
      # 配置 mod_jk
      #加载集群中的workers
         JkWorkersFile conf/workers.properties
      #加载workers的请求处理分配文件
         JkMountFile conf/uriworkermap.properties
      #指定jk的日志输出文件
         JkLogFile logs/mod_jk.log
      #指定日志级别
         JkLogLevel warn
     #指定哪些请求交给tomcat处理,"controller"为在 workers.propertise里指定的负载分配控制器名
         JkMount /* controller

4】  配置workers.propertise文件

       在Apache_Home\conf下建立workers.propertise文件

       配置内容:

       #server 列表
         worker.list=controller,tomcat1,tomcat2
      #========tomcat1========
      #ajp13 端口号,在tomcat下server.xml配置,默认8009
        worker.tomcat1.port=8009
      #tomcat的主机地址,如不为本机,请填写ip地址
        worker.tomcat1.host=localhost
        worker.tomcat1.type=ajp13
     #server的加权比重,值越高,分得的请求越多
        worker.tomcat1.lbfactor=1
     #========tomcat2========
     #ajp13 端口号,在tomcat下server.xml配置,默认8009
       worker.tomcat2.port=9009
     #tomcat的主机地址,如不为本机,请填写ip地址
      worker.tomcat2.host=localhost
      worker.tomcat2.type=ajp13
    #server的加权比重,值越高,分得的请求越多
       worker.tomcat2.lbfactor=1
    #========controller,负载均衡控制器========
    #server名为controller,用于负载均衡
      worker.controller.type=lb
   #重试次数
      worker.retries=3
   #指定分担请求的tomcat
     worker.controller.balanced_workers=tomcat1,tomcat2
   #粘性Session(默认是打开的) 当该属性值=True(或1)时,代表Session是粘性的,即同一Session在集群中的同一个节点上处理,Session不跨越节点。在集群环境中,一般将该值设置为False
     worker.controller.sticky_session=false
  #设置用于负载均衡的server的session可否共享 有不少文章说设置为1是可以的,也有设置为0才可以的
     worker.controller.sticky_session=1
  #worker.controller.sticky_session_force=1
  #worker.status.type=status

5】 配置uriworkermap.properties文件

      在Apache_Home\conf下建立uriworkermap.properties文件

      配置内容:

     #所有请求都由controller这个server处理
     /*=controller
     #所有包含jkstatus请求的都由status这个 server处理
     #/jkstatus=status
     #这里的"!”是“非”的意思。
     !/*.gif=controller
     !/*.jpg=controller
     !/*.png=controller
     !/*.css=controller
     !/*.js=controller
     !/*.htm=controller
     !/*.html=controller

6】修改tomcat1_Home\conf\server.xml配置

      Starting Coyote HTTP/1.1 on http-8081 默认端口为8080,修改为8081

     <Connector port="8081" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

      JK: ajp13 listening on /0.0.0.0:8009 修改端口必须与workers.propertise文件内worker.tomcat1.port=8009一致

     <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

     需要添加的内容:

    <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat2">   <!--tomcat1将与tomcat2黏贴session 在这里指定黏贴对象-->

      <!--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"
                 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="228.0.0.4"
                        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>   

      上面部分如果需要详细的说明可以看webapps\docs\cluster-howto.html

7】修改tomcat2_Home\conf\server.xml配置

      Starting Coyote HTTP/1.1 on http-8082 默认端口为8080,修改为8082

     <Connector port="8082" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

      JK: ajp13 listening on /0.0.0.0:9009 修改端口必须与workers.propertise文件内worker.tomcat2.port=9009一致

     <Connector port="9009" protocol="AJP/1.3" redirectPort="8443" />

     需要添加的内容:

    <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">   <!--tomcat2将与tomcat1黏贴session 在这里指定黏贴对象-->

      <!--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"
                 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="228.0.0.4"
                        port="45564"
                        frequency="500"
                        dropTime="3000"/>
            <Receiver className="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">
              <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>   

      上面部分如果需要详细的说明可以看webapps\docs\cluster-howto.html

8】session黏贴(共享)方面,如果session中存放的为javabean,javabean必须实现Serializable接口,如果没有实现会报错误 Exception thrown: class java.lang.IllegalArgumentException


9】补充:

 

      看到jameswxx的回复发现确实有欠妥的地方,现在进行改正

      在工程的web.xml文件内加入 <distributable/>    标签

      标题名不够准确,将原名称“tomcat集群配置流程”更正为“基于apache的tomcat负载均衡和集群配置”

 

 

 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/388471.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

pdf.js插件使用记录,在线打开pdf

pdf.js插件使用记录&#xff0c;在线打开pdf 原文:pdf.js插件使用记录&#xff0c;在线打开pdf天记录一个js库&#xff1a;pdf.js。主要是实现在线打开pdf功能。因为项目需求需要能在线查看pdf文档&#xff0c;所以就研究了一下这个控件。 有些人很好奇&#xff0c;在线打开pdf…

程序员 sql面试_非程序员SQL使用指南

程序员 sql面试Today, the word of the moment is DATA, this little combination of 4 letters is transforming how all companies and their employees work, but most people don’t really know how data behaves or how to access it and they also think that this is j…

Apache+Tomcat集群负载均衡的两种session处理方式

session共享有两种方式&#xff1a; 1、session共享&#xff0c;多个服务器session拷贝保存&#xff0c;一台宕机不会影响用户的登录状态&#xff1b; 2、请求精确集中定位&#xff0c;即当前用户的请求都集中定位到一台服务器中&#xff0c;这样单台服务器保存了用户的sessi…

SmartSVN:File has inconsistent newlines

用SmartSVN提交文件的时候&#xff0c;提示svn: File has inconsistent newlines 这是由于要提交的文件编码时混合了windows和unix符号导致的。 解决方案 SmartSVN设置做如下修改可以解决问题&#xff1a; Project–>Setting选择Working copy下的EOL-style将Default EOL-sty…

我要认真学Git了 - Config

有一天&#xff0c;当我像往常一样打开SourceTree提交代码&#xff0c;然后推送的时候&#xff0c;我突然意识到我只是根据肌肉记忆完成这个过程&#xff0c;我压根不知道这其中到底发生了什么。这是个很严重的问题&#xff0c;作为一个技术人员&#xff0c;居然只满足于使用工…

计算机科学与技术科研论文,计算机科学与技术学院2007年度科研论文一览表

1Qiang Sun,Xianwen Zeng, Raihan Ur Rasool, Zongwu Ke, Niansheng Chen. The Capacity of Wireless Ad Hoc Networks with Power Control. IWCLD 2007. (EI收录: 083511480101)2Hong jia ping. The Application of the AES in the Bootloader of AVR Microcontroller. In: DC…

r a/b 测试_R中的A / B测试

r a/b 测试什么是A / B测试&#xff1f; (What is A/B Testing?) A/B testing is a method used to test whether the response rate is different for two variants of the same feature. For instance, you may want to test whether a specific change to your website lik…

一台机器同时运行两个Tomcat

如果不加任何修改&#xff0c;在一台服务器上同时运行两个Tomcat服务显然会发生端口冲突。假设现在已经按照正常的方式安装配置好了第一个Tomcat,第二个如何设置呢&#xff1f;以下是使用Tomcat5.5解压版本所做的实验。 解决办法&#xff1a; 1.解压Tomcat到一个新的目录&#…

PHP获取IP地址的方法,防止伪造IP地址注入攻击

PHP获取IP地址的方法,防止伪造IP地址注入攻击 原文:PHP获取IP地址的方法,防止伪造IP地址注入攻击PHP获取IP地址的方法 /*** 获取客户端IP地址* <br />来源&#xff1a;ThinkPHP* <br />"X-FORWARDED-FOR" 是代理服务器通过 HTTP Headers 提供的客户端IP。…

工作10年厌倦写代码_厌倦了数据质量讨论?

工作10年厌倦写代码I have been in tons of meetings where data and results of any sort of analysis have been presented. And most meetings have one thing in common, data quality is being challenged and most of the meeting time is used for discussing potential…

Java基础回顾

内容&#xff1a; 1、Java中的数据类型 2、引用类型的使用 3、IO流及读写文件 4、对象的内存图 5、this的作用及本质 6、匿名对象 1、Java中的数据类型 Java中的数据类型有如下两种&#xff1a; 基本数据类型: 4类8种 byte(1) boolean(1) short(2) char(2) int(4) float(4) l…

oracle数据库 日志满了

1、 数据库不能启动SQL> startupORACLE 例程已经启动。Total System Global Area 289406976 bytesFixed Size 1248576 bytesVariable Size 83886784 bytesDatabase Buffers 197132288 bytesRedo Buffers 7139328 byt…

计算机应用基础学生自查报告,计算机应用基础(专科).docx

1.在资源管理器中&#xff0c;如果要选择连续多个文件或文件夹&#xff0c;需要单击第一个文件或文件夹&#xff0c;按下键盘()&#xff0c;再用鼠标单击最后一个文件或文件夹即可。(A)Shift(B)Tab(C)Alt(D)Ctrl分值&#xff1a;2完全正确?得分&#xff1a;2?2.下列数据能被E…

Random随机数

Random 随机数 1 产生随机数 1.1 Random的使用步骤 我们想产生1-100(包含1和100)的随机数该怎么办&#xff1f;我们不需要自己写算法&#xff0c;因为额Java已经为我们提供好了产生随机数的类---Random 作用&#xff1a;用于产生一个随机数 使用步骤(和Scanner类似)&#xff1a…

模拟一个简单计算器_阅读模拟器的简单介绍

模拟一个简单计算器Read simulators are widely being used within the research community to create synthetic and mock datasets for analysis. In this article, I will introduce some recently proposed, commonly used read simulators.阅读模拟器在研究社区中被广泛使…

计算机部分应用显示模糊,win10系统打开部分软件字体总显示模糊的解决方法-电脑自学网...

win10系统打开部分软件字体总显示模糊的解决方法。方法一&#xff1a;win10软件字体模糊1、首先&#xff0c;在Win10的桌面点击鼠标右键&#xff0c;选择“显示设置”。2、在“显示设置”的界面下方&#xff0c;点击“高级显示设置”。3、在“高级显示设置”的界面中&#xff0…

Tomcat调节

Tomcat默认可以使用的内存为128MB&#xff0c;在较大型的应用项目中&#xff0c;这点内存是不够的&#xff0c;需要调大,并且Tomcat本身不能直接在计算机上运行&#xff0c;需要依赖于硬件基础之上的操作系统和一个java虚拟机。 AD&#xff1a; 这里向大家描述一下如何使用Tom…

假如不工作了,你还有源源不断的收入吗?

拥有金山跟银矿&#xff0c;其实不值得羡慕。俗话说&#xff1a;授人以鱼不如授人以渔。与其选择万贯家财&#xff0c;倒不如选择一个会持续冒出钱的杯子。很多人害怕上班的收入不确定&#xff0c;上班族急于寻找双薪&#xff0c;下班之后还要辛勤工作&#xff0c;以为这样就可…

turtle 20秒画完小猪佩奇“社会人”

转载&#xff1a;https://blog.csdn.net/csdnsevenn/article/details/80650456 图片源自网络 作者 丁彦军 如需转载&#xff0c;请联系原作者授权。 今年社交平台上最火的带货女王是谁&#xff1f;范冰冰&#xff1f;杨幂&#xff1f;Angelababy&#xff1f;不&#xff0c;是猪…

最佳子集aic选择_AutoML的起源:最佳子集选择

最佳子集aic选择As there is a lot of buzz about AutoML, I decided to write about the original AutoML; step-wise regression and best subset selection. Then I decided to ignore step-wise regression because it is bad and should probably stop being taught. That…