This article is the first part of my serie : load balancing using mod_jk
Let’s install first java using openjdk:
$ sudo apt-get install openjdk-7-jre
In fact in the previous command we are just installing the Java Runtime Environment (JRE). If there is a case where you would need the Development ToolKit (JDK) then use openjdk-7-jdk instead.
Now that we have our java installed let’s proceed with the tomcat.
$ sudo apt-get install -y tomcat6 tomcat6-users
Normally tomcat6 itself would have been enough but because we needed to install multiple instance of it, there is a very convenient command to cater for that bundled with the tomcat6-users packages.
We actually needed some files and components provided by tomcat6 command, that was the only reason we installed it, we could have actually done without it if not. But as is we don’t want tomcat with all the defaults stuff to get in our way specially when restarting the box(machine) or anything else, we will disable it and remove it’s scripts from all the auto start stop etc stuff that ubuntu itself runs.
Let’s stop the default tomcat6 that we installed.
$ sudo service tomcat6 stop
The let’s disable it(removing its scripts from update-rc.d)
$ sudo update-rc.d -f tomcat6 remove
That’s done now let’s go to where we want to actually create our instances. Let me stop here and give a brief overview of what we’ve done so far. we installed java and used(you can say trick in this case 🙂 ) tomcat6 to get some structure, files and folders done for us. But in reality we never had the intention of using that tomcat instead we would use that special utility that comes with the tomcat6-users package. i will be using /opt/tomcat6 folder for this tutorial but feel free to use any path at your convenience.
Moving to /opt path
$ cd /opt
Creating tomcat6 directory
$ sudo mkdir tomcat6 $ sudo chown tomcat6:root #Let's own the folder to simplify access privileges to that folder
For this tutorial we are creating 2 instances of tomcat. Let’s call them timo and pumba
$ sudo tomcat6-instance-create -p 8081 -c 8006 timo
$ sudo tomcat6-instance-create -p 8082 -c 8007 pumba
-p specifies the running port of the instance and -c the shutdown port. according to this documentation
Normally we would have stopped here but let’s configure a little utility to ease our life.
$ cd /etc/init.d
$ sudo cp tomcat6 timo $ sudo cp tomcat6 pumba
Using nano editor we are going to personalize our startup/shutdown script.
$ sudo nano timo
Let’s change the following values
NAME=timo DESC="Tomcat Timo servlet engine" #DEFAULT=/etc/default/$NAME DEFAULT=/etc/default/tomcat6 JVM_TMP=/tmp/$NAME-tmp CATALINA_HOME=/usr/share/tomcat6 #CATALINA_BASE=/var/lib/$NAME CATALINA_BASE=/opt/tomcat6/timo
NAME=pumba DESC="Tomcat Pumba servlet engine" #DEFAULT=/etc/default/$NAME DEFAULT=/etc/default/tomcat6 JVM_TMP=/tmp/$NAME-tmp CATALINA_HOME=/usr/share/tomcat6 #CATALINA_BASE=/var/lib/$NAME CATALINA_BASE=/opt/tomcat6/pumba
After this edit, let’s automate their shutdown and startup.
$ sudo update-rc.d timo defaults 90 $ sudo update-rc.d pumba defaults 90
Voila!, now you can start your timo instance with:
$ sudo service timo start # or shutdown sudo service timo stop
Same for pumba
$ sudo service pumba start # or shutdown sudo service pumba stop
Stay tune for the next post where i show how i load balance the timo and pumba with apache2 mod_jk