测试了一天,终于可以工作了,配置大致如下:

Apache2.2+moj_jk1.2+tomcat5.5.9


Apache+Mod_JK的配置
1. mod_jk.conf

LoadModule jk_module modules/mod_jk.so

JkWorkersFile conf/workers.properties

JkLogFile logs/mod_jk.log

JkMount /8thManage* loadbalancer

JkMount /jkmanager/* jkstatus

2. workers.properties

worker.list=loadbalancer,jkstatus

# Define the first node...

worker.server1.port=8050

worker.server1.host=192.168.1.186

worker.server1.type=ajp13

worker.server1.lbfactor=1

# Define the second node...

worker.server2.port=8050

worker.server2.host=192.168.1.182

worker.server2.type=ajp13

worker.server2.lbfactor=1

# Now we define the load-balancing behaviour

worker.loadbalancer.type=lb

worker.loadbalancer.balance_workers=server1,server2

worker.loadbalancer.sticky_session=true

##worker.loadbalancer.sticky_session_force=true

worker.jkstatus.type=status

Tomcat的配置:

1. 在Server.xml的Host里面加入:

<Engine name="Application" defaultHost="localhost" jvmRoute="server1">
<Host ......>

<Cluster className="org.apache.catalina.cluster.tcp.SimpleTcpCluster"

              doClusterLog="true" clusterLogName="clusterlog"

              manager.className="org.apache.catalina.cluster.session.DeltaManager"

              manager.expireSessionsOnShutdown="false"

              manager.notifyListenersOnReplication="true"

              manager.notifySessionListenersOnReplication="true"

              manager.sendAllSessions="false" manager.sendAllSessionsSize="500"

              manager.sendAllSessionsWaitTime="20">

             <Membership className="org.apache.catalina.cluster.mcast.McastService"

                     mcastAddr="230.0.0.4" mcastBindAddress="192.168.1.182"

                     mcastClusterDomain="LB_TC" mcastPort="10001" mcastFrequency="1000"

                     mcastDropTime="30000"/>

              <Receiver className="org.apache.catalina.cluster.tcp.ReplicationListener"

                     tcpListenAddress="192.168.1.182" tcpListenPort="10008" tcpSelectorTimeout="100"

                     tcpThreadCount="8"/>

              <Sender className="org.apache.catalina.cluster.tcp.ReplicationTransmitter"

                     replicationMode="fastasyncqueue" recoverTimeout="5000" recoverCounter="6"

                     doTransmitterProcessingStats="true" doProcessingStats="true"

                     doWaitAckStats="true" queueTimeWait="true" queueDoStats="true"

                     queueCheckLock="true" ackTimeout="15000" waitForAck="true"

                     keepAliveTimeout="80000" keepAliveMaxRequestCount="-1"/>

              <Valve className="org.apache.catalina.cluster.tcp.ReplicationValve"

                     filter=".*\.gif;.*\.js;.*\.css;.*\.png;.*\.jpeg;.*\.jpg;.*\.htm;.*\.html;.*\.txt;"

                     primaryIndicator="true"/>

             

              <ClusterListener className="org.apache.catalina.cluster.session.ClusterSessionListener"/>

              <ClusterListener className="org.apache.catalina.cluster.session.JvmRouteSessionIDBinderListener"/>

      </Cluster>

......
</Host>

其中
tcpListenAddress 是本机的IP地址
tcpListenPort 当前tomcat的监听端口,如果一台机器上有多个tomcat,则这端口不能重复

mcastAddr 组播IP
mcastBindAddress 组播绑定的IP,一般是本机IP

2.在web.xml的Context里面加入:

<Context ..... distributable="true">

......

<Valve className="org.apache.catalina.cluster.session.JvmRouteBinderValve" enabled="true" />
(如果是5.5.9以上版本,需要在server.xml的Cluster里面加上这句)

</Context>

Ipaddr注:
如果Tomcat Cluster下的应用程序,需要共享目录,Windows下面,可以使用UNC的目录格式(\\machinename\shareDir), Unix下可以使用NFS. Windows下的Tomcat服务,建议Run as Domain User,而不是Local System.

Net | 评论(0) | 引用(0) | 阅读(9166)