Linux设置Tomcat服务开机启动

来源:互联网 发布:python控制继电器代码 编辑:程序博客网 时间:2024/06/05 17:48

1、生成启动脚本文件

vi /etc/rc.d/init.d/tomcat

文件内容:(记得修改标红的参数)

#!/bin/bash## /etc/rc.d/init.d/tomcat# init script for tomcat precesses## processname: tomcat# description: tomcat is a j2se server# chkconfig: 2345 86 16# description: Start up the Tomcat servlet engine.if [ -f /etc/init.d/functions ]; then. /etc/init.d/functionselif [ -f /etc/rc.d/init.d/functions ]; then. /etc/rc.d/init.d/functionselseecho -e "\atomcat: unable to locate functions lib. Cannot continue."exit -1fiRETVAL=$?CATALINA_HOME="/usr/java/tomcat" #tomcat安装目录case "$1" instart)if [ -f $CATALINA_HOME/bin/startup.sh ];thenecho $"Starting Tomcat"$CATALINA_HOME/bin/startup.shfi;;stop)if [ -f $CATALINA_HOME/bin/shutdown.sh ];thenecho $"Stopping Tomcat"$CATALINA_HOME/bin/shutdown.shfi;;*)echo $"Usage: $0 {start|stop}"exit 1;;esacexit $RETVAL

2、添加权限

chmod 755 /etc/rc.d/init.d/tomcat  #使得脚本文件可执行

3、运行:

chkconfig --add /etc/rc.d/init.d/tomcat #将其加到服务中

4、执行指令

vi /usr/java/tomcat/bin/catalina.sh

文件中加入以下语句:

export JAVA_HOME=/usr/java/jdkexport CATALINA_HOME=/usr/java/tomcatexport CATALINA_BASE=/usr/java/tomcatexport CATALINA_TMPDIR=/usr/java/tomcat/temp

5、通过service启动服务

service tomcat start
service tomcat stop

6、reboot重启服务器测试,成功!!


原创粉丝点击