一、系统环境
 1、使用APACHE+TOMCAT方法来实现集群  2、Clustery主机为Centos5.6 ,tomcat 主机为Centos一台(与APACHE为同一台)、一台Asianux、一台WIN,查看一下APACHE版本与JDK版本:

[root@localhost ~]# httpd -version
Server version: Apache/2.2.3
[root@localhost ~]# java -version
java version "1.6.0_17"
OpenJDK Runtime Environment (IcedTea6 1.7.5) (rhel-1.16.b17.el5-i386)
OpenJDK Server VM (build 14.0-b16, mixed mode)  ##各TOMCAT主机JDK版本应尽量一致

2、时间的因素 所有节点的操作系统时间必须一致!不然会出现节点之间Session同步困难的现象,从而网站会很慢,从同一台NTP获取时间是个不错的主意。  

二、具体配置 1、APACHE配置

[root@localhost ~]# vi /etc/httpd/conf.d/mod_jk.conf
<ifmodule !jk_module>
LoadModule jk_module modules/mod_jk-1.2.23-apache-2.2.x-linux-i686.so   ##下载mod_jk放到/etc/httpd/modules下, 注意版本,TOMCAT官网有下载
</ifmodule>
<ifmodule jk_module>
JkWorkersFile conf/workers.properties
JkMount /* controller
</ifmodule>

建立conf/workers.properties

[root@localhost ~]# vi workers.properties
worker.list=controller,tomcat01,tomcat02,tomcat03
worker.tomcat01.port=8009
worker.tomcat01.host=localhost
worker.tomcat01.type=ajp13
worker.tomcat01.lbfactor=1        ##权重,值越大分到的请求越多
worker.tomcat02.port=8019
worker.tomcat02.host=192.168.1.190
worker.tomcat02.type=ajp13
worker.tomcat02.lbfactor=1
worker.tomcat03.port=8029
worker.tomcat03.host=192.168.1.188
worker.tomcat03.type=ajp13
worker.tomcat03.lbfactor=1
worker.controller.type=lb
worker.controller.balanced_workers=tomcat01,tomcat02,tomcat03
#worker.controller.sticky_session=1   ##粘性session,本例用复制session;

2、TOMCAT 配置  2.1.三个tomcat的AJP 端口与workers.properties中要一致

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

2.2.Engine配置

[root@localhost ~]# vi tomcat/conf/server.xml
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat01">##jvmRoute为本tomcat在workers.properties中的名字

2.3.Cluster配置 (sessions的配置)

[root@localhost ~]# vi tomcat/conf/server.xml
<cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="10"> ##异步模式下完成完成Session的拷贝并效验
     <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="4031"
                   autoBind="100"
                   selectorTimeout="1000"
                   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=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"/>##过滤一些不需要同步session的文件,提高反应速度;
       <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>

三、web应用程序中session复制配置  session复制配置则是在发布的web应用程序中的web.xml中添加

 <display -name>Tomcat</display>
    <distributable />  ##在两者之间加入这句
</web-app>