Linux: Tomcat 7 Installation

Installation:

tar xvzf apache-tomcat-7.0.2.tar.gz -C /usr/tomcat7 cd /usr/tomcat7 mv * .. cd .. rm -rf apache-tomcat-7.0.2.tar.gz

edit tomcat-users.xml and put:

<role rolename="manager-gui"/> <user name="nista" password="kookoo" roles="admin,manager,manager-gui" /> 
  • Optional Step: change port: edit server.xml and put port 1453 instead of 8080

Create environment variable CATALINA_HOME:

CATALINA_HOME="/usr/tomcat7" echo $CATALINA_HOME export CATALINA_HOME

start it:

cd bin . startup.sh

access it:

http://myIP:1453
  • upload the .war file for the application: ts.war, must include the /WEB-INF/lib

wsdl:

http://myIP:1453/ts/ts?wsdl

Run Tomcat as a service:

#!/bin/sh
#Startup script for the Jakarta Tomcat Java Servlets and JSP server
#
#chkconfig: - 85 15
#description: Jakarta Tomcat Java Servlets and JSP server
#processname: tomcat
#pidfile: /var/run/tomcat7.pid
#config:
#Source function library.
. /etc/rc.d/init.d/functions
#Source networking configuration.
. /etc/sysconfig/network
#Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
#: Set Tomcat environment.
export JAVA_HOME=/usr/java/jdk1.6.0_21
export CLASSPATH=.:/usr/java/jdk1.6.0_21/lib/tools.jar:/usr/java/jdk1.6.0_21/lib/rt.jar
export CATALINA_HOME=/usr/tomcat7
export CATALINA_OPTS="-server -Xms64m -Xmx512m -Dbuild.compiler.emacs=true"
export PATH=/usr/java/jdk1.6.0_21/bin:/usr/java/jdk1.6.0_21/bin:$PATH
[ -f /usr/tomcat7/bin/startup.sh ] || exit 0
[ -f /usr/tomcat7/bin/shutdown.sh ] || exit 0
export PATH=$PATH:/usr/bin:/usr/local/bin
#See how we were called.
case "$1" in
start)
# Start daemon.
echo -n "Starting Tomcat7: "
/usr/tomcat7/bin/startup.sh
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/tomcat7
;;
stop)
stop)
stop)
stop)
# Stop daemons.
echo -n "Shutting down Tomcat7: "
/usr/tomcat7/bin/shutdown.sh
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/tomcat7
;;
restart)
$0 stop
$0 start
;;
condrestart)
[ -e /var/lock/subsys/tomcat7 ] && $0 restart
;;
status)
status tomcat7
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit 0

Set its ownership and access rights:

chown root:root /etc/rc.d/init.d/tomcat7
chmod 755 /etc/rc.d/init.d/tomcat7

And add this init script to chkconfig:

chkconfig --add tomcat7
chkconfig tomcat7 on

Leave a Reply