Friday, March 21, 2014

How To Install Apache Tomcat 7.0.52 Server on CentOS & RedHat 5/6

Apache Tomcat (or simply Tomcat) is an open source web server and servlet container developed by the Apache Software Foundation (ASF). Tomcat implements the Java Servlet and the JavaServer Pages (JSP) specifications from Sun Microsystems, and provides a "pure Java" HTTP web server environment for Java code to run in.

Apache Tomcat includes tools for configuration and management, but can also be configured by editing XML configuration files,To install Apache Tomcat 7.0.52 

Step 1) SSH your server as root user

Step 2) Install Java we will go for java-1.7.0-openjdk

yum install java-1.7.0-openjdk

Once java is installed check the current version of java by using command java -version output of the command will be like below as you can see version is "1.7.0_51".

=========
[root@ronakserver.com ~]# java -version
java version "1.7.0_51"
OpenJDK Runtime Environment (rhel-2.4.4.2.el5_10-i386 u51-b02)
OpenJDK Server VM (build 24.45-b08, mixed mode)
=========

Step 3) Not time to install Apache Tomcat7 follow the steps below.


  • cd /opt
  • wget http://www.eu.apache.org/dist/tomcat/tomcat-7/v7.0.52/bin/apache-tomcat-7.0.52.tar.gz
  • tar zxvf apache-tomcat-7.0.52.tar.gz
  • mv apache-tomcat-7.0.52 /usr/tomcat7
  • useradd -d /usr/tomcat7 tomcat
  • chown -R tomcat /usr/tomcat7
  • vi /etc/rc.d/init.d/tomcat7
Paste the below content in the file tomcat7 then save and exit.

 #!/bin/bash
# Tomcat7: Start/Stop Tomcat 7
#
# chkconfig: - 90 10
# description: Tomcat is a Java application Server.
. /etc/init.d/functions
. /etc/sysconfig/network
CATALINA_HOME=/usr/tomcat7
TOMCAT_USER=tomcat
LOCKFILE=/var/lock/subsys/tomcat
RETVAL=0
start(){
   echo "Starting Tomcat7: "
   su - $TOMCAT_USER -c "$CATALINA_HOME/bin/startup.sh"
   RETVAL=$?
   echo
   [ $RETVAL -eq 0 ] && touch $LOCKFILE
   return $RETVAL
}
stop(){
   echo "Shutting down Tomcat7: "
   $CATALINA_HOME/bin/shutdown.sh
   RETVAL=$?
   echo
   [ $RETVAL -eq 0 ] && rm -f $LOCKFILE
   return $RETVAL
}
case "$1" in
   start)
      start
      ;;
   stop)
      stop
      ;;
   restart)
      stop
      start
      ;;
   status)
      status tomcat
      ;;
   *)
      echo $"Usage: $0 {start|stop|restart|status}"
      exit 1
      ;;
esac
exit $?
  •  chmod 755 /etc/rc.d/init.d/tomcat7
  • /etc/rc.d/init.d/tomcat7 start
output of the command will be like below.
=======
[root@ronakserver.com~]# /etc/rc.d/init.d/tomcat7 start
Starting Tomcat7:
Using CATALINA_BASE:   /usr/tomcat7
Using CATALINA_HOME:   /usr/tomcat7
Using CATALINA_TMPDIR: /usr/tomcat7/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /usr/tomcat7/bin/bootstrap.jar:/usr/tomcat7/bin/tomcat-juli.jar
Tomcat started.
======
  • chkconfig --add tomcat7
  • chkconfig tomcat7 on
Now you can access Apache Tomcat7 using IP:8080 also make sure port 8080 is open in iptables.


No comments:

Post a Comment

Do Write about the Blog and Welcome to the world where open source is every thing :-)