Saturday, October 08, 2011

Installing Tomcat 6 on Redhat Linux Enterprise or CentOS

http://wiki.openbluedragon.org/wiki/index.php/Apache_Tomcat_on_CentOS/RedHat

From: 

Install Tomcat

With CentOS/RedHat you could install Tomcat from the YUM repositories, but they only hold the older 5.5.x version. Of course, if you want to have Version 5.5.x installed then you only have to issue a;
yum install tomcat*
But I do recommend that you install Tomcat 6.0.18 (the current version of this writing), since it features better memory handling and some other improvements. The official Tomcat page is your friend in this regard http://tomcat.apache.org/. Luckily, installing Tomcat is straight forward.
  1. Download Tomcat 6.0.18
    1. Browse to http://tomcat.apache.org/download-60.cgi and download the Binary Distribution or click on the direct link here http://apache.mirror.testserver.li/tomcat/tomcat-6/v6.0.18/bin/apache-tomcat-6.0.18.tar.gz. Wget is your friend.
  2. I recommend to install Tomcat in the "/opt" directory. Thus copy the downloaded file into "/opt".
  3. Extract it with
tar xzvf apache-tomcat-6.0.18.tar.gz
  1. For better handling I always create a symbolic link for "tomcat" with
ln -s /opt/apache-tomcat-6.0.18 tomcat
  1. Test Tomcat
    1. Start Tomcat with:
/opt/tomcat/bin/startup.sh
    1. Hit http://localhost:8080. If all is fine you should see the Tomcat homepage.
All should be fine, right? Ok, move on.

Deploy (Install) OpenBD

  1. go into the tomcat folder
    1. cd /opt/tomcat/
  2. download the openbd.war file (be sure to check the OpenBD download site for the latest war file link)
    1. wget http://openbd.viviotech.net/downloader.cfm/id/64/file/openbd.war
  3. once the file has downloaded move it to the tomcat webapps folder where it will automatically deploy
    1. mv /opt/tomcat/openbd.war /opt/tomcat/webapps
  4. once the war file is in webapps Tomcat will pick it up and create an openbd folder
  5. go to the administrator
    1. http://localhost:8080/openbd/bluedragon/administrator
      1. the default bluedragon administrator password is admin

Configure Tomcat to run on startup

Now, that Tomcat and OpenDB runs nicely you might want to have it automatically started when you reboot your system. For that we can use the following script and "chkconfig" command line.
  1. Create a "tomcat" file in "/etc/init.d"
vi /etc/init.d/tomcat
  1. Copy the below startup script
#!/bin/bash
#
# Init file for SixSigns Tomcat server
#
# chkconfig: 2345 55 25
# description: SixSigns Tomcat server
#

# Source function library.
. /etc/init.d/functions

RUN_AS_USER=tomcat # Adjust run user here
CATALINA_HOME=/opt/tomcat

start() {
        echo "Starting Razuna Tomcat: "
        if [ "x$USER" != "x$RUN_AS_USER" ]; then
          su - $RUN_AS_USER -c "$CATALINA_HOME/bin/startup.sh"
        else
          $CATALINA_HOME/bin/startup.sh
        fi
        echo "done."
}
stop() {
        echo "Shutting down Razuna Tomcat: "
        if [ "x$USER" != "x$RUN_AS_USER" ]; then
          su - $RUN_AS_USER -c "$CATALINA_HOME/bin/shutdown.sh"
        else
          $CATALINA_HOME/bin/shutdown.sh
        fi
        echo "done."
}

case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        stop
        sleep 10
        #echo "Hard killing any remaining threads.."
        #kill -9 `cat $CATALINA_HOME/work/catalina.pid`
        start
        ;;
  *)
        echo "Usage: $0 {start|stop|restart}"
esac

exit 0
  1. Save the file (case you forgot "esc + x) :-)
  2. Add the tomcat startup script to the chkconfig with:
chkconfig --add tomcat
  1. Then activate it for your run level. Since I am not running any X Server on my server I only want to run it on level 345. Do it with:
chkconfig --level 345 tomcat on
  1. You can check if Tomcat will startup on reboot with listing the startup scripts with:
chkconfig --list
You should see a;
tomcat         	0:off	1:off	2:on	3:on	4:on	5:on	6:off
  1. If you have done all well, you should now be able to bounce Tomcat with this script as well. Try it with:
/etc/init.d/tomcat restart

No comments: