Tuesday, 12 March 2013

Quick Guide to setting up Tomcat on Linux

Tomcat's default website

Before starting

Check for the process:


# ps ax | grep tomcat

If it is installed it will show up in the response (don't be fooled by just grep tomcat).

And check the OS (see):
$ cat /etc/*-release
$ uname -m

This will tell you the release and whether it is 64 or 32 bit.

Install the Java JDK

Versions of Java can be installed using the “yum” tool (this will require super user rights). 
See: http://wiki.centos.org/HowTos/JavaOnCentOS


When installed I find that a convenience symbolic link "/java" is helpful.
Often the Yum tool places the files here /usr/lib/jvm/java-6-oracle
NB.
ln -s [TARGET DIRECTORY OR FILE] ./[SHORTCUT]

You can download the latest JDK here: http://www.oracle.com/technetwork/java/javase/downloads/index.html
The problem with this site is that it asks for you to accept the license conditions before you can down load the file.
This can be done by checking the url you get after browsing the appropriate links (see but best done using firefox not IE).

We'll install the latest JDK, which is JDK 7, Update 17. The JDK is specific to 32 and 64 bit versions.

My CentOS box is 64 bit, so I'll need: jdk-7u17-linux-x64.tar.gz.

If you are on 32 bit, you'll need: jdk-7u17-linux-i586.tar.gz
ie.

wget http://download.oracle.com/otn-pub/java/jdk/7u17-b02/jdk-7u17-linux-i586.tar.gz

NB. I'm not sure this works at all so I used WinSCP and transferred the file.

Start by creating a new directory /usr/java: (# mkdir /usr/java).
Download the appropriate JDK and save it to /usr/java directory we created above.

Unpack jdk-7u17-linux-x64.tar.gz in the /usr/java directory using tar -xzf:
tar -xzf jdk-7u17-linux-x64.tar.gz  

DON'T FORGET!!! 
... Set JAVA_HOME and put Java into the path of our user!

JAVA_HOME=/usr/java/jdk1.7.0_17
export JAVA_HOME 
PATH=$JAVA_HOME/bin:$PATH 
export PATH 
   
NB. The export command will marks each VAR for automatic export to the environment of subsequently executed commands i.e. make the local shell variable VAR global. (see)

Check you did it correctly:

#echo $JAVA_HOME 
#java -version

One GOTCHA at this point can be the error "-bash: /usr/java/jdk1.7.0_17/bin/java: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory"

This is easy to fix (see here) by issuing this command:
yum -y install glibc.i686
 

Download & Install Tomcat

If necessary versions of Tomcat can be installed by hand or using “yum”.

Details on Tomcat can be found here: http://tomcat.apache.org/ or more specifically: http://tomcat.apache.org/tomcat-7.0-doc/index.html.

We can manually do this as follows (installing Tomcat 7 under /usr/share.).
Download and unzip.

# wget http://mirror.ox.ac.uk/sites/rsync.apache.org/tomcat/tomcat-7/v7.0.37/bin/apache-tomcat-7.0.37.tar.gz
# tar -xzf apache-tomcat-7.0.29.tar.gz

 From this point you should be able to start the process by jumping to /user/share/apache-tomcat-7.0.37/bin and running the start.sh

For more information on starting as a service : see http://www.davidghedini.com/pg/entry/install_tomcat_7_on_centos

NB. I haven't gone into the details of tidying up the service with symbolic links (an exercise for the reader and me to tidy up in future.) 

To check the process is working then the following operation will work:

#curl -I http://localhost:8080

 

 

 







No comments:

Post a Comment