请通过浏览器功能收藏网页

apache Tomcat 构建小型集群服务 tomcat

发布时间:2020-01-09 12:17:21  作者:本站编辑  来源:本站原创  浏览次数:
我有话说 | 分享 |
www.javainfo.com.cn 上干货 欢迎收藏


这里是tomcat小集群搭建示意图,标识出 软件分布位置。

         image.png

        说明:  apache: 负责负载;

                    tomcat :负责业务处理及资源处理;

                    mod_jk : 负责 tomcat之间会话同步。


搭建流程:

  1 软件下载:  http://archive.apache.org/dist/ 

   apache :    /httpd/binaries/win32/httpd-2.2.25-win32-x86-no_ssl.msi

   tomcat:     /tomcat/..

   mod_jk:    /tomcat/tomcat-connectors/jk/..

 2 软件安装过程不再说明,安装目录后结构:

    image.png

 3  开始配置各个软件

       一、apache22

         1. 将下载的mod_jk-1.2.31-httpd-2.2.3.so放到  {apache path}\modules目录下

      2. 打开:apache 的conf文件目录下 新建 mod_jk.conf: 在其内加如下代码:               

            #加载mod_jk Module

            LoadModule jk_module modules/mod_jk-1.2.31-httpd-2.2.3.so             

            #指定workers.properties文件路径

            JkWorkersFile conf/workers.properties             

            #指定那些请求交给tomcat处理,"controller"为在tomcats.propertise里指定的负载分配控制器名

            JkMount /* controller

           3 在Apache 的conf目录下 新建tomcats.properties 文件,并添加如下内容:                  

                #serverController

                worker.list = controller    ##此name的名字与上面的配置的名字是一致的

                #========tomcat1========

                #ajp1.3端口号,在tomcatserver.xml配置,默认8009

                worker.tomcat1.port=8009                 

                #tomcat的主机地址,如不为本机,请填写ip地址

                worker.tomcat1.host=localhost         #暴露前台的访问地址          

                #协议类型

                worker.tomcat1.type=ajp13                 

                #server的加权比重,值越高,分得的请求越多。lbfactor是负载平衡因数(Load Balance Factor)

                worker.tomcat1.lbfactor=1                 

                #========tomcat2========

                worker.tomcat2.port=8010

                worker.tomcat2.host= localhost

                worker.tomcat2.type=ajp13

                worker.tomcat2.lbfactor=1                

                #========tomcat3========

                worker.tomcat3.port=8011

                worker.tomcat3.host= localhost

                worker.tomcat3.type=ajp13

                worker.tomcat3.lbfactor=1

                 

                #========controller,负载均衡控制器========

                #负载均衡控制器类型,lbfactor是负载平衡因数(Load Balance Factor)

                worker.controller.type=lb                 

                #指定分担请求的tomcat列表 

                worker.controller.balanced_workers=tomcat1,tomcat2,tomcat3     #此名字与tomcat的jvmRoute="tomcat2"  是一致的

                #粘性session(默认是打开的) 当该属性值=true(或1)时,代表session是粘性的,即同一session在集群中的

        同一个节点上处理,session不跨越节点。在集群环境中,一般将该值设置为false

                worker.controller.sticky_session=false                 

                #设置用于负载均衡的serversession可否共享

                worker.controller.sticky_session_force=1

            4 在apache的 httpd.conf文件内 尾部添加加载mod_jk的代码               

                    Include conf/mod_jk.conf

           二、分别配置tomcat的配置文件 server.xml

                    1 分别配置engine标签:  注意:jvmRoute的名字就是 tomcats.properties 里配置 分担请求的tomcat列表 中的名字 

                          image.png 

            2 分别配置 JAP协议的端口 ,这些端口要与 tomcats.properties里配置的  worker.tomcat3.port=8011 分别保持一致

                image.png                    

                 3   在每个tomcat的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="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>

                  

                 4 分别修改tomcat的启动端口 关闭端口 保证,每个tomcat启动不会报错


4  分别启动 Apache ,tomcat服务,经过测试  配置成功

             

            image.png

            image.png

            image.png

                访问测试:OK 

                  image.pngimage.png



如有疑问 请留言 欢迎提供建议
  • 0

    开心

  • 0

    板砖

  • 0

    感动

  • 0

    有用

  • 0

    疑问

  • 0

    难过

  • 0

    无聊

  • 0

    震惊

评论已有 0