Installing and Configuring Multiple Tomcat Server Instances In Ubuntu Server.

Hello all, today I ‘m taking you through the steps to configure multiple server instances of Apache Tomcat server in a single machine. In this case I have taken Ubuntu server 12.04 version to be demonstrated. So first of all let’s look at the what are the steps for the server.

  1. Availability of JDK and JRE.
  2. Installing the tomcat server.
  3. Create multiple instances.

In here let’s check whether that your server has the JDK and JRE.

$ sudo java -version

In here let’s check whether that your server has the JDK and JRE.

$sudo java -version

java version “1.6.0_31”
OpenJDK Runtime Environment (IcedTea6 1.13.3) (6b31-1.13.3-1ubuntu1~0.12.04.2)
OpenJDK 64-Bit Server VM (build 23.25-b01, mixed mode)

If u r getting the response like this you have already installed the JDK and JRE otherwise you have to install JDK and JRE. following commands will help you to install the latest version of JDK and JRE.

 $ sudo apt-get update
 $ sudo apt-get install default-jre
 $ sudo apt-get install default-jdk

After installation is completed, u can check the JDK and JRE has been installed or not using java version command.

$ sudo java -version

Now, we have to set the JAVA_HOME variable path to the relevant directory, do the followings.

$ sudo nano ~/.bashrc

Then add the following line and reboot the system.

export JAVA_HOME=/usr/lib/jvm/default-java

After verified the JDK and JRE is installed correctly, let’s move to the next step. In here let’s install the apache tomcat with tomcat admin.

$ sudo apt-get install tomcat7 tomcat7-admin

Now you can test the tomcat is working using http://myserver.com:8080 ,

tomcat-1

Image – 01

Now let’s create multiple instances on Tomcat server called tomcat7-a, tomcat7-b, tomcat7-c. follow the commndes given below.

 $ cd /var/lib/
 $ sudo mkdir tomcat7-a
 $ sudo mkdir tomcat7-b
 $ sudo mkdir tomcat7-c

 $ cd /var/lib/tomcat7-a
 $ sudo mkdir conf temp webapps work logs
 $ cd /var/lib/tomcat7-b
 $ sudo mkdir conf temp webapps work logs
 $ cd /var/lib/tomcat7-c

 $ sudo mkdir conf temp webapps work logs
 $ cd ..

 $ sudo chown -R tomcat7:tomcat7 tomcat7-a tomcat7-b tomcat7-c

Now we have created the directories of new instances, in next step we need link main configurations files which are available in main tomcat7 server instance.

 $ sudo ln- s /var/lib/tomcat7/conf/catalina.properties /var/lib/tomcat7-a/conf
 $ sudo ln- s /var/lib/tomcat7/conf/catalina.properties /var/lib/tomcat7-b/conf
 $ sudo ln- s /var/lib/tomcat7/conf/catalina.properties /var/lib/tomcat7-c/conf
 $ sudo ln- s /var/lib/tomcat7/conf/web.xml /var/lib/tomcat7-a/conf
 $ sudo ln- s /var/lib/tomcat7/conf/ web.xml /var/lib/tomcat7-b/conf
 $ sudo ln- s /var/lib/tomcat7/conf/ web.xml /var/lib/tomcat7-c/conf
 $ sudo ln- s /var/lib/tomcat7/conf/policy.d/ /var/lib/tomcat7-a/conf
 $ sudo ln- s /var/lib/tomcat7/conf/policy.d/ /var/lib/tomcat7-b/conf
 $ sudo ln- s /var/lib/tomcat7/conf/policy.d/ /var/lib/tomcat7-c/conf

Now the necessary files have been copied. So in next step let’s configure the server port, shutdown port and the connector port on server.xml file.

$ sudo cp /var/lib/tomcat7/conf/server.xml /var/lib/tomcat7-a/conf/
 $ sudo cp /var/lib/tomcat7/conf/server.xml /var/lib/tomcat7-b/conf/
 $ sudo cp /var/lib/tomcat7/conf/server.xml /var/lib/tomcat7-c/conf/

Open the server.xml files separatly and chenge the above mentioned port numbers.

<Server port=”8005″ shutdown=”SHUTDOWN”>
.
.
.
<Connector port=”8080″ protocol=”HTTP/1.1″
                connectionTimeout=”20000″              
                URIEncoding=”UTF-8″
                redirectPort=”8443″ />
.
.
.

<Connector port=”8009″ protocol=”AJP/1.3″ redirectPort=”8443″ />
.
.

After setting up the port number on server.xml file , you have to change the configuration on the service file which is in “/etc/init.d/” . In here copy the main tomcat7 service file and make three copies and change the appropriate values.

$ cd /etc/init.d/
 $ sudo cp tomcat7 tomcat7-a
 $ sudo cp tomcat7 tomcat7-b
 $ sudo cp tomcat7 tomcat7-c

