Archive for Nov 24, 2011

Installing Tomcat 6.x on CentOS 5

             

Installing Tomcat 6.x on CentOS 5


UPDATE: This post was revised to work with java6u10 and now includes instructions for automated startup config.
FYI: if you used this post before 11/06, there have been some major changes to the start up script. This new version is the most basic and easiest.
This is a quick and dirty guide for installing Apache Tomcat 6.0.18 on CentOS5. It is based on detailed instructions for CentOS 4 and tomcat 6.0.13 here. If you get no luck, please check out this link for comprehensive explanation and adopt it to your platform.
Install pre-requisite
1. Download java JDK 6 Update 10 and Java Runtime Environment (JRE) 6 Update 10 bin (NOT RPM)

2. Open terminal, su to root and move downloaded files to /root directory
$ su root
Password:
# mv [.....]
3. Create java environment
# mkdir /usr/java
# cd /usr/java
4. Execute downloaded jdk and jre bins.
# sh /root/jre-6u10-linux-i586.bin
# sh /root/jdk-6u10-linux-i586.bin
5. verify install
# ls
you should see that your /usr/java directory now contains jdk1.6.0_10 and jre1.6.0_10 directories
Install overview
1. Download and extract Apache Ant (apache-ant-1.7.1-bin.tar.gz) to /usr/share
# cd /usr/share
# tar -xzf apache-ant-1.7.1-bin.tar.gz
2. Download and extract Apache Tomcat (apache-tomcat-6.0.18.tar.gz) to /usr/share
# tar -xzf apache-tomcat-6.0.18.tar.gz
3. Enable ant link
# ln -s /usr/share/apache-ant-1.7.1/bin/ant /usr/bin
4. Set up JAVA_HOME $env in catalina.sh
# cd /usr/share/apache-tomcat-6.0.18/bin
# vi catalina.sh
5. After the first line, add following
JAVA_HOME=/usr/java/jdk1.6.0_10
6. Test config with Tomcat
# cd /usr/share/apache-tomcat-6.0.18/bin
# ./startup.sh
7. Check logs for errors
# less /usr/share/apache-tomcat-6.0.18/logs/catalina.out
8. Fix errors if any. Go to http://localhost:8080 for Tomcat's web interface.
Automate start up
1. Create script in /etc/init.d for automated start up/shutdown
# cd /etc/init.d
# vi tomcat

2. Place following in the file
#!/bin/bash
# chkconfig: 234 20 80
# description: Tomcat Server basic start/shutdown script
# processname: tomcat
JAVA_HOME=/usr/java/jdk1.6.0_10
export JAVA_HOME
TOMCAT_HOME=/usr/share/apache-tomcat-6.0.18/bin
START_TOMCAT=/usr/share/apache-tomcat-6.0.18/bin/startup.sh
STOP_TOMCAT=/usr/share/apache-tomcat-6.0.18/bin/shutdown.sh
start() {
echo -n "Starting tomcat: "
cd $TOMCAT_HOME
${START_TOMCAT}
echo "done."
}
stop() {
echo -n "Shutting down tomcat: "
cd $TOMCAT_HOME
${STOP_TOMCAT}
echo "done."
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 10
start
;;
*)
echo "Usage: $0 {start|stop|restart}"
esac
exit 0

2. Change permissions
# chmod 755 tomcat
3. Add script to system services
# chkconfig --add tomcat
4. Verify modifications (this script uses levels 2-4)
# chkconfig --level 234 tomcat on
# chkconfig --list tomcat
you should see that service using levels 2, 3 and 4:
tomcat 0:off 1:off 2:on 3:on 4:on 5:off 6:off
5. Test script start up/shutdown
# service tomcat start
# service tomcat stop

So, at this point, tomcat service will start automatically upon reboot. G'luck

-------------------------------------------------------------------------------------------------------------
FEED













SUPPORT US












VISIT COUNTER !!





Installing Java and Apache Tomcat in your CentOS / Redhat Server

Installing Java and Apache Tomcat in your CentOS / Redhat Server

Steps :

Installing Java SDK

Step 1: SSH into the server using the following command
ssh –X root@ip-address-of-server
Then provide the root password. Please note that you need to use the root (admin) account itself, since you need super-user privileges to install applications in the server.

ssh to linux server

Step 2: Install jpackage-utils in the server using
yum install jpackage-utils

You can also get the packages (using wget) from http://www.jpackage.org/ and install them manually.

installing jpackage

This will automatically pull the packages from the repository and install them Smile

java-utils

Step 3: Now we are going to install the Java SE Development Kit 6u22 for Linux. You may check this site to find whether this is latest version or not.
Since I’m going to use wget, I need a direct link to download the package.You can grab the package from here


http://techblog.googlecode.com/files/jdk-6u22-linux-i586-rpm.bin

Now use wget and pull this package to your server.

downloading java sdk from techblog project site

Step 4: Once it has been downloaded directly to the server, change the permissions accordingly as shown below:
chmod +x package-name.bin



Now issue the following command and verify that Java has been installed properly.
java –version

verifying java installation

Installing Tomcat

Since Apache Tomcat is available in the repository, you can use the install command for installing it:
yum install tomcat*

This will install the server.

installing tomcat using yum

But in my case, it installed tomcat5 – which is an old version. The new version has a better memory management utility. So I had to remove the installation Sad smile
remove yum 

removing tomcat

Installing Tomcat6 manually

As of today the latest version is 6.0.29. So we use the wget utility and download the package from the server:
wget http://apache.mirror.testserver.li/tomcat/tomcat-6/v6.0.29/bin/apache-tomcat-6.0.29.tar.gz

Please note that it is better to download this file to the /opt directory. (You can do this either by ‘cd-ing’ to the directory before issuing the wget or moving the file to /opt once the file has been downloaded).

installing tomcat manually

Now untar the tarball using
tar –xvfz tarball-name.tar.gz

This will extract the items in the tarball and now you need to go to the bin directory in the extracted directory and run the startup.sh script. That’s it!
Now go to localhost:8080 (you may use Lynx for this) and verify that tomcat is running:
lynx
press g
enter “localhost:8080”

tomcat - using lynx

NOTE: Now you can try it at ip-address-of-server:8080. Please note that sometimes the datacentre may not have opened the port 8080. In my case, since Nazdrovia is using Planet Inc as the datacentre for providing the frontend and Amazon EC2 as backend, I had to ask them to open the port. So if you are getting a ‘server not found’ error, it is due the firewall – you may ask the datacentre to open it.

Starting Apache Tomcat during bootup

It is hard to run the start-up script manually every time you restart the server. So you may add the location of the script to
/etc/rc.d/rc.local
 
And it will be executed automatically every time you boot the system.
Please note that if you are using a Debian based distribution, then the location of the above mentioned file is at:
/etc/rc.local
 
Admin and Manager roles You need to assign admin and manager roles to the tomcat users in order to manage web apps using a web based interface. (Please note that if you put anything in the web-apps directory of the server, it will be deployed automatically).You can do this by going to the new folder you created by extracting the tarball and editing the tomcat-users.xml file (/conf/tomcat-users.xml).
nano tomcat-users.xml

Now you need to add the following lines to that xml file:



Please note that you have to change the default passwords of the existing users due to security reasons. Once you have done that you can login to the admin and manager pages :
ip-address-of-server:8080/admin

tomcat web app admin

ip-address-of-server:8080/manager

tomcat web app manager


Managing the service

You can start or stop the tomcat service using the following commands:

/etc/init.d/tomcat6 start
/etc/init.d/tomcat restart
/etc/init.d/tomcat stop


Have fun and enjoy!




FEED













SUPPORT US












VISIT COUNTER !!