0
votes

I want to do clustering and load balancing for my applications running in tomcat. I am using ubuntu, apache version 2.4.18 and two tomcat 8.5 instances. I tried with mod_jk for this but it is not working for me.

following is my configuration in apache and tomcat

in jk.conf

<IfModule jk_module>

 JkWorkersFile /etc/apache2/conf/workers.properties

 JkLogFile /etc/apache2/log/mod_jk.log

 JkLogLevel info

 JkShmFile /etc/apache2/log/jk-runtime-status

 JkWatchdogInterval 60

 JkMount /clusterjsp/* loadbalancer
 JkMount /jk-status status

 <Location /jk-status>
    JkMount jk-status
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1
 </Location>

 <Location /jk-manager>
    JkMount jk-manager
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1
 </Location>
</IfModule>

in workers.properies

worker.list=loadbalancer,status
worker.server1.port=8009
worker.server1.host=127.0.0.1
worker.server1.type=ajp13
worker.server1.connection_pool_size=200
worker.server1.connection_pool_timeout=600
worker.server1.socket_keepalive=1

worker.server2.port=7009
worker.server2.host=127.0.0.1
worker.server2.type=ajp13
worker.server2.connection_pool_size=200
worker.server2.connection_pool_timeout=600
worker.server2.socket_keepalive=1

worker.server1.lbfactor=1
worker.server2.lbfactor=1

worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=server1,server2

worker.status.type=status

and in both tomcat server.xml

<Engine name="Catalina" defaultHost="localhost" jvmRoute="server1"> <!-- server2 for another instance -->

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

      <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
        <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
      </Sender>

      <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver" address="auto" port="4000" autoBind="100" selectorTimeout="5000" maxThreads="50"/>
      <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
      <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptor"/>
    </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.ClusterSessionListener"/>
</Cluster>

<Realm className="org.apache.catalina.realm.LockOutRealm">
    <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
</Realm>

<Host name="localhost"  appBase="webapps" unpackWARs="true" autoDeploy="true">
 <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t &quot;%r&quot; %s %b" />
</Host>

</Engine>

i did not make any changes in apache2.conf or i don't have httpd.conf in apache home directory. i have deployed same application i both tomcat servers and it is working when using http://localhost:8080/clusterjsp and http://localhost:7070/clusterjsp but When i type http://localhost/clusterjsp in my browser it gives me 404 error but http://localhost shows apache default page.

Can you please let me know what i am missing or what is wrong in my configuration.

1

1 Answers

0
votes

Probably it is due to the fact that you are redirecting all incoming requests matching /clusterjsp/* to load balancer, but you don't take care of the requests which don't have anything after the context path. You could try just adding this line to your jk.conf:

JkMount /clusterjsp loadbalancer

There are other aproaches too, but probably this is the easyest one to test.