Then open those files and change the necessary configurations sample shown given below.

DESC=”Tomcat servlet engine”
CATALINA_BASE=/var/lib/$NAME
CATALINA_PID=”/var/run/$NAME.pid”

After configurations are completed save the files and start the tomcat instances.

 $ sudo service tomcat7-a start
 $ sudo service tomcat7-b start
 $ sudo service tomcat7-c start

If services are not started properly, please make sure the configuration file changes are correct. The set those main tomcat instance services to the startup services.

 $ sudo update -rc.d tomcat7-a defaults
 $ sudo update -rc.d tomcat7-b defaults
 $ sudo update -rc.d tomcat7-c defaults

Now try the instances using the appropriate URLs with port numbers. If you have set the port numbers like 8181, 8282, 8383, use the following URLs.

http://localhost:8181 ,http://localhost:8282, http://localhost:8383

Thank You.

Advertisements

10 thoughts on “Installing and Configuring Multiple Tomcat Server Instances In Ubuntu Server.

  1. Pingback: Tomcat Server Loab-Balancing Using Multiple Tomcat Server Instances in Ubuntu | disamTECHbench

  2. hi there .
    just i finish tomcat installation ubuntu 14.04 and no think show at http://xxxxxx.com:8080
    this is the file /etc/default/tomcat7
    # Run Tomcat as this user ID. Not setting this or leaving it blank will use the
    # default of tomcat7.
    TOMCAT7_USER=tomcat7

    # Run Tomcat as this group ID. Not setting this or leaving it blank will use
    # the default of tomcat7.
    TOMCAT7_GROUP=tomcat7

    # The home directory of the Java development kit (JDK). You need at least
    # JDK version 1.5. If JAVA_HOME is not set, some common directories for
    # OpenJDK, the Sun JDK, and various J2SE 1.5 versions are tried.
    #JAVA_HOME=/usr/lib/jvm/openjdk-6-jdk

    # You may pass JVM startup parameters to Java here. If unset, the default
    # options will be: -Djava.awt.headless=true -Xmx128m -XX:+UseConcMarkSweepGC
    #
    # Use “-XX:+UseConcMarkSweepGC” to enable the CMS garbage collector (improved
    # response time). If you use that option and you run Tomcat on a machine with
    # exactly one CPU chip that contains one or two cores, you should also add
    # the “-XX:+CMSIncrementalMode” option.
    JAVA_OPTS=”-Djava.awt.headless=true -Xmx128m -XX:+UseConcMarkSweepGC”

    # To enable remote debugging uncomment the following line.
    # You will then be able to use a java debugger on port 8000.
    #JAVA_OPTS=”${JAVA_OPTS} -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n”

    # Java compiler to use for translating JavaServer Pages (JSPs). You can use all
    # compilers that are accepted by Ant’s build.compiler property.
    #JSP_COMPILER=javac

    # Use the Java security manager? (yes/no, default: no)
    #TOMCAT7_SECURITY=no

    # Number of days to keep logfiles in /var/log/tomcat7. Default is 14 days.
    #LOGFILE_DAYS=14
    # Whether to compress logfiles older than today’s
    #LOGFILE_COMPRESS=1

    # Location of the JVM temporary directory
    # WARNING: This directory will be destroyed and recreated at every startup !
    #JVM_TMP=/tmp/tomcat7-temp

    # If you run Tomcat on port numbers that are all higher than 1023, then you
    # do not need authbind. It is used for binding Tomcat to lower port numbers.
    # NOTE: authbind works only with IPv4. Do not enable it when using IPv6.
    # (yes/no, default: no)
    #AUTHBIND=no

    is any think i want to change ?????
    thank you

  3. Creating config file /etc/logrotate.d/tomcat7 with new version
    * Starting Tomcat servlet engine tomcat7 [ OK ]
    Setting up tomcat7-admin (7.0.52-1ubuntu0.1) …
    Setting up authbind (2.1.1) …
    Processing triggers for ureadahead (0.100.0-16) …
    root@server:/home/user# sudo java -version
    java version “1.7.0_65”
    OpenJDK Runtime Environment (IcedTea 2.5.2) (7u65-2.5.2-3~14.04)
    OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode)

  4. Sorry for my Post .Can the Moderator please remove my post because was no think wrong but i forget to forward the port 8080
    Thx Arian

  5. Hi, Thanks for the post. Where are the apps/war files deployed? When I deploy them in the webapps folder of tomcat7-a it does not work. any help?

  6. Great post and very detailed!

    I got confused at one point following your tutorial. What do we must modify on the lines below, can you give us a sample following each of the instances that you ahve used throughout your sample

    Then open those files and change the necessary configurations sample shown given below.

    DESC=”Tomcat servlet engine”
    CATALINA_BASE=/var/lib/$NAME
    CATALINA_PID=”/var/run/$NAME.pid”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s