jsvc将tomcat配置成服务

1、在/usr/share/tomcat6/bin中有commons-daemon-native.tar.gz  压缩包
2、解压commons-daemon-native.tar.gz
# tar -zxvf commons-daemon-native.tar.gz
3、解压完成,出现commons-daemon-1.0.2-native-src文件夹(目录)
4、  执行configure 文件
cd commons-daemon-1.0.2-native-src/unix
./configure
5、  编译
[root@localhost ~]# make   #会报错
[root@localhost ~]# make clean
[root@localhost ~]# make    #重新编译成功
6、 编译完成后出现jsvc文件夹,复制jsvc到/usr/share/tomcat6/bin目录下面
[root@localhost ~]# cp jsvc ../../
10、在/etc/init.d/目录下编写tomcat6启动服务配置文件。
[root@localhost ~]#cd /etc/init.d/
[root@localhost ~]# vi tomcat6

#!/bin/sh
# tomcat: Start/Stop/Restart tomcat
#
# chkconfig: 2345 85 15
# description: Apache tomcat6

# Small shell script to show how to start/stop Tomcat using jsvc

JAVA_HOME=/usr/java/jdk1.6.0  #根据自己的实际jdk位置来修改

CATALINA_HOME=/usr/local/tomcat        #根据自己实际tomcat位置来修改
DAEMON_HOME=$CATALINA_HOME/bin
# I did not use the user.
TOMCAT_USER=tomcat

# for multi instances adapt those lines.
TMP_DIR=$CATALINA_HOME/tmp
PID_FILE=$DAEMON_HOME/jsvc.pid
CATALINA_BASE=$CATALINA_HOME
. /etc/rc.d/init.d/functions
CATALINA_OPTS=
CLASSPATH=\
$JAVA_HOME/lib/tools.jar:\
$CATALINA_HOME/bin/commons-daemon.jar:\
$CATALINA_HOME/bin/bootstrap.jar

start() {
    echo -n $"Starting Tomcat6: "
    # If you want to specify a user to run Tomcat.
    #increase the 'user $ TOMCAT_USER \' to the parameter list.
    $DAEMON_HOME/jsvc \
    -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
   echo "*****************************[ok]"
}

stop() {
    echo -n $"Stopping Tomcat6: "
    #
    $DAEMON_HOME/jsvc \
    -stop \
    -pidfile $PID_FILE \
    org.apache.catalina.startup.Bootstrap
   echo "*****************************[ok]"
}

status() {
     ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap" | awk '{printf $1 " "}' | wc | awk '{print $2}' >/tmp/tomcat_process_count.txt
     read line < /tmp/tomcat_process_count.txt
     if [ $line -gt 0 ]; then
       echo -n "tomcat6 ( pid "
       ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap" | awk '{printf $1 " "}'
       echo ") is running                             "
     else
       echo "Tomcat6 is stopped"
     fi
}

case "$1" in
  start)
    # Start Tomcat
    start
    exit $?
    ;;

  stop)
    # Stop Tomcat
    stop
    exit $?
    ;;
  restart)
    # Restart Tomcat
    stop
    sleep 3
    start
    exit $?
    ;;
   status)
    status
    exit $?
    ;;
  *)
    echo "Usage: tomcat6 {start|stop|restart|status}"
    exit 1;;
esac

#####

####


11、录入完成,按Esc键。输入: wq保存退出并赋予/etc/init.d/tomcat6文件可执行权限
[root@localhost~]# chmod 777 /etc/init.d/tomcat6
------------------添加服务-----------------------------------------
12、[root@localhost~] #chkconfig --add tomcat6          ##添加tomcat服务
13、[root@localhost~] #chkconfig –list |grep tomcat6      ##查看tomcat服务是否被添加
--------------------启动服务---------------------------------------------
14、[root@localhost~] # service tomcat6 start            ##启动tomcat服务
15、[root@localhost~] # service tomcat6 stop            ##停止tomcat服务
16、[root@localhost~] # service tomcat6 restart          ##重启tomcat
17、[root@localhost~] # service tomcat6 status           ##查看tomcat服务启动状态
然后给普通用户tomcat的权限,就可以了。

你可能感兴趣的:(tomcat)