linux下安装tomcat6

安装tomcat6。
  将tomcat安装包复制到/usr下。

  cp apache-tomcat-6.0.14.tar /usr/
  cd /usr
  mkdir tomcat6
  tar -zvxf apache-tomcat-6.0.14.tar

  解压后,就可以启动了。
  cd /usr/tomcat6/bin
  sh startup.sh
测试
http://127.0.0.1:8080
出现小猫说明成功
附加到系统启动
#vi /etc/rc.d/rc.local
#/usr/local/tomcat/bin/startup.sh(加到文件末尾)

  Tomcat启动可以用自带的jsvc来实现(转):

jsvc本来要从 http://jakarta.apache.org 下载,不过tomcat6 已经自己带了一个,在apache-tomcat-6.0.13/bin目录下有一个jsvc.tar.gz包,解压,编译:

#tar -xzvf jsvc.tar.gz
#cd jsvc-src
#sh support/buildconf.sh
#./configure --with-java=/usr/java
#make

查看/usr/local/apache-tomcat-6.0.13/bin/jsvc-src/native目录下有两个脚本 Tomcat.sh 和 Tomcat5.sh ,分别用作tomcat5前后版本的启动和停止tomcat的脚本。
由于每台机器的配置不尽相同,因此需要修改启动脚本的参数。

这里以tomcat6为例,因此修改Tomcat5.sh。修改后的文件如下:

#!/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.
##############################################################################
#
#chkconfig: 2345 85 15
#description: apache-tomcat.6

#
# 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:
#
   <!-- Define a non-SSL HTTP/1.1 Connector on port 80 -->
   <Connector className="org.apache.catalina.connector.http.HttpConnector"
             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_01
CATALINA_HOME=/usr/local/apache-tomcat-6.0.13
DAEMON_HOME=/usr/local/apache-tomcat-6.0.13/bin
TOMCAT_USER=tomcat

# for multi instances adapt those lines.
TMP_DIR=/var/tmp
PID_FILE=/var/run/jsvc.pid
CATALINA_BASE=/usr/local/apache-tomcat-6.0.13
#CATALINA_OPTS="-Djava.library.path=/home/jfclere/jakarta-tomcat-connectors/jni/native/.libs"
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/jsvc-src/jsvc \
    -stop \
    -pidfile $PID_FILE \
    org.apache.catalina.startup.Bootstrap
    exit $?
    ;;
  *)
    echo "Usage tomcat.sh start/stop"
    exit 1;;
esac

修改完成后,将Tomcat5.sh拷贝到 /etc/rc.d/init.d/目录下将命名为tomcat
#cp /usr/local/apache-tomcat-6.0.13/bin/jsvc-src/native/Tomcat5.sh /etc/rc.d/init.d/tomcat

添加进系统服务
#chkconfig --add tomcat
用--list看一下是否系统已有tomcat启动文件
#ckhconfig --list
即可把tomcat 添加为系统服务自动随系统启动了。这个脚本会在runlevel 2/3/4/5三种模式自动启动。


系统服务脚本必须有这下面这两行
#chkconfig: 2345 85 15 

(注:在运行级2/3/4/5中加入服务,启动顺序85,停止顺序15)
#description: apache-tomcat.6

posted @ 2008-12-09 11:16  不染丹心  阅读(1536)  评论(0编辑  收藏  举报