现在的位置: 首页 > 综合 > 正文

JSVC的配置与使用详解

2013年06月24日 ⁄ 综合 ⁄ 共 2942字 ⁄ 字号 评论关闭
JSVC是apache出的所谓common daemon的一个工具套件,他利用一个daemon程序,从而使tomcat这样的程序能在开机的时候自动启动,而且能使tomcat被 chkconfig这样的工具所管理。在之前的一篇文章中对jsvc有详细的说明和介绍,这里不再赘述了。 

JSVC download下来是源码版本,需要自己编译,编译很简单,如下(假设我们已经解开包,位于jsvc源码的根目录下): 

1、sh support/buildconf.sh # 生成configure脚本 

2、./configure # 要求JAVA_HOME已经正确设置,如未设置JAVA_HOME,那么,要这样: 

./configure --with-java=/usr/java/j2sdk1.4.2_09 

3、make # jsvc可执行文件生成完毕 

OK, jsvc已经得到了,然后,我们可以利用jsvc自带的一个脚本来将tomcat放到启动中去,首先: 

cp native/Tomcat.sh /etc/init.d 

然后修改这个Tomcat.sh(主要是修改一些路径配置),这里有个修改好的版本(这个版本tomcat装在/opt/tomcat-4.1.31下,jdk在/usr/java/j2sdk1.4.2_09下): 

CODE: SELECT ALL
#!/bin/sh
#
# chkconfig:35 98 98
# description: start/stop tomcat automatically
#
##############################################################################
#
#   Copyright 2001-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:
#
#    <!-- 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"/>
#
# This is for of Tomcat-4.1.x (Apache Tomcat/4.1)
#
# Adapt the following lines to your configuration
JAVA_HOME=/usr/java/j2sdk1.4.2_09
JAVA_OPTS="-server"
export JAVA_OPTS
CATALINA_HOME=/opt/tomcat-4.1.31
DAEMON_HOME=/opt/tomcat-4.1.31
TOMCAT_USER=root
TMP_DIR=/opt/tomcat-4.1.31/temp
CATALINA_OPTS=
CLASSPATH=\
$JAVA_HOME/lib/tools.jar:\
$DAEMON_HOME/bin/commons-daemon.jar:\
$CATALINA_HOME/bin/bootstrap.jar

case "$1" in
  start)
    #
    # Start Tomcat
    #
    /opt/software/jsvc-src/jsvc \
    -user $TOMCAT_USER \
    -home $JAVA_HOME \
    -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.BootstrapService
    #
    # To get a verbose JVM
    #-verbose \
    # To get a debug of jsvc.
    #-debug \
    ;;

  stop)
    #
    # Stop Tomcat
    #
    PID=`cat /var/run/jsvc.pid`
    kill $PID
    ;;

  *)
    echo "Usage tomcat.sh start/stop"
    exit 1;;
esac



上述配置中,common-daemon.jar和bootstap.jar在tomcat的各版本中路径可能不一样,请按照具体情况自己配置,这里是 tomcat 4.1.31的版本。如果是tomcat5,那么请在jsvc根目录下native/Tomcat5.sh的基础上进行改动。 

此外,路径一定不能配错,比如,TMP_DIR一行,这应该配成tomcat根目录下的temp目录,有时习惯就写成tmp目录了,这是不可以的,tomcat启动的时候会出错的。 

OK了,最后我们将Tomcat.sh改个名字,改个权限,就可以加到chkconfig里面去了: 

mv Tomcat.sh tomcat 

chmod 755 tomcat 

chkconfig --add tomcat 

最后重启一下机器吧,看tomcat是不是在启动的时候已经起来了?

抱歉!评论已关闭.