Install Tomcat6. JAVA SE Kit and WEB server is also needed on this example.
[1] Install and configure Tomcat6.
[root@www ~]# wget
[root@www ~]# tar zxvf apache-tomcat-6.0.14.tar.gz
[root@www ~]# mv apache-tomcat-6.0.14 /usr/tomcat6
[root@www ~]# useradd -d /usr/tomcat6 -s /sbin/nologin tomcat
useradd: warning: the home directory already exists.
Not copying any file from skel directory into it.
[root@www jsvc-src]# chown -R tomcat. /usr/tomcat6
[2] Create starting or stopping script.
[root@www ~]# cd /usr/tomcat6/bin/
[root@www ~]# tar zxvf jsvc.tar.gz
[root@www ~]# cd jsvc-src
[root@www jsvc-src]# autoconf
[root@www jsvc-src]# sh configure --with-java=/usr/java/default
[root@www jsvc-src]# make
[root@www jsvc-src]# chown tomcat. jsvc
[root@www jsvc-src]# cp -p jsvc ../
[root@www jsvc-src]# cd
[root@www ~]# vi /etc/rc.d/init.d/tomcat
# an example
#!/bin/bash
#
# chkconfig: - 90 10
# description: Tomcat 6 - Java apprication server
. /etc/init.d/functions
JAVA=/usr/java/default
CATALINA_HOME=/usr/tomcat6
TOMCAT_USER=tomcat
TMP_DIR=/tmp
CATALINA_OPTS=
CLASSPATH=\
$JAVA/lib/tools.jar:\
$CATALINA_HOME/bin/commons-daemon.jar:\
$CATALINA_HOME/bin/bootstrap.jar
PIDFILE=/var/run/tomcat.pid
LOCKFILE=/var/lock/subsys/tomcat
DAEMON=$CATALINA_HOME/bin/jsvc
start(){
echo -n "Starting jsvc: "
$DAEMON \
-pidfile $PIDFILE \
-user $TOMCAT_USER \
-home $JAVA \
-Dcatalina.home=$CATALINA_HOME \
-Djava.io.tmpdir=$TMP_DIR \
-outfile $CATALINA_HOME/logs/catalina.out \
-errfile '&1' \
$CATALINA_OPTS \
-cp $CLASSPATH \
org.apache.catalina.startup.Bootstrap
RETVAL=$?
if [ $RETVAL = 0 ]; then
echo_success
touch $LOCKFILE
else
echo_failure
fi
echo
}
stop(){
echo -n "Shutting down jsvc: "
$DAEMON \
-stop \
-pidfile $PIDFILE \
org.apache.catalina.startup.Bootstrap
RETVAL=$?
if [ $RETVAL = 0 ]; then
echo_success
rm -f $PIDFILE $LOCKFILE
else
echo_failure
fi
echo
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status $DAEMON
RETVAL=$?
;;
*)
echo $"Usage: jsvc {start|stop|restart|status}"
exit 1
;;
esac
[root@www ~]# chmod 755 /etc/rc.d/init.d/tomcat
[root@www ~]# /etc/rc.d/init.d/tomcat start
Starting jsvc: [ OK ]
[root@www ~]# chkconfig --add tomcat
[root@www ~]# chkconfig tomcat on
[3] Access to "http://(your host name):8080/" with web browser and verify following tomcat site is shown normally.
[4] Configure to be able to access without specify 8080 in URL.
[root@www ~]# vi /etc/httpd/conf.d/proxy_ajp.conf
# add at the bottom
ProxyPass /tomcat/ ajp://localhost:8009/
[root@www ~]# /etc/rc.d/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[5] Access to "http://(your host name)/tomcat/" with web browser and verify tomcat site like [3] section is shown normally.
[6] Make test servlet that shows current day and time and Verify working.
[root@www ~]# mkdir /usr/tomcat6/webapps/ROOT/WEB-INF/classes
[root@www ~]# chown tomcat. /usr/tomcat6/webapps/ROOT/WEB-INF/classes
[root@www ~]# cd /usr/tomcat6/webapps/ROOT/WEB-INF/classes
[root@www classes]# vi daytime.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.Calendar;
public class daytime extends HttpServlet {
public void doGet(HttpServletRequest request
,HttpServletResponse response)
throws IOException, ServletException{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
Calendar cal = Calendar.getInstance();
out.println("");
out.println("");
out.println("
DayTime");
out.println("");
out.println("");
out.println("
");
out.println(cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DATE) + " " + cal.get(Calendar.HOUR_OF_DAY) + ":" + cal.get(Calendar.MINUTE));
out.println("
");
out.println("
");
out.println("");
}
}
[root@www classes]# javac -classpath /usr/tomcat6/lib/servlet-api.jar daytime.java
[root@www classes]# vi /usr/tomcat6/webapps/ROOT/WEB-INF/web.xml
# add following lines between
and .
daytime
daytime
daytime
/daytime
[7] Access to "http://(your host name)/tomcat/daytime" and verify following page is shown normally.