建立自启动脚本:
vim /etc/init.d/tomcat
输入如下内容:
#!/bin/bash # # tomcat startup script for the Tomcat server # # chkconfig: 345 80 20 # description: start the tomcat deamon # # Source function library . /etc/rc.d/init.d/functions #脚本名称 prog=tomcat #JDK安装目录 JAVA_HOME=/usr/jdk export JAVA_HOME #Tomcat安装目录 CATALANA_HOME=/usr/tomcat export CATALINA_HOME case "$1" in start) echo "Starting Tomcat..." $CATALANA_HOME/bin/startup.sh ;; stop) echo "Stopping Tomcat..." $CATALANA_HOME/bin/shutdown.sh ;; restart) echo "Stopping Tomcat..." $CATALANA_HOME/bin/shutdown.sh sleep 2 echo echo "Starting Tomcat..." $CATALANA_HOME/bin/startup.sh ;; *) echo "Usage: $prog {start|stop|restart}" ;; esac exit 0
chmod a+x tomcat
查看tomcat开机启动情况:
chkconfig --list
如没有,则添加到系统启动队列中:
chkconfig --add tomcat
重新检查tomcat开机启动情况,若成功,则应显示如下内容:
tomcat 0:off 1:off 2:on 3:on 4:on 5:on 6:off
使用下列命令对tomcat进行重启、停止、启动:
service tomcat restart/stop/start