apache tomcat loadbalancing clustering on ubuntu
- by user740010
i am facing a problem in clustering the tomcat with apache as a loadbalancer using mod_jk on ubuntu.
i have install apache2 on my ubuntu 11.04 and i have downloaded tomcat7 created two copies
and kept them at two different location.
1st one is at /home/net4u/vishal/test/tomcatA
2nd one is at /home/net4u/vishal/test1/tomcatB
i have made following changes to server.xml file in /conf folder
1. <Server port="8205" shutdown="SHUTDOWN">
2. <Connector port="8280" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
3.<Connector port="8209" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcatB">
4. <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
similarly i have modified other tomcat i.e tomcatA server.xml
content of the server.xml is as follow:
--
<!--The connectors can use a shared executor, you can define one or more named thread pools-->
<!--
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="150" minSpareThreads="4"/>
-->
<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Documentation at :
Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
Java AJP Connector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL HTTP/1.1 Connector on port 8080
-->
<Connector port="8280" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<!-- A "Connector" using the shared thread pool-->
<!--
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
-->
<!-- Define a SSL HTTP/1.1 Connector on port 8443
This connector uses the JSSE configuration, when using APR, the
connector should be using the OpenSSL style configuration
described in the APR documentation -->
<!--
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
-->
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8109" protocol="AJP/1.3" redirectPort="8443" />
<!-- An Engine represents the entry point (within Catalina) that processes
every request. The Engine implementation for Tomcat stand alone
analyzes the HTTP headers included with the request, and passes them
on to the appropriate Host (virtual host).
Documentation at /docs/config/engine.html -->
<!-- You should set jvmRoute to support load-balancing via AJP ie :
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
-->
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcatB">
<!--For clustering, please take a look at documentation at:
/docs/cluster-howto.html (simple how to)
/docs/config/cluster.html (reference documentation) -->
<!-- uncomment for clustering-->
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
<!-- Use the LockOutRealm to prevent attempts to guess user passwords
via a brute-force attack -->
<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" resolveHosts="false"/>
</Host>
</Engine>
i have install libapache2-mod-jk
step 1. i have Created jk.load file in
/etc/apache2/mods-enabled/jk.load
content is as follows:
LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so
Create /etc/apache2/mods-enabled/jk.conf:
JkWorkersFile /etc/apache2/workers.properties
JkLogFile /var/log/apache2/jk.log
JkMount /ecommerce/* worker1
JkMount /images/* worker1
JkMount /content/* worker1
step 2. Created workers.properties file in
/etc/apache2/workers.properties
content is as follows:
workers.tomcat_home=/home/vishal/Desktop/test/tomcatA
workers.java_home=/usr/lib/jvm/default-java
ps=/
worker.list=tomcatA,tomcatB,loadbalancer
worker.tomcatA.port=8109
worker.tomcatA.host=localhost
worker.tomcatA.type=ajp13
worker.tomcatA.lbfactor=1
worker.tomcatB.port=8209
worker.tomcatB.host=localhost
worker.tomcatB.type=ajp13
worker.tomcatB.lbfactor=1
worker.loadbalancer.type=lb
worker.loadbalancer.balanced_workers=tomcatA,tomcatB
worker.loadbalancer.sticky_session=1
i tried the same thing on the windows machine it is working.