Apache+Tomcat集群

准备环境 

下载 

Apache HTTP Server http://labs.mop.com/apache-mirror/httpd/binaries/win32/ 下载httpd-2.2.22-win32-x86-no_ssl.msi

JK http://www.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/windows/ 下载tomcat-connectors-1.2.37-windows-i386-httpd-2.2.x.zip

Tomcat http://tomcat.apache.org/download-70.cgi

安装

安装Apache HTTP Server,如果没有其他的http服务器(如iis)则应该可以成功安装,端口即为80,能够访问http://localhost/ 说明安装成功。

安装Tomcat7,下载tomcat7解压缩为4个tomcat文件,分别命名tomcat1、tomcat2、tomcat3、tomcat4.

tomcat6.X与tomcat7.X集群通用。

配置

Apache配置

1、修改httpd.conf

在Apache安装目录下找到conf目录下的httpd.conf,在文件的最后一行添加

include conf/mod_jk.conf

2、新建mod_jk.conf文件,内容如下:

LoadModule jk_module modules/mod_jk.so

JkWorkersFile conf/workers.properties

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

JkMount /* controller

3、将下载的JK插件解压拷贝mod_jk.so,复制到Apache安装目录的modules目录下。

4、在apache的安装目录conf下新建并编辑workers.properties文件,内容如下:

#server

worker.list = controller

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

worker.tomcat1.port=8719

worker.tomcat1.host=localhost

worker.tomcat1.type=ajp13

worker.tomcat1.lbfactor = 1

worker.tomcat1.redirect=tomcat2

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

worker.tomcat2.port=8729

worker.tomcat2.host=localhost

worker.tomcat2.type=ajp13

worker.tomcat2.lbfactor = 1

worker.tomcat2.redirect=tomcat1

#worker.tomcat2.activation=disabled

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

worker.tomcat3.port=8739

worker.tomcat3.host=localhost

worker.tomcat3.type=ajp13

worker.tomcat3.lbfactor = 1

worker.tomcat3.redirect=tomcat4

#========tomcat4========

worker.tomcat4.port=8749

worker.tomcat4.host=localhost

worker.tomcat4.type=ajp13

worker.tomcat4.lbfactor = 1

worker.tomcat4.redirect=tomcat3

#worker.tomcat4.activation=disabled  

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

worker.controller.type=lb

worker.controller.balanced_workers=tomcat1,tomcat2,tomcat3,tomcat4

worker.controller.sticky_session=false

#worker.controller.sticky_session_force=1

#worker.controller.sticky_session=1

PS:#worker.tomcat4.activation=disabled  表示tomcat是否激活

tomcat配置

Tomcat1中server.xml配置:

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

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

<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">

<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"/>   

            <!-- timeout="60000"-->   

            <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"/>   

            <Interceptor classname="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>   

          </Channel>   

  

          <Valve classname="org.apache.catalina.ha.tcp.ReplicationValve" filter=""/>   

          <Valve classname="org.apache.catalina.ha.session.JvmRouteBinderValve"/>   

  

          <ClusterListener classname="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>   

          <ClusterListener classname="org.apache.catalina.ha.session.ClusterSessionListener"/>   

        </Cluster>

....

 <Host name="localhost"  appBase="C:\tomcat7-ex\webapps"

            unpackWARs="true" autoDeploy="true">

Tomcat2中server.xml配置:

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

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

<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat2">

<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"/>   

            <!-- timeout="60000"-->   

            <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"/>   

            <Interceptor classname="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>   

          </Channel>   

  

          <Valve classname="org.apache.catalina.ha.tcp.ReplicationValve" filter=""/>   

          <Valve classname="org.apache.catalina.ha.session.JvmRouteBinderValve"/>   

  

          <ClusterListener classname="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>   

          <ClusterListener classname="org.apache.catalina.ha.session.ClusterSessionListener"/>   

        </Cluster>

....

 <Host name="localhost"  appBase="C:\tomcat7-ex\webapps"

            unpackWARs="true" autoDeploy="true">

Tomcat3中server.xml配置:

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

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

<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat3">

<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.5"  

                        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"/>   

            <!-- timeout="60000"-->   

            <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"/>   

            <Interceptor classname="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>   

          </Channel>   

  

          <Valve classname="org.apache.catalina.ha.tcp.ReplicationValve" filter=""/>   

          <Valve classname="org.apache.catalina.ha.session.JvmRouteBinderValve"/>   

  

          <ClusterListener classname="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>   

          <ClusterListener classname="org.apache.catalina.ha.session.ClusterSessionListener"/>   

        </Cluster>

...

 <Host name="localhost"  appBase="C:\tomcat7-ex\webapps"

            unpackWARs="true" autoDeploy="true">

Tomcat4中server.xml配置:

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

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

<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat4">

<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.5"  

                        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"/>   

            <!-- timeout="60000"-->   

            <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"/>   

            <Interceptor classname="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>   

          </Channel>   

  

          <Valve classname="org.apache.catalina.ha.tcp.ReplicationValve" filter=""/>   

          <Valve classname="org.apache.catalina.ha.session.JvmRouteBinderValve"/>   

  

          <ClusterListener classname="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>   

          <ClusterListener classname="org.apache.catalina.ha.session.ClusterSessionListener"/>   

        </Cluster>

...

     <Host name="localhost"  appBase="C:\tomcat7-ex\webapps"

            unpackWARs="true" autoDeploy="true">

注意AJP13的connector的poat和jvmRoute名称和workers.properties中配置对应。228.0.0.4和228.0.0.5表示tomcat的群组

基于windows环境搭建完毕,参考文档如下

2、对tomcat cluster集群配置中session复制用法的一个误解 http://618119.com/archives/2007/11/13/26.html

相关推荐