通过jsvc将tomcat6添加到linux服务

时间:2022-02-02 19:14:54
1.安装jsvc
http://archive.apache.org/dist/tomcat/tomcat-6/v6.0.16/bin/apache-tomcat-6.0.16.tar.gz
解压出来,上传一个jsvc.tar.gz


#cd /usr/local/apache-tomcat-6.0/bin
#tar xvfz jsvc.tar.gz
#cd jsvc-src
#sh support/buildconf.sh
#chmod 755 configure
#./configure --with-java=/usr/local/java/jdk1.6.0 (改成你的JDK的位置)
#make


2、添加脚本让tomcat自动启动
添加用户,-s /sbin/nologin,虚拟用户禁止登陆
#/usr/sbin/useradd -d /opt/beinan -s /sbin/nologin tomcat
添加组
#/usr/sbin/groupadd tomcat
把tomcat加入www组
#/usr/sbin/usermod -G www www
设置用户www对tomcat的权限
#chown -R www /usr/local/apache-tomcat-6.0
移动文件Tomcat5.sh到/etc/init.d/里面并改名为tomcat
#cp apache-tomcat-6.0/bin/jsvc-src/native/Tomcat5.sh /etc/init.d/tomcat


#chmod +x /etc/init.d/tomcat
#vi /etc/init.d/tomcat


我的配置如下
#!/bin/sh
# tomcat
# Startup Script for Tomcat
#
# chkconfig: 345 88 14
# description: Tomcat Daemon
# processname: jsvc
# pidfile: /var/run/jsvc.pid
#
prog=tomcat
#
JAVA_HOME=/usr/local/java/jdk1.6.0
DAEMON_HOME=/usr/local/tomcat/bin
CATALINA_HOME=/usr/local/tomcat
TOMCAT_USER=tomcat




# for multi instances adapt those lines.
TMP_DIR=/var/tmp
PID_FILE=/var/run/jsvc.pid
CATALINA_BASE=/usr/local/tomcat
JAVA_OPTS="-XX:PermSize=64M -XX:MaxPermSize=128M -Xms1G -Xmx1G"
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
     #
     echo "Starting $prog"
     $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 $JAVA_OPTS $CATALINA_OPTS -cp $CLASSPATH org.apache.catalina.startup.Bootstrap -debug
     exit $?
     ;;




   stop)
     #
     # Stop Tomcat
     #
      echo "Stopping $prog"
     $DAEMON_HOME/jsvc-src/jsvc -stop -pidfile $PID_FILE org.apache.catalina.startup.Bootstrap
     exit $?
     ;;




   *)
     echo "Usage tomcat.sh start/stop"
     exit 1
     ;;
esac
测试tomcat能不能启动
#/sbin/service tomcat start
测试tomcat能不能停止
#/sbin/service tomcat stop


剩下的就是和其他service一样的
加入服务
#/sbin/chkconfig --add tomcat
启动级别
#/sbin/chkconfig --level 345 tomcat on
查看一下
#/sbin/chkconfig --list tomcat