Adsense 1

Tuesday, April 01, 2008

Installing tomcat in Linux

We will need Java to install tomcat. You can download it here. I used JDK 6 Update 5.

I am not going into the details of installing jdk. Make a note of where you install it. My jdk location is: /usr/java/jdk1.6.0_5

Download tomcat from here. I used 6.0.16

By default tomcat listens on port 8080, so you will not need super user permissions. If you are using any port <1024>
# passwd myuser

su - myuser

$ unzip /your/download/directory/apache-tomcat-x.x.x.zip (or)

if downloaded gzip file then
$ tar zxfv /your/download/directory/apache-tomcat-x.x.x.tar.gz

This creates a directory apache-tomcat-x.x.x. It is always a good practice to rename the directory and give it some meaning full name:
$ mv apache-tomcat-x.x.x test-tomcat

Set JAVA_HOME
$ export JAVA_HOME=/usr/java/jdk1.6.0_5/bin

Optionally set CATALINA_HOME (If you are running only one instance).
$ export CATALINA_HOME=/opt/test-tomcat

Remember to put the above entries in user's .bash_profile.

Starting tomcat:

$ cd ~/test-tomcat/bin/
$ chmod u+x *.sh ( so that the sh scripts can be executed)
$ cd ~/myservlet/ (where you store all config files needed by your servlet)
$ ~/test-tomcat/bin/startup.sh

Note: Normally any output/log file generated by your Servlet will be created in the directory where you started tomcat from. I generally use a directory named after my servlet. For this tutorial i am using used ~/myservlet as the directory.

If your servlet isn't generating logs of its own then you can view the logs in ~/test-tomcat/logs/ directory. This directory has many files. Two files are particularly important.
1. catalina.out is the main log file (watch out this grows faster in a big site with more hits & logging).
2. There are also individual files for each day (eg format: catalina-yyyy-mm-dd.log).

As i said above, tomcat service listens on port 8080 and serves webpages/ servlets through it. It also listens on following default ports:

8005 - Shutdown port (you can telnet to this port from localhost and shutdown the tomcat service by issuing SHUTDOWN in the telnet session. Afaik, You cannot enable this for remote connections).

8009 - AJP connector port (used to connect this tomcat instance with other tomcat or apache instances. Apache communicates with tomcat through this port).

8443 - SSL port (disabled by default).

To make life easier add aliases for shutting down and starting the tomcat instances:
$alias tomcat-down=~/test-tomcat/bin/shutdown.sh

$ alias tomcat-up= cd ~/myservlet ; ~/test-tomcat/bin/startup.sh

Remember to put alias entries in ~./bashrc. Also note that the above alias entry will work only if tomcat is installed in that user's home directory.

No comments:

Post a Comment