Tuesday, March 15, 2011

Tomcat Install (under linux)

Introduction

Well, here we are again :) Installations! This time I’m installing Tomcat (not sure which version yet – possibly 6.x ) on a linux box. Of course, there’s a bit of head scratching and finding out exactly what we need to do prior to install.

So, we have a vanilla system. It has apache running but has never seen hide nor hair of anything like java. So first I have to download a jdk – sounds simple ? Well, it should be – but like many people I tend to get a bit confused when it comes to navigating Sun’s java site. So many varieties of jdk, sdk, jre with or without beans and whatever new “technological methods” Sun have come up with. Occasionally conflicting documentation (search for jdk linux – you get instructions telling you to install obsolete software … or is it obsolete ? I’ve no idea)

Installing Java

As I’m not sure I have access to compilers and the like (a legacy policy of never putting any sort of development malarkey on a front-facing server) I’m going to have to pick a binary install; which should work fine without any issues… I hope!

(fortunately, if there are any issues – this is a soon-to-be-decommissioned box that is just sitting around spinning it’s wheels, so to speak; so it’s not going to take down any “mission critical” applications … at least… it shouldn’t do :) )

In this instance, I’ve decided upon the Linux binary distribution of the Java SE Development Kit 6 (update 6) (I’d give a link to the page on java.sun.com but that looks to be generated via session variables on a by-user basis)

jdk-6u6-linux-i586.bin

(from the page http://java.sun.com/j2se/1.5.0/install_jdk150-nb40_linux.html we are told to set the permissions on the file so we can execute it; they say chmod 755 jdk*.bin although my preferred method ischmod u+x jdk*.bin (but that’s just me … oh, and I’m just being lazy – you can type the whole jdk filename in if you want (or if you have lots of jdk’s in the folder and don’t want them all to be executable :) )))

let’s run the executable

./jdk-6u6-linux-i586.bin

Good grief ! That’s a long user agreement… I really should read it one of these days, I heard rumours of them smuggling clauses allowing them to take your first born son … but… life’s too short :) and generally they could be summarized into a simple statement

“you agree to not do anything naughty – like stealing things , we’ll find out and catch you you know.”

to which, we have to say “yes” (surely we should be able to say “no, we don’t agree” and still use the software? Are these things really binding? I don’t know… anyway… I’m digressing )
of course, once it gets to the end “Java(TM) SE Development Kit 6 successfully installed”

So what have I got ?

in the directory I ran the jdk in, there is now a folder “jdk1.6.0_06″ ; to make upgrades (hopefully) easier, I’ll make a symbolic link to this directory

ln -s jdk1.6.0_06 java

I’ll now set up some environment variables (so we know where to find things)

emacs /etc/profile

(or feel free to use vi or whichever text editor you prefer)
Assuming you’ve not done anything to tweak the default profile, there will be a line in the file that says something like

export PATH DISPLAY LESS TERM PS1 PS2

before this line I’ll add the following

JAVA_HOME=/[path to java install eg. /usr/local/java]
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=$JAVA_HOME/lib

and then on the end of this line I’ll add JAVA_HOME and CLASSPATH
i.e.

export PATH DISPLAY LESS TERM PS1 PS2 JAVA_HOME CLASSPATH

that done, I can type . /etc/profile which’ll re-set the environment variables (which can be proven by typing java -version ); which in turn means we can now run java. Now to install tomcat. Let’s try tomcat 6…

Installing Tomcat 6

First to download our copy of tomcat. http://tomcat.apache.org/download-60.cgi (Question: Why aren’t there any “linux” versions listed ? Answer: Because it’s java! The same package as is installed on windows will work on Macs, unix boxes and all sorts of places – probably even your hand-held device (assuming it has space for it!)

We’ll download the tar.gz version (tar being a unix standard “tape archive” (remember unix principles 101?) and gz being the gzip compression format (as tar archives are uncompressed by default – remember? Were you listening ? :) )) at the moment, the latest archive is http://www.smudge-it.co.uk/pub/apache/tomcat/tomcat-6/v6.0.16/bin/apache-tomcat-6.0.16.tar.gz (note that this is linking to one of the many mirror sites used for distribution of the apache/jakarta projects)

change directory to your installation folder – e.g. cd /usr/local
decompress the archive – gunzip apache-tomcat-6.0.16.tar.gz
untar the archive – tar -xmvf apache-tomcat-6.0.16.tar

(alternatively, you can miss out the decompressing stage and instead use tar -xmzvf (the z is for decompress gzip format)

we’ll make another symbolic link now, to make it (hopefully) easier to upgrade

ln -s apache-tomcat-6.0.16 tomcat

in the tomcat directory there will be a folder called “RUNNING.txt” – the following notes are derived from that…

First I’ll edit the /etc/profile file again and add in a new environment variable for “CATALINA_HOME” (this will point to the installation folder) and ensure that the variable gets exported – similar to the JAVA_HOME

in theory, we should now be able to start up tomcat and see it running on port 8080 – cd $CATALINA_HOME/bin and type ./startup.sh

When I tried this just, it complained about being unable to find a file … “setclasspath.sh” – which is strange as it is right there… Let’s try and troubleshoot a little bit…

(A quick search online provides an answer to this – on the tomcat wiki )

We have to edit the catalina.sh and setclasspath.sh files and add the following lines (to the beginning)

BASEDIR=/[path to your tomcat install]
CATALINA_HOME=[/path to your tomcat install]

we can then try again – cd /path to tomcat/bin
./startup.sh

if everything works okay, we should then be able to type

ps guax | grep java

which’ll show the process (note, versions of ps differ from system to system; so if you get an error, you can always try ps -guax or some other combination – remember the system manual is your friend :) man ps )

we can now try and display the site – in a web browser, point it to the server on port 8080 – if everything has worked (as it has in my case) you’ll get the default tomcat server page/documentation/examples.

And as everything has worked so far – I think it’s a good time to take lunch :)
More later!

Well, that was lunch… back to the install.

After all that work, we should have a working version of tomcat. However, we don’t have any users set up – so how do we manage our applications (etc) ? Well, first things first, let’s create a role in the

[tomcat root]/conf/tomcat-users.xml file.

it should look something like this





once you have made the changes, you’ll need to restart tomcat
/[tomcat root]/bin/shutdown.sh

(wait a few moments – you can type ps guax|grep java to see if the process has stopped before running)

/[tomcat root]/bin/startup.sh

to start the service up again.

You can check in the /[tomcat root]/logs/catalina.out file to see if there are any errors generated .

No comments: