Friday, June 3, 2011

Installing tomcat in linux

Installing The Software
There are many ways that you can get Tomcat installed on your Linux system. You could use the rpm's that are now available on http://tomcat.apache.org/ or the tarballs from the http://tomcat.apache.org/ site. This document covers only the Tomcat tarballs.
If you have already downloaded the binary, simply copy it to the directory you want to install it under and expand the file. For example, if I downloaded the Tomcat tar file into /home/someuser/downloads and wanted to install it under /opt, here is what I would do. As root user:
# cp /home/someuser/downloads/jakarta-tomcat-5.x.xx.tar.gz /opt
# tar -zxvf jakarta-tomcat-5.x.xx.tar.gz
A directory called jakarta-tomcat-5.x.xx will be created and the Tomcat files will expand under it.
Previously, I would have recommended that the jakarta-tomcat-5.x.xx directory be renamed to just tomcat. However, because I expect Tomcat 5 to be updated more frequently for now, since it has only just been released, I would instead recommend creating a symbolic link to a tomcat directory.
# ln -s jakarta-tomcat-5.0.25 tomcat
In order for Tomcat to startup and shutdown, you will also need to add an environment variable pointing to the Tomcat directory (CATALINA_HOME), and one variable pointing to your Java SDK directory (JAVA_HOME). I will make the following assumptions:
JAVA_HOME
Java is installed into /opt/IBMJava2-141.
CATALINA_HOME
Tomcat is installed into /opt/jakarta-tomcat-5.x.xx and symlinked to /opt/tomcat.
Insert the following lines inside /etc/profile or /root/.bashrc.
export JAVA_HOME=/opt/IBMJava2-141
export CATALINA_HOME=/opt/tomcat
Now, save the file and reboot the system to ensure that all changes take effect.
3.4. Starting and Stopping Tomcat
Before we begin, we will need to ensure that CATALINA_HOME and JAVA_HOME are correctly set. To do this, we open a terminal and type the following :
# echo $CATALINA_HOME
# echo $JAVA_HOME
If you get a blank line, or if the directory points anywhere besides where it is supposed to, you will have to correct these environment variables first, before continuing.
If everything is fine, you can start Tomcat with the following command. As root,
# $CATALINA_HOME/bin/startup.sh
To check if Tomcat is running fine, you should open a browser and point the URL to http://localhost:8080. You should see the default Tomcat welcome page. It would be a good idea, at this point, to browse the documentation or try out the example servlets and JavaServer Pages samples.
To stop Tomcat, as root,
# $CATALINA_HOME/bin/shutdown.sh
If Tomcat does not start and you downloaded the zip file, the cause is probably due to permissions. Ensure that the following files are executable : inside $CATALINA_HOME/bin directory,
# chmod +x startup.sh
# chmod +x shutdown.sh
# chmod +x tomcat.sh
After you have made the files executable, try starting and stopping Tomcat again.
3.5. Running Tomcat as Non-Root User
I don't believe there any issues with running Tomcat as root user. However, for the more security-conscious readers out there, here are some instructions on running Tomcat as a non-root user.
At this stage, the Tomcat packages, files and binaries are owned by root. We will first need to create a Tomcat user and group that will own these files, and under which Tomcat will run.
Tomcat User :: tomcat
Tomcat Group :: tomcat
Not too imaginative, huh ? We will now create the Tomcat user and group. Open a terminal window and, as root,
# groupadd tomcat
# useradd -g tomcat -d /opt/tomcat tomcat
# passwd tomcat
Notice that we specified the home directory of Tomcat to be /opt/tomcat. Some people believe that this is good practice because it eliminates an additional home directory that needs to be administered.
Now, we will put everything in /opt/tomcat under Tomcat user and group. As root,
# chown -R tomcat:tomcat /opt/tomcat
If /opt/tomcat is a symlink to your Tomcat install directory, you'll need to do this:
# chown -R tomcat:tomcat /opt/jakarta-tomcat-5.x.xx
Verify that JAVA_HOME and CATALINA_HOME environment variables are setup for tomcat user, and you should be good to go. Once the Tomcat binaries are under Tomcat user, the way you invoke it will be different.
To start Tomcat,
# su - tomcat -c /opt/tomcat/bin/startup.sh
To stop Tomcat,
# su - tomcat -c /opt/tomcat/bin/shutdown.sh
Also, be aware that your web applications will need to be deployed (i.e. copied to the web application directories) as user tomcat, instead of root. A little more hassle, but possibly a little safer too.

Logoff Remote desktop connections Remotely

I used to receive the maximum number of connections error message when I try to log on to the Windows 2003 Server in my office via Windows Remote Desktop.
“The terminal server has exceeded the maximum number of allowed connections“

This is pretty annoying if you have some urgent work to do in the server. Most of the already logged in users won’t even be using the session at the time, but I can’t login! So how to solve this? After a bit of googling, as usual, I found a simple way to disconnect other remotely logged in sessions.

First of all you must be logged in to your client computer as a domain Admin user. Now open the command prompt and type in the following command.
qwinsta /server:SERVERIP
The Ip address or domain name of the Remote server should be entered in place of SERVERIP
Example:
qwinsta /server:10.10.1.10
You will get a list of the Remote Sessions in the command window.

In the above sceenshot we can clearly see an Active RDP session with the ID 2 which belongs to the user Administrator. In order to disconnect that user we are going to use the session ID. Use the following command line to disconnect the remote session.
rwinsta /server:SERVERIP SESSIONID
For example in order to terminate the session of the Administrator user the following command should be given.
rwinsta /server:10.10.1.10 2

Now let’s confirm if the user is really disconnected. Just type in the qwinsta command in proper format.

As you can see our session with ID 2 is no longer there. Now for the user we just disconnected will see the following message.

The remote session was disconnected because you session was logged off at the remote computer. Your administrator or another user might have ended your connection.