1、准备工作
Tomcat安装后,如果让Tomcat用root身份启动,Tomcat将会拥用root权限,这将可能给系统带来安全隐患,黑客可能利用这个来攻击我们的系统,所以我们得添加一个独立运行此服务的用户,用下面的命令:
shell>useradd -d /usr/local/tomcat6 -s /usr/sbin/nologin tomcat
以上命令为系统增加一个tomcat用户,并且设置为nologin
设置用户tomcat5对tomcat的权限
shell>chown -R tomcat:tomcat /usr/local/tomcat6
shell>chown -R tomcat:tomcat /opt/apache-tomcat-6.0.13
2、安装jsvc
shell>cd /usr/local/tomcat6/bin
shell>tar xvfz jsvc.tar.gz
shell>cd jsvc-src
shell>sh support/buildconf.sh
如果成功,命令终端打印出下面report:
support/buildconf.sh: configure script generated successfully
[注:在此之前,我的系统安装了autoconf,可以使用shell>sudo apt-get install autoconf 进行安装]
为configure添加执行权限
shell>chmod 755 configure
shell> ./configure -with-java=/usr/lib/j2sdk1.6-sun (这是俺系统的JDK安装的位置)
shell>make
okay!如果没有出现错误的话,jsvc就安装成功了!
3、设置启动脚本
接下来,就是把jsvc中带有的一个tomcat5.sh的一个模板复制到/etc/init.d目录下,然后根据自己的情况,进行修改。
shell>cp /usr/local/tomcat6/bin/jsvc-src/native/Tomcat5.sh /etc/init.d/tomcat
上面的命令是移动文件tomcat5.sh到/etc/init.d/里面并改名为tomcat
修改/etc/init.d/tomcat文件:
shell>vi /etc/init.d/tomcat
俺的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/lib/j2sdk1.6-sun
CATALINA_HOME=/usr/local/tomcat6
DAEMON_HOME=/usr/local/tomcat6/bin
TOMCAT_USER=tomcat
# 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
之后用update-rc.d 修改一下运行级别。