Thursday, December 22, 2016

Apache Tomcat Clustering with Apache Http Server

Summary 

     1) Create OS User tomcat
     2) Install the JDK  & Export The JAVA_HOME in .bash_profile
     3) Install Tomcat Binaries in Two Directories instance1 & instance2
     4) Set JAVA_OPTIONS in setenv.sh file
     5) Install Apache Http Server
     6) Compile & Build Tomcat Connector for Generating mod_jk.so
     7) Load the mod_jk.so file in httpd.conf file located at /etc/httpd/conf
     8) Create workers.properties file with below content in Apache WebServer Machine
     9)  Load the worker.properties file & Other Entries in httpd.conf
   10)  Enter application context specific  entries in httpd.conf
   11)  Start up instance1,instance2 and apache WebServer.
   12)  Test the set up using WebServer URL


Steps
=====

1) Create OS User tomcat

     Use below command for creating user & setting password

     useradd -u 54666  tomcat
     passwd tomcat





2) Install the JDK  & Export The JAVA_HOME in .bash_profile

Download JDK using below link

http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Use below command for installing jdk

tar -zxvf jdk-8u112-linux-x64.tar.gz



Set JAVA_HOME  by adding below lines in .bash_profile

vi ~/.bash_profile

JAVA_HOME=/home/tomcat/java/jdk1.8.0_112
export JAVA_HOME
export PATH=$JAVA_HOME/bin:$PATH



3) Install Tomcat Binaries & Export The CATALINA_HOME in .bash_profile

Download tomcat 8 using below link

https://tomcat.apache.org/download-80.cgi

Create two directories for two instances say instance1 & instance2

mkdir mkdir instance1 instance2



Install tomcat by executing below command in directories instance1 and instance2

 tar -zxvf apache-tomcat-8.5.9.tar.gz





4) Set JAVA_OPTIONS in setenv.sh file for instance1 & instance2

Create file setenv.sh

cd /home/tomcat/instance1/apache-tomcat-8.5.9/bin
touch setenv.sh

 cd /home/tomcat/instance2/apache-tomcat-8.5.9/bin
touch setenv.sh



Add below content to setenv.sh 

JAVA_OPTS="-Xms256m -Xmx512m "

Note: Java Options PermSize &  MaxPermSize are Deprecated in JDK8

5) Install Apache Http Server

Install Apache WebServer Using below link

https://blogbyjagan.blogspot.in/2015/10/wls-reading.html

OR Use below command for quick installation

yum install httpd

6) Compile & Build Tomcat Connector for Generating mod_jk.so  in Apache webServer Machine.

Download Tomcat Connector using below link

https://tomcat.apache.org/connectors-doc/

Using WinSCP copy the Connector file to the remote machine & untar it



navigate to directory /connector/tomcat-connectors-1.2.42-src/native & execute below command

cd /connector/tomcat-connectors-1.2.42-src/native

./configure --with-apxs=/usr/bin/apxs

make

make install

Now navigate to the directory /connector/tomcat-connectors-1.2.42-src/native/apache-2.0 & copy the mod_jk.so to /etc/httpd/modules

cd /connector/tomcat-connectors-1.2.42-src/native/apache-2.0
cp mod_jk.so /etc/httpd/modules

7) Load the mod_jk.so file in httpd.conf file located at /etc/httpd/conf

LoadModule jk_module        modules/mod_jk.so

8) Create workers.properties file with below content in Apache WebServer Machine

cd /etc/httpd/conf
touch workers.properties

Add below content in workers.properties file and Save & Exit

worker.list=instance1,instance2

worker.instance1.type=ajp13
worker.instance1.port=8009
worker.instance1.host=192.168.52.129

worker.instance2.type=ajp13
worker.instance2.port=8010
worker.instance2.host=192.168.52.129

worker.balancer.type=lb
worker.balancer.balance_workers=instance1,instance2

worker.stat.type=status
worker.list=balancer,stat

worker.ajp13.lbfactor=50
worker.ajp13.cachesize=10
worker.ajp13.cache_timeout=600
worker.ajp13.socket_keepalive=1
worker.ajp13.socket_timeout=300


9) Load the worker.properties file & Other Entries in httpd.conf 

JkWorkersFile /etc/httpd/conf/workers.properties
JkLogFile /etc/httpd/logs/mod_jk.log
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat "%w %V %T"

10)  Enter below application specific  entries in httpd.conf 

JkMount /examples balancer
JkMount /examples/* balancer

JkMount  /status  stat


11) Now login to the tomcat machine & change instance1 and instance2 ports in server.xml file

cd /home/tomcat/instance1/apache-tomcat-8.5.9/conf/
vi server.xml

instance1: tomcat server port 8080, AJP port 8009, shutdown port 8005

cd /home/tomcat/instance2/apache-tomcat-8.5.9/conf/
vi server.xml
instance2: tomcat server port 8081, AJP port 8010, shutdown port 8006

11) Start up instance1,instance2 and apache WebServer.

On Tomcat Machine
==================
[tomcat@test1 bin]$ /home/tomcat/instance1/apache-tomcat-8.5.9/bin/startup.sh
Using CATALINA_BASE:   /home/tomcat/instance1/apache-tomcat-8.5.9
Using CATALINA_HOME:   /home/tomcat/instance1/apache-tomcat-8.5.9
Using CATALINA_TMPDIR: /home/tomcat/instance1/apache-tomcat-8.5.9/temp
Using JRE_HOME:        /home/tomcat/java/jdk1.8.0_112
Using CLASSPATH:       /home/tomcat/instance1/apache-tomcat-8.5.9/bin/bootstrap.jar:/home/tomcat/instance1/apache-tomcat-8.5.9/bin/tomcat-juli.jar
Tomcat started.
[tomcat@test1 bin]$


[tomcat@test1 bin]$ /home/tomcat/instance2/apache-tomcat-8.5.9/bin/startup.sh
Using CATALINA_BASE:   /home/tomcat/instance2/apache-tomcat-8.5.9
Using CATALINA_HOME:   /home/tomcat/instance2/apache-tomcat-8.5.9
Using CATALINA_TMPDIR: /home/tomcat/instance2/apache-tomcat-8.5.9/temp
Using JRE_HOME:        /home/tomcat/java/jdk1.8.0_112
Using CLASSPATH:       /home/tomcat/instance2/apache-tomcat-8.5.9/bin/bootstrap.jar:/home/tomcat/instance2/apache-tomcat-8.5.9/bin/tomcat-juli.jar
Tomcat started.
[tomcat@test1 bin]$


On WebServer Machine
==================
[root@test2 logs]# service httpd start
Redirecting to /bin/systemctl start  httpd.service
[root@test2 logs]#


12) Test the set up using below WebServer URL

http://192.168.52.161/examples/



No comments:

Post a Comment