Linux - Unix Learning

LINUX - UNIX Administration Learning

Sunday, August 8, 2010

Apache Tomcat

Apache Tomcat is an open source software implementation of the Java ServletJavaServer Pages technologies. The Java Servlet and JavaServer Pages specifications are developed under the Java Community Process.

Apache Tomcat is developed in an open and participatory environment and released under the Apache License version 2. Apache Tomcat is intended to be a collaboration of the best-of-breed developers from around the world. We invite you to participate in this open development project. To learn more about getting involved, click here
Apache Tomcat powers numerous large-scale, mission-critical web applications across a diverse range of industries and organizations. Some of these users and their stories are listed on the PoweredBy wiki page.

Step 1: Download the following source
   >> apache-tomcat-5.5.30.tar.gz
   >> jdk-6u21-linux-i586.rpm

Step 2: follow the instruction below
   >> adduser tomcat
   >> cd /home/tomcat

Download the source file.
-- wget http://download.filehat.com/apache/tomcat/tomcat-5/v5.5.30/bin/apache-tomcat-5.5.30.tar.gz
-- http://java.sun.com/javase/downloads/index.jsp >> (jdk-6u21-linux-i586.rpm)


   >> chmod a+x jdk-6u21-linux-i586-rpm.bin
   >> ./jdk-6u21-linux-i586-rpm.bin
   >> tar xzvf apache-tomcat-5.5.30.tar.gz


 Edit the file ".bash_profile" and add the following line


   >> vi /home/tomcat/.bash_profile
      add this >> export JAVA_HOME=/usr/java/jdk1.6.0_21


   >> chown tomcat:tomcat apache-tomcat-5.5.30


Step 3: Create starup script for tomcat


   >> vi /etc/init.d/tomcat
   >> chmod 755 /etc/init.d/tomcat


Add the following lines below.........
==========================================================
#!/bin/sh
#
# Startup script for Tomcat

JAVA_HOME=/usr/java/jdk1.6.0_21
export JAVA_HOME
start_tomcat=/home/tomcat/apache-tomcat-5.5.30/bin/startup.sh
stop_tomcat=/home/tomcat/apache-tomcat-5.5.30/bin/shutdown.sh

start() {
        echo -n "Starting tomcat: "
        su -c ${start_tomcat} - tomcat
        echo "done."
}
stop() {
        #echo -n "Shutting down http: "
        echo -n "Shutting down tomcat: "
        ${stop_tomcat}
        echo "done."
}

# See how we were called
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        stop
        sleep 10
        start
        ;;
  *)
        echo "Usage: $0 {start|stop|restart}"
esac

exit 0
===========================================================
Step 4: Edit /etc/sysconfig/iptables and add the line below

 -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT

  >> Restart Iptables 
     > service iptables restart or /etc/init.d/iptables restart

  >> telnet localhost 8080

Example:

    [root@nocdev java]# telnet localhost 8080
    Trying 127.0.0.1...
    Connected to localhost.localdomain (127.0.0.1).
    Escape character is '^]'.

Step 5: Run the tomcat script

    >> /etc/init.d/tomcat start

    You should get this after execute the command.

    [root@nocdev java]# /etc/init.d/tomcat  start
    Starting tomcat: Using CATALINA_BASE:   /home/tomcat/apache-tomcat-5.5.30
    Using CATALINA_HOME:   /home/tomcat/apache-tomcat-5.5.30
    Using CATALINA_TMPDIR: /home/tomcat/apache-tomcat-5.5.30/temp
    Using JRE_HOME:        /usr/java/jdk1.6.0_21
    Using CLASSPATH:       /home/tomcat/apache-tomcat-5.5.30/bin/bootstrap.jar
    done.

Then try to access http://localhost:8080 or http://IP ADDRESS:8080 in your local pc.