Question

I have configured the HttpServer2.2 to achieve the load balancing and the Clusteringfor my java application.

But the Load Balancing works fine and Clustering(session replication) not works .

My worker.properties in HttpServer will be ,

workers.java_home=C:/Program Files/Java/jdk1.6.0_25

#worker.list=worker1,worker2
worker.list=balancer

worker.worker1.port=8009
worker.worker1.host=localhost
worker.worker1.type=ajp13
worker.worker1.lbfactor=1

worker.worker2.port=8019
worker.worker2.host=192.168.100.84
worker.worker2.type=ajp13
worker.worker2.lbfactor=1

worker.balancer.type=lb
worker.balancer.balance_workers=worker1,worker2
worker.balancer.method=B
# Specifies whether requests with SESSION ID's 
# should be routed back to the same #Tomcat worker.
worker.balancer.sticky_session =True

and the httpd.conf will be,

<IfModule jk_module>

JkWorkersFile conf/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel info

JkMount /CustomerChat_V1.02.00 balancer
JkMount /CustomerChat_V1.02.00/* balance

</IfModule>

In my server.xml for Tomcat one,

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

            port="45564"
            frequency="500"
            dropTime="3000" />

        <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
              address="auto"
              port="4200"
              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=".*\.gif;.*\.js;.*\.jpg;.*\.htm;.*\.html;.*\.txt;" />

     <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
           tempDir="D:/cluster/temp/war-temp/"
           deployDir="D:/cluster/temp/war-deploy/"
           watchDir="D:/cluster/temp/war-listen/"
           watchEnabled="false" />

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

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

In my server.xml for Tomcat two,

       <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
                  address="192.168.0.1"
                  port="4100"
                  autoBind="100"
                  selectorTimeout="5000"
                  maxThreads="6" />

But Still having the problem.

When I shutdown the Tomcat one ,the new request will be automatically goes to the tomcat two. But the Tomcat two doesn't know about the current user state and his stored session object of the application.

hope our stack members will help me with this.

Good answers are definitely appreciated.

Was it helpful?

Solution 2

Some comments/suggestions

  • The configuration you have mentioned is purely of load-balancing. I assume you are using Tomcat behind the HttpServer (with AJP connector in Tomcat).
  • HttpServer will only forward the request to Tomcat server. It itself does not maintain the session of the user.
  • Session are maintained in Tomcat and and hence you should configure Tomcat for session clustering.
  • For Tomcat Clustering, refer to the tomcat version specific documentation. Here is link for Tomcat 6.0 session clustering.
  • Once Tomcat servers are clustered appropriately, the session would be replicated and each server would recognize the session of the users of other Server.

EDIT:

In your configuration you are mentioning

worker.balancer.sticky_session =True

this will make the HttpServer to send all the request to a tomcat where the session was created for first time (the session is stuck to that server hence the name sticky session). This defeats your purpose of session clustering. Please set this to false.

OTHER TIPS

As a good alternative Redis based Tomcat Session clustering can be used. It requires much less efforts to configure.

First, add session manager your context.xml file:

<Manager className="org.redisson.tomcat.RedissonSessionManager" 
         configPath="${catalina.base}/redisson.yaml" 
         readMode="MEMORY" updateMode="DEFAULT"/>

Second, create redisson.yaml config file:

singleServerConfig:
    address: "redis://my-redis:6379"

Third, сopy two jars from Redisson project into TOMCAT_BASE/lib directory:

redisson-all-3.16.1.jar

for Tomcat 7.x - redisson-tomcat-7-3.16.1.jar
for Tomcat 8.x - redisson-tomcat-8-3.16.1.jar
for Tomcat 9.x - redisson-tomcat-9-3.16.1.jar
for Tomcat 10.x - redisson-tomcat-10-3.16.1.jar

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top