安装tomcat6。
一,到Apache下载 Tomcat6.0.16
二,解压缩Tomcat文件到/opt目录下(需要root用户权限)
#tar xvzf apache-tomcat-6.0.16.tar.gz
确认你的目录为/usr/local/apache6
三,测试你的tomcat是不是能够正常运行(确保JAVA_HOME环境变量设置过)
启动
测试
http://xx.xx.xx.xx:8080 出现小猫说明成功
#/usr/local/apache6/bin/start.sh
停止
#/usr/local/apache6/bin/shutdown.sh
四,将Tomcat部署为系统的服务(以jsvc方式运行)
1,解压缩jsvc包(/usr/local/tomcat6/bin/jsvc.tar.gz)
#tar xvzf jsvc.tar.gz
2,编译jsvc,并测试(假设jdk的安装路径:/usr/java/jdk1.6.0_06)
#cd /usr/local/tomcat6/bin/jsvc-src
#chmod +x configure
#.configure --with-java=/usr/java/jdk1.6.0_12
#.make
#cp jsvc ../
#cp /usr/local/tomcat6/bin/jsvc-src/native/Tomcat5.sh /etc/init.d/tomcat
编辑刚copy的tomcat文件
#vi /etc/init.d/tomcat
#!/bin/sh ############################################################################## # # Copyright 2004 The Apache Software Foundation. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ############################################################################## # # Small shell script to show how to start/stop Tomcat using jsvc # If you want to have Tomcat running on port 80 please modify the server.xml # file: # # # # port="80" minProcessors="5" maxProcessors="75" # enableLookups="true" redirectPort="8443" # acceptCount="10" debug="0" connectionTimeout="60000"/> # # That is for Tomcat-5.0.x (Apache Tomcat/5.0) # # Adapt the following lines to your configuration JAVA_HOME=/usr/java/jdk1.6.0_12 CATALINA_HOME=/usr/local/tomcat6 DAEMON_HOME=/usr/local/tomcat6/bin TOMCAT_USER=tomcat6 # for multi instances adapt those lines. TMP_DIR=/var/tmp PID_FILE=/var/run/jsvc.pid CATALINA_BASE=/usr/local/tomcat6 CATALINA_OPTS= CLASSPATH=\ $JAVA_HOME/lib/tools.jar:\ $CATALINA_HOME/bin/commons-daemon.jar:\ $CATALINA_HOME/bin/bootstrap.jar case "$1" in start) # # Start Tomcat # $DAEMON_HOME/jsvc-src/jsvc \ -user $TOMCAT_USER \ -home $JAVA_HOME \ -Dcatalina.home=$CATALINA_HOME \ -Dcatalina.base=$CATALINA_BASE \ -Djava.io.tmpdir=$TMP_DIR \ -wait 10 \ -pidfile $PID_FILE \ -outfile $CATALINA_HOME/logs/catalina.out \ -errfile '&1' \ $CATALINA_OPTS \ -cp $CLASSPATH \ org.apache.catalina.startup.Bootstrap # # To get a verbose JVM #-verbose \ # To get a debug of jsvc. #-debug \ exit $? ;; stop) # # Stop Tomcat # $DAEMON_HOME/src/native/unix/jsvc \ -stop \ -pidfile $PID_FILE \ org.apache.catalina.startup.Bootstrap exit $? ;; *) echo "Usage tomcat.sh start/stop" exit 1;; esac
添加执行用户
#useradd tomcat
确保tomcat用户能够访问tomcat的目录
#chown -R tomcat /usr/local/tomcat6
#chgrp -R tomcat /usr/local/tomcat6
#chmod +x /etc/init.d/tomcat
测试是否能启动tomcat
#/etc/init.d/tomcat start
#/etc/init.d/tomcat stop
添加进系统服务
#chkconfig --add tomcat
用--list看一下是否系统已有tomcat启动文件
#ckhconfig --list
即可把tomcat 添加为系统服务自动随系统启动了。这个脚本会在runlevel 2/3/4/5三种模式自动启动。
将tomcat部署成为自动运行的服务
#chkconfig tomcat on
启动服务
#service tomcat start
查询服务状态
#service tomcat status
停止服务
#service tomcat stop
系统服务脚本必须有这下面这两行
#chkconfig: 2345 85 15
(注:在运行级2/3/4/5中加入服务,启动顺序85,停止顺序15)
#description: apache-tomcat.6