Saturday, October 08, 2011

Installing Tomcat 6 on Redhat Enterprise

List of commands that took place:

cd /opt
wget http://mirrors.isu.net.sa/pub/apache/tomcat/tomcat-6/v6.0.33/bin/apache-tomcat-6.0.33.zip
unzip apache-tomcat-6.0.33.zip
ln -s /opt/apache-tomcat-6.0.33 tomcat
yum install java-1.6.0-sun
alternatives --config java



There are 3 programs which provide 'java'.


Selection    Command
-----------------------------------------------
1           /usr/lib/jvm/jre-1.4.2-gcj/bin/java
*+ 2           /usr/lib/jvm/jre-1.6.0-sun.x86_64/bin/java
3           /usr/lib/jvm/jre-1.6.0-sun/bin/java


Enter to keep the current selection[+], or type selection number: (Press 2 Then Enter)
vim /etc/init.d/tomcat

While in vim type the following in command mode to avoid extra spaces which pasting:
:set paste

Copy the following text and paste it:

#!/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

Then write and quit in vim:
:wq

Make sure the file doesn't contain microsoft new lines:
dos2unix /etc/init.d/tomcat

Now change to executable:
chmod +x /etc/init.d/tomcat

Next create a tomcat user:
groupadd tomcat
useradd -g tomcat -d /opt/tomcat tomcat
passwd tomcat
password: tomcat
retype password: tomcat

Reassign permissions to directories:
chown -R tomcat:tomcat /opt/tomcat
chown -R tomcat:tomcat /opt/apache-tomcat-6.0.33
cd /opt/tomcat/bin
chown +x *.sh

Add tomcat to services:
chkconfig --add tomcat
chkconfig --level 345 tomcat on

Start tomcat:
/etc/init.d/tomcat start


No comments: