根据tomcat官方的document说明,linux下设置开机自启动可以使用jsvc(tomcat包里自带)
设置tomcat以独立的用户运行(防止以root运行,权限太大) shell>sudo useradd -d /opt/tomcat -s /usr/sbin/nologin tomcat 上边的这个命令是添加一个系统用户tomcat,并且设置为不可登录系统。
设置用户tomcat 对tomcat6的访问权限 shell>sudo chown -R tomcat:website /opt/tomcat
安装jsvc,前提需要系统安装了gcc(系统一般默认安装),autoconf,libc6-dev 解压jsvc.tar.g shell>cd /opt/tomcat/bin
shell>sudo tar zxvf jsvc.tar.gz
准备编译配置文件 shell>cd jsvc-src shell>sudo sh support/buildconf.sh 如果成功,命令终端会打出: support/buildconf.sh: configure script generated successfully
为configure添加执行权限 shell>sudo chmod 755 configure
编译 shell>sudo ./configure –with-java=/usr/java/jdk1.6.0_10(java的安装路径) shell>sudo make 如果没有出现错误,jsvc就安装成功了。
设置启动脚本
修改/opt/tomcat/bin/jsvc-src/native/Tomcat5.sh 文件
# Adapt the following lines to your configuration
JAVA_HOME=/usr/java/jdk1.6.0_10
CATALINA_HOME=/opt/tomcat
DAEMON_HOME=/opt/tomcat/bin
TOMCAT_USER=tomcat# for multi instances adapt those lines.
TMP_DIR=/var/tmp
PID_FILE=/var/run/jsvc.pid
CATALINA_BASE=/opt/tomcatCATALINA_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/jsvc-src/jsvc \
-stop \
-pidfile $PID_FILE \
org.apache.catalina.startup.Bootstrap
exit $?
;;*)
echo “Usage tomcat.sh start/stop”
exit 1;;
esac拷贝jsvc带的tomcat5.sh 脚本拷贝到 /etc/init.d/ 下,并改名为tomcat
shell>sudo cp /opt/tomcat/bin/jsvc-src/native/Tomcat5.sh /etc/init.d/tomcat
设置 /etc/init.d/tomcat的可执行权限 Shell>sudo chmod 755 /etc/init.d/tomcat在/etc/rc2.d/下设置一个/etc/init.d/tomcat 的软链接 shell>cd /etc/rc2.d/ shell>sudo ln -s /etc/init.d/tomcat S16tomcat /etc/init.d/tomcat start ps aux|grep java 可以看到2个进程,一个是root,一个是tomcat 参考 http://wiki.ubuntu.org.cn/Tomcat6
No Responses (yet)
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.