Wednesday 23 May 2012

Step by step Installing Tomcat 6 on Redhat Enterprise Linux.

 *********************

Tomcat 6 on CentOS 5.2

1. Download jdk-6u11-linux-i586-rpm.bin from
http://java.sun.com/javase/downloads/index.jsp.

2. cd Desktop;
 #./ jdk-6u11-linux-i586.bin

3. As root, insert following lines in /etc/profile.
#vim /etc/profile --add below code..
export JAVA_HOME=/usr/java/default
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar

4. . /etc/profile

5. #mkdir /tmp; cd /tmp

6. wget http://ftp.sh.cvut.cz/MIRRORS/apache/tomcat/tomcat-6/v6.0.18/bin/apache-tomcat-6.0.18.tar.gz

7. #tar xvzf apache-tomcat-6.0.18.tar.gz

8. #mv -f apache-tomcat-6.0.18 /usr/share/tomcat6

9. #chown -R tomcat /usr/share/tomcat6

10. #ln -s /usr/share/tomcat6 /usr/share/tomcat

11. #useradd -d /usr/share/tomcat -s /sbin/nologin tomcat

12. Create /etc/init.d/tomcat as shown below:(Script to start, stop and restart Tomcat)
The above installation step will not create tomcat service so that user can restart tomcat using command service tomcat restart. Create a new file in /etc/init.d as tomcat and copy following contenents into it.
Quote:
#vi /etc/init.d/tomcat
#!/bin/bash
#
# Startup script for Tomcat
#
# chkconfig: 345 84 16
# description: Tomcat jakarta JSP server
#Necessary environment variables
export CATALINA_HOME="/usr/local/tomcat"
if [ ! -f $CATALINA_HOME/bin/catalina.sh ]
then
echo "Tomcat not available..."
exit
fi


start() {
echo -n -e '\E[0;0m'"\033[1;32mStarting Tomcat: \033[0m \n"
su -l tomcat -c $CATALINA_HOME/bin/startup.sh
echo
touch /var/lock/subsys/tomcatd
sleep 3
}

stop() {
echo -n -e '\E[0;0m'"\033[1;31mShutting down Tomcat: \033[m \n"
su -l tomcat -c $CATALINA_HOME/bin/shutdown.sh
rm -f /var/lock/subsys/tomcatd
echo
}

status() {
ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}' | wc | awk '{print $2}' > /tmp/tomcat_process_count.txt
read line < /tmp/tomcat_process_count.txt
if [ $line -gt 0 ]; then
echo -n "tomcatd ( pid "
ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'
echo -n ") is running..."
echo
else
echo "Tomcat is stopped"
fi
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 3
start
;;
status)
status
;;
*)
echo "Usage: tomcatd {start|stop|restart|status}"
exit 1
esac
Save and exit from the file. Now assign executable permission to this file
#vim /etc/init.d/tomcat---add below code...

# Tomcat auto-start
#
# description: Auto-starts tomcat
# processname: tomcat
# pidfile: /var/run/tomcat.pid

export JAVA_HOME=/usr/java/default

case $1 in
start)
sh /usr/share/tomcat6/bin/startup.sh
;;
stop)
sh /usr/share/tomcat6/bin/shutdown.sh
;;
restart)
sh /usr/share/tomcat6/bin/shutdown.sh
sh /usr/share/tomcat6/bin/startup.sh
;;
esac
exit 0

:wq

13. #chmod +x /etc/init.d/tomcat

14. #chkconfig tomcat6 on

15. Add following into /usr/share/tomcat/conf/tomcat-users.xml:
#vim /usr/share/tomcat/conf/tomcat-users.xml
 <user username="tomcat" password="tomcat" roles="manager,admin">

16. Add $CATALINA_HOME to /etc/profile.
#vim /etc/profile

export CATALINA_HOME=/usr/share/tomcat

17. #/etc/init.d/tomcat start

18. If the Apache Tomcat page can be found at http://localhost:8080, the installation is correct.
-->open browser--->http://localhost:8080
19. Done.















            
----------------------------
Add username/Password for tomcat manager:

How to add a new user name to tomcat manager:

just add line number 3 and 6 to /install/apache-tomcat-5.5.29/conf/tomcat-users.xml    
 1) <?xml version='1.0' encoding='utf-8'?>    
 2) <tomcat-users>   
 3) <role rolename="manager"/>  
 4) <role rolename="tomcat"/>    
 5) <role rolename="role1"/>    
 6) <user username="manager" password="tomcat" roles="manager,tomcat"/> 
 7) <user username="tomcat" password="tomcat" roles="tomcat"/>   
 8) <user username="both" password="tomcat" roles="tomcat,role1"/>   
 9) <user username="role1" password="tomcat" roles="role1"/>   
10) </tomcat-users>Restart tomcat server.By using service tomcat restart.

1007  /usr/bin/java -version
 1008  yum install java*
 1009  ls
 1010  ./jdk-6u32-linux-i586.bin
 1011  ls
 1012  pwd
 1013  chmod +x jdk-6u32-linux-i586.bin
 1014  ./jdk-6u32-linux-i586.bin
 1015  vim /etc/profile
 1016  ls
 1017  tar -xvzf apache-tomcat-6.0.18.tar.gz
 1018  ls
 1019  mv -f apache-tomcat-6.0.18 /usr/share/tomcat6
 1021  ln -s /usr/share/tomcat6 /usr/share/tomcat
 1034  vim /etc/init.d/tomcat
 1035  dos2unix /etc/init.d/tomcat
 1036  chmod +x /etc/init.d/tomcat
 1037  groupadd tomcat
  1039  /usr/sbin/groupadd tomcat
 1040  /usr/sbin/useradd -g tomcat -d /opt/tomcat tomcat
 1041  passwd tomcat
 1042  pwd
 1043  ls
 1047  vim  /usr/share/tomcat/conf/tomcat-users.xml
 1048  vim /etc/profile
 1049  /etc/init.d/tomcat start
 1050  vim /etc/profile
 1051  /etc/init.d/tomcat start
 1052  vim /etc/init.d/tomcat
 1053  /etc/init.d/tomcat start

**********************



###########################################

3 comments:

  1. See http://www.davidghedini.com/pg/entry/install_tomcat_6_on_centos for more up-to-date info.

    ReplyDelete
  2. Thanks a lot <<<<<<<<<<<>>>>>>>>

    ReplyDelete