日期:2014-05-16  浏览次数:20716 次

Linux系统下tomcat5自启动配置

?? Linux系统系下tomcat自启动大体有两种配置方式:

? 【1】直接将启动代码写到/etc/rc.local里面。此种方式tomcat将以root权限运行,存在安全隐患,推荐第二种配置方式

? 【2】采用tomcat自带的jsvc脚本,下文仅介绍jsvc脚本的配置方式

?? 步骤一:创建tomcat运行用户

?? #useradd tomcat (创建用于运行tomcat的用户)

?? #usergrp tomcat (创建运行tomcat用户所在的组)

?? #usermod -G tomcat tomcat (将tomcat运行用户添入新建组中)

?? #chown -R tomcat $CATALINA_HOME (修改tomcat安装目录所属用户)

?? #chgrp -R tomcat $CATALINA_HOM (修改tomcat安装目录所属组)

?

?? 步骤二:生成jsvc脚本

?? 1.tomcat的安装目录的bin目录下存在一个jsvc.tar.gz或commons-daemon-native.tar.gz压缩文件,对其解压

?? 2.执行解压目录中的configure文件

?? 3.执行make命令即可得到jsvc脚本并将其复制到$CATALINA_HOME/bin目录下(建议在执行之前先执行makge clean命令,以避免make命令执行时报如下错误:

???? ar:?libservice.a:?Malformed?archive

???? make[1]:?***?[libservice.a]?Error?1)

?

?? 步骤三:将 commons-daemon-native.tar.gz解压目录\unix\native 目录 下的Tomcat5.sh脚本复制到/etc/init.d目录下并重命名为tomcat后做如下修改(注意:1.红色字体即可须修改部分? 2.脚本名一般和服务器保持一致,此即为将Tomcat5.sh修改成tomcat的原因)

?

#!/bin/sh
##############################################################################
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.? See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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:
#
#??? <!-- 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.5.0_15 (注意:不能引用系统的环境变量)
CATALINA_HOME=/usr/local/tomcat5 (注意:不能引用系统的环境变量)
DAEMON_HOME=$CATALINA_HOME
TOMCAT_USER=tomcat (设置tomcat将以何种用户执行)

# for multi instances adapt those lines.
TMP_DIR=/var/tmp
PID_FILE=/var/run/jsvc.pid
CATALINA_BASE=$CATALINA_HOME
?
#CATALINA_OPTS="-Djava.library.path=/home/jfclere/jakarta-tomcat-connectors/jni/native/.libs"
CLASSPATH=\
$JAVA_HOME/lib/tools.jar:\
$CATALINA_HOME/bin/commons-daemon.jar:\
$CATALINA_HOME/bin/bootstrap.jar

case "$1" in
? start)
??? $DAEMON_HOME/bin/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' \
??? $