Wednesday 18 January 2017

Multiple Tomcat Instances connected via apache using mod-jk connector configuration::

Multiple Tomcat Instances connected via apache using mod-jk connector configuration::
================================================================
# yum install gcc

Creating the users and group::
# groupadd apache
# useradd -g apache -m -d /home/linuxgeek1 linuxgeek1

Install apache as mentioned in previous thread.

Download latest java from the url

cd /opt/ linuxgeek1/
# wget  http://download.oracle.com/otn-pub/java/jdk/8u121-b13/e9e7ea248e2c4826b92b3f075a80e441/jdk-8u121-linux-x64.tar.gz
untar it

Goto the home directory of the user  ' linuxgeek1' and edit .bash_profile as below  to set the PATH

PATH=$PATH:$HOME/.local/bin:$HOME/bin:$HOME/httpd/bin:/opt/linuxgeek1/jdk1.8.0_121/bin
#export JAVA_HOME=/opt/linuxgeek1/jdk1.8.0_121
export PATH

Check the installed java version
# java -version

java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)




Download latest Apache Tomcat into the home directory and untar it
# wget http://www-us.apache.org/dist/tomcat/tomcat-8/v8.5.11/bin/apache-tomcat-8.5.11.tar.gz
# tar -zxvf  apache-tomcat-8.5.11.tar.gz
# cd  apache-tomcat-8.5.11

Download latest mod-jk connector into the home directory and untar it.
# wget  http://www-us.apache.org/dist/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.42-src.tar.gz
#  tar -zxvf tomcat-connectors-1.2.42-src.tar.gz
#  cd  tomcat-connectors-1.2.42-src/native
#  ./configure  --with-apache=/home/linuxgeek1/httpd  –-with-apxs=/home/linuxgeek1/httpd/bin/apxs
or 
#  ./configure  --with-apxs=/home/iaas1idm/httpd/bin/apxs

Now goto apache home directory and under conf dir, create two files workers.properties and  mod_jk.conf with the contents as follows:

# vi  workers.properties
===========================
workers.tomcat_home=/home/linuxgeek1/apache-tomcat
workers.java_home=/opt/linuxgeek1/jdk1.8.0_121
worker.list=worker1
worker.worker1.type=ajp13
worker.worker1.port=8029
worker.worker1.host=localhost
worker.worker1.lbfactor=1
# Set properties
===========================

# vi mod_jk.conf
===========================
# Where to find workers.properties
JkWorkersFile /home/linuxgeek1/httpd/conf/workers.properties
# location of log file
JkLogFile /home/linuxgeek1/httpd/logs/mod_jk.log
# log level
JkLogLevel info
# Select the log format
#JkLogStampFormat “[%a %b %d %H:%M:%S %Y]”
# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format
#JkRequestLogFormat “%w %V %T”
#Send everything for context /test to worker ajp13
JkMount /* worker1
============================

Now edit the httpd.conf file and entries for virtual host, port and mod_jk module details

#vi httpd.conf

Listen 192.168.1.1:8010 
LoadModule jk_module modules/mod_jk.so  (add this line in the load module section)

At the bottom of the httpd.conf file add the virtual host entries as folows::


====================================
#mod_jk
Include conf/mod_jk.conf
#JkWorkersFile "conf/workers.properties"
#JkLogFile "/home/linuxgeek1/httpd/logs/mod_jk.log"
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"

<VirtualHost *:80>
#ServerAdmin admin@www.mydomain1.com
DocumentRoot "/home/linuxgeek1/apache-tomcat/webapps/ROOT"
#ServerName http://www.mydomain1.com
#ErrorLog logs/www.mydomain1.com_log
#CustomLog logs/www.mydomain1.com_log combined

#JkMount /  worker1
JkMount /* worker1

</VirtualHost>
====================================


Also edit the port details in tomcat configuration file "server.xml". We need to mention different port numbers for shutdown, tomcat thread and AJP for  different users. Below mentioned configuration is for the user linuxgeek1.
====================================
<Server port="8011" shutdown="SHUTDOWN">

  <Connector port="8082" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    <!-- A "Connector" using the shared thread pool-->
    <!--
    <Connector executor="tomcatThreadPool"
               port="8082" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8029" protocol="AJP/1.3" redirectPort="8443" />
===================================
Now restart apache  and tomcat and try accessing the url 192.168.1.1:8010 and 192.168.1.1:8082

Both the pages will display the apache tomcat default page.

Repeat the same steps above with different users and different ports for multiple instances

No comments:

Post a Comment