Thursday 2 May 2013

Step by step install and configure Apache+Tomcat+mod_jk+load Balancing+Clustering

  • Apache 2.2.x
  • Tomcat 6.0.X OR Above
  • Jdk1.5 or above
  • Mod_jk.1.2.26.so
Installing apache :
# yum install httpd*
Then extract jdk on /usr/local directory
#cd /usr/local
#./jdk-6u23-linux-i586.bin
Than make it three copy of jdk
[root@localhost local]# cp -r jdk1.6.0_23 jdk1.6.0_23-1
[root@localhost local]# cp -r jdk1.6.0_23 jdk1.6.0_23-2
[root@localhost local]# cp -r jdk1.6.0_23 jdk1.6.0_23-3
Also extrat the tomcat file.
[root@localhost local]#tar –xvzf apache-tomcat-6.0.18.tar.gz
[root@localhost local]# mv apache-tomcat-6.0.18 tomcat-1
[root@localhost local]# cp tomcat-1 tomcat-2
cp: omitting directory `tomcat-1′
[root@localhost local]# cp -r tomcat-1 tomcat-2
[root@localhost local]# cp -r tomcat-1 tomcat-3
Map jdk with tomcat
[root@localhost local]#cd tomcat-1/bin
Open catalina.sh file and make it JAVA_HOME
[root@localhost bin]#vi catalina.sh
# OS specific support. $var _must_ be set to either true or false. (below this line )
JAVA_HOME=/usr/local/jdk1.6.0_23-1
export JAVA_HOME
CATALINA_OPTS=”-server -Xms128m -Xmx128m”
cygwin=false
os400=false
darwin=false
case “`uname`” in
[root@localhost bin]# vi ../../tomcat-2/bin/catalina.sh
JAVA_HOME=/usr/local/jdk1.6.0_23-2
export JAVA_HOME
CATALINA_OPTS=”-server -Xms128m -Xmx128m”
[root@localhost bin]# vi ../../tomcat-3/bin/catalina.sh
JAVA_HOME=/usr/local/jdk1.6.0_23-3
export JAVA_HOME
CATALINA_OPTS=”-server -Xms128m -Xmx128m”
We have required to change three port for running multiple tomcat on a single machine.
[root@localhost bin]# vi ../conf/server.xml
<?xml version=’1.0′ encoding=’utf-8′?>
<Server port=”8005” shutdown=”SHUTDOWN”>
<!–APR library loader. Documentation at /docs/apr.html –>
<Listener className=”org.apache.catalina.core.AprLifecycleListener” SSLEngine=”on” />
<!–Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html –>
<Listener className=”org.apache.catalina.core.JasperListener” />
<!– Prevent memory leaks due to use of particular java/javax APIs–>
<Listener className=”org.apache.catalina.core.JreMemoryLeakPreventionListener” />
<!– JMX Support for the Tomcat server. Documentation at /docs/non-existent.html –>
<Listener className=”org.apache.catalina.mbeans.ServerLifecycleListener” />
<Listener className=”org.apache.catalina.mbeans.GlobalResourcesLifecycleListener” />
<GlobalNamingResources>
<Resource name=”UserDatabase” auth=”Container”
type=”org.apache.catalina.UserDatabase”
description=”User database that can be updated and saved”
factory=”org.apache.catalina.users.MemoryUserDatabaseFactory”
pathname=”conf/tomcat-users.xml” />
</GlobalNamingResources>
<Service name=”Catalina”>
<Connector port=”8080” protocol=”HTTP/1.1″
connectionTimeout=”20000″
redirectPort=”8443″ />
<Connector port=”8009” protocol=”AJP/1.3″ redirectPort=”8443″ />
<Engine name=”Catalina” defaultHost=”localhost” jvmRoute=”worker1″>
<!– <Cluster className=”org.apache.catalina.ha.tcp.SimpleTcpCluster”/> –> # (FOR Session managenet)
<Realm className=”org.apache.catalina.realm.UserDatabaseRealm”
resourceName=”UserDatabase”/>
<Host name=”localhost” appBase=”webapps”
unpackWARs=”true” autoDeploy=”true”
xmlValidation=”false” xmlNamespaceAware=”false”>
</Host>
</Engine>
</Service>
</Server>
Do the same on tomcat-2 and tomcat-3
I have given to tomcat-2 : <Server port=”8006” shutdown=”SHUTDOWN”>
<Connector port=”8081” protocol=”HTTP/1.1″
<Connector port=”8010” protocol=”AJP/1.3″ redirectPort=”8443″ />
On tomcat-3 : <Server port=”8007” shutdown=”SHUTDOWN”>
<Connector port=”8082” protocol=”HTTP/1.1″
<Connector port=”8011” protocol=”AJP/1.3″ redirectPort=”8443″ />
Intigrate apache +tomcat with mod_jk+load Balanceing
Download supportable file for apache server (It’s depend on http version).
  • Downlaod and rename this mod_jk.1.2.24.so to mod_jk.so then past in /etc/httpd/modules/
  • Then open httpd.conf file and make this entry: LoadModule jk_module modules/mod_jk.so , be sure mod_jk.so working or not with restart httpd service.
[root@localhost apache_tomcat]# ls
catalina.sh httpd.conf mod_jk.so server.xml web.xml worker.properties
[root@localhost apache_tomcat]# cp mod_jk.so /etc/httpd/modules/
[root@localhost apache_tomcat]# service httpd restart
Stopping httpd: FAILED]
Starting httpd: OK ]
Note: ( if httpd not starting means your mod_jk.so is not correct file , download sutable file then check again.)
  • Create in /ets/httpd/conf/worker.properties file and make this entry
For Single
worker.list = worker1
worker.worker1.type = ajp13
worker.worker1.host =192.168.1.1 or 127.0.0.1 (depend on host ip)
worker.worker1.port = 8009
worker.worker1.connection_pool_size = 5
worker.worker1.connection_pool_timeout = 300
Make entry in httpd.conf for windows:
JkWorkersFile “H:\cluster\Apache2.2\conf\worker.properties”
JkLogFile “H:\cluster\Apache2.2\logs\mod_jk.log”
JkRequestLogFormat “%w %V %T”
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkLogLevel info
JkLogStampFormat “[%a %b %d %H:%M:%S %Y]“
JkMount /examples worker1 (worker.list name of worker.properties file)
JkMount /examples/* worker1
For Linux :
JkWorkersFile “/etc/httpd/conf/worker.properties”
JkLogFile “/etc/httpd/conf/mod_jk.log”
JkRequestLogFormat “%w %V %T”
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkLogLevel info
JkLogStampFormat “[%a %b %d %H:%M:%S %Y]“
JkMount /examples worker1
JkMount /examples/* worker1
Working on Load Balancing:
For Load Balancing
worker.list=worker1,worker2,worker3,balance
# Define Node1
worker.worker1.port=8009
worker.worker1.host=192.168.0.112
worker.worker1.type=ajp13
worker.worker1.lbfactor=1
# Define Node2
worker.worker2.port=8010
worker.worker2.host=192.168.0.112
worker.worker2.type=ajp13
worker.worker2.lbfactor=1
# Define Node3
worker.worker3.port=80011
worker.worker3.host=192.168.0.112
worker.worker3.type=ajp13
worker.worker3.lbfactor=1
worker.balance.type=lb
worker.balance.balance_workers=worker1,worker2,worker3
worker.loadbalancer.sticky_session=1
Worker.properties file
Make a file with name of workers.properties in conf folder. This file tells properties of all tomcat instances. We have to specify all tomcat properties here. Apache will forword request to tomcat through this file
Vertical tomcat clustering this file like
workers.tomcat_home=/tomcatA
workers.java_home=$JAVA_HOME
ps=/
worker.list=tomcatA,tomcatB,tomcatC,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.tomcatC.port=8309
worker.tomcatC.host=localhost
worker.tomcatC.type=ajp13
worker.tomcatC.lbfactor=1
worker.loadbalancer.type=lb
worker.loadbalancer.balanced_workers=tomcatA,tomcatB,tomcatC
worker.loadbalancer.sticky_session=1
for horizontal tomcat clustering
workers.tomcat_home=/tomcatA
workers.java_home=$JAVA_HOME
ps=/
worker.list=tomcatA,tomcatB,tomcatC,loadbalancer

worker.tomcatA.port=8009
worker.tomcatA.host=192.168.1.1
worker.tomcatA.type=ajp13
worker.tomcatA.lbfactor=1

worker.tomcatB.port=8009
worker.tomcatB.host=192.168.1.2
worker.tomcatB.type=ajp13
worker.tomcatB.lbfactor=1
worker.tomcatC.port=8009
worker.tomcatC.host=192.168.1.3
worker.tomcatC.type=ajp13
worker.tomcatC.lbfactor=1
worker.loadbalancer.type=lb
worker.loadbalancer.balanced_workers=tomcatA,tomcatB,tomcatC
worker.loadbalancer.sticky_session=1
then make the entry in httpd.conf file
JkWorkersFile “/etc/httpd/conf/worker.properties”
JkLogFile “/etc/httpd/conf/mod_jk.log”
JkRequestLogFormat “%w %V %T”
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkLogLevel info
JkLogStampFormat “[%a %b %d %H:%M:%S %Y]“
JkMount /examples balance
JkMount /examples/* balance
Open server.xml of tomcat-1 Server :
<Server port=”8005” shutdown=”SHUTDOWN”>
<Connector port=”81″ protocol=”HTTP/1.1″
<Connector port=”8009″ protocol=”AJP/1.3″ redirectPort=”8443″ />
Change <!–<Engine name=”Catalina” defaultHost=”localhost” jvmRoute=”jvm1″> –>
To < Engine name=”Catalina” defaultHost=”localhost” jvmRoute=”tomcat-1″>
Change <Engine name=”Catalina” defaultHost=”localhost”>
To <!–<Engine name=”Catalina” defaultHost=”localhost”> –>
Same on tomcat-2 :
<Server port=”8006” shutdown=”SHUTDOWN”>
<Connector port=”82″ protocol=”HTTP/1.1″
<Connector port=”8010″ protocol=”AJP/1.3″ redirectPort=”8443″ />
Change <!–<Engine name=”Catalina” defaultHost=”localhost” jvmRoute=”jvm1″> –>
To < Engine name=”Catalina” defaultHost=”localhost” jvmRoute=”tomcat-2″>
Change <Engine name=”Catalina” defaultHost=”localhost”>
To <!–<Engine name=”Catalina” defaultHost=”localhost”> –>
Same on tomcat-3 :
<Server port=”8007” shutdown=”SHUTDOWN”>
<Connector port=”83″ protocol=”HTTP/1.1″
<Connector port=”8011″ protocol=”AJP/1.3″ redirectPort=”8443″ />
Change <!–<Engine name=”Catalina” defaultHost=”localhost” jvmRoute=”jvm1″> –>
To < Engine name=”Catalina” defaultHost=”localhost” jvmRoute=”tomcat-3″>
Change <Engine name=”Catalina” defaultHost=”localhost”>
To <!–<Engine name=”Catalina” defaultHost=”localhost”> –>
ERROR LIST :
Catalina.out
java.lang.NoClassDefFoundError: org/apache/tomcat/util/log/SystemLogHandler
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2357)
at java.lang.Class.getConstructor0(Class.java:2671)
at java.lang.Class.newInstance0(Class.java:321)
at java.lang.Class.newInstance(Class.java:303)
at org.apache.catalina.startup.Bootstrap.init(Bootstrap.java:218)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:390)
java.lang.NoClassDefFoundError: org/apache/tomcat/util/log/SystemLogHandler
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2357)
at java.lang.Class.getConstructor0(Class.java:2671)
at java.lang.Class.newInstance0(Class.java:321)
at java.lang.Class.newInstance(Class.java:303)
at org.apache.catalina.startup.Bootstrap.init(Bootstrap.java:218)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:390)
java.lang.NoClassDefFoundError: org/apache/tomcat/util/log/SystemLogHandler
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2357)
at java.lang.Class.getConstructor0(Class.java:2671)
at java.lang.Class.newInstance0(Class.java:321)
at java.lang.Class.newInstance(Class.java:303)
at org.apache.catalina.startup.Bootstrap.init(Bootstrap.java:218)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:390)
/home/rakesh/jdk1.6.0_30-1

1 comment:

Install XRDP in Centos 7

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm yum update yum groupinstall "GNOME Desktop" ...