Thursday, 24 February 2011

How to Configure Two Tomcat instance in Linux

Download Java SE Development Kit. http://java.sun.com/javase/downloads/index.jsp.

# mkdir -p /opt/test
# cd /opt/test
# chmod 755 jdk-6u10-linux-x64.bin
# sh /opt/test/jdk-6u10-linux-x64.bin

# export JAVA_HOME=/opt/test/jdk1.6.0_10/bin
# export PATH=$JAVA_HOME/bin:$PATH

now check java version-
# java -version

Install Tomcat6
Download tomcat6 from the http://tomcat.apache.org/download-60.cgi
extract in /tmp folder.

Download httpd-2.64.tar.gz
now extract in /opt/test directory

Apache compile process-: Compile process we need GCC and lib file must be require
# yum install gcc*
# yum install lib
# cd /test/httpd-2.64
#./configure -prefix=/opt/httpd-2.64
# make
# make install
# cd /opt/test/httpd-2.64
# cd /bin
# apachectl start

Set permanent variable -: In Linux we can set up path

#vim /root/.bashrc
JAVA_HOME=/opt/test/jdk-1.6.0/
export JAVA_HOME
PATH=$JAVA_HOME/bin/;$PATH


We can set new installation JDK java path
#alternative --config Java

Install Tomcat6 and configuration-:

#cp apache-tomcat-6.0.20/opt/test/tomcat-1

Set CATALINA_HOME environment
CATALINA_HOME=/opt/test/tomcat-1

#cd /opt/test/tomcat-1/bin
# sh startup.sh

Configure tomcat2 instance

#cp apache-tomcat-6.0.20/opt/test/tomcat-2

Set CATALINA_HOME environment
CATALINA_HOME=/opt/test/tomcat-2

#cd /opt/test/tomcat-2/bin


Now check first jvm tomcat instance is working or not
http://localhost:8080

Configuring Tomcat Network Ports-:
Since this is the first tomcat that's being created here,the default port numbers can be unchanged in tomcat1
#vim /opt/test/tomcat1/conf/server.xml


connectionTimeout="20000"
redirectPort="8443" />



Second Tomcat we need to be changed
# vim /opt/test/tomcat2/conf/server.xml




connectionTimeout="20000"
redirectPort="8444" />



Install tomcat-connector-1.2.30-src.tar.gz
Unzip directory
tomcat-connector-1.2.30-src

Compile tomcat-connector
# cd /tomcat-connector-1.2.30-src
# cd native
# ./configure -with-apxs=/opt/test/httpd-2.64/bin/apxs
# make
# make install

Now we can find mod_jk.so file will be put on /opt/test/httpd-2.64/modules/

# chmod 755 /opt/test/httpd-2.64/modules/mod_jk.so

Now create workers.properties
# cd /opt/test/httpd-2.64/conf/
# touch workers.properties
Add the following lines

Define list of workers that will be used
# for mapping requests
worker.list=loadbalancer,status

# Define Node1
# modify the host as your host IP or DNS name.
worker.node1.port=8005
worker.node1.type=ajp13
worker.node1.lbfactor=1
worker.node1.cachesize=10

# Define Node2
# modify the host as your host IP or DNS name.
worker.node2.port=8006

worker.node2.type=ajp13
worker.node2.lbfactor=1
worker.node2.cachesize=10

# Load-balancing behavior
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=node1,node2
worker.loadbalancer.sticky_session=1
#worker.list=loadbalancer

# Status worker for managing load balancer
worker.status.type=status

Edit httpd.conf file-:
# /opt/test/httpd-2.64/conf/
# vim httpd.conf
LoadModule jk_module modules/mod_jk.so
JkWorkersFile conf/workers.properties
JkMount /* myworker


Start the httpd server
#/bin/apachctl start

start both Tomcat server
#/bin/startup.sh

2 comments:

  1. Thank you for a post.
    Just a little correction: instead of myworker, there should be written loadbalancer.

    Thanks

    ReplyDelete
  2. It's actually a nice and helpful piece of info. I'm happy that you simply shared this helpful information with us.

    Please stay us informed like this. Thank you for sharing.



    Here is my web blog ... bmi calculator for women

    ReplyDelete