Linux设置Tomcat服务开机启动

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/functions

elif [ -f /etc/rc.d/init.d/functions ]; then

. /etc/rc.d/init.d/functions

else

echo -e "\atomcat: unable to locate functions lib. Cannot continue."

exit -1

fi

RETVAL=$?

CATALINA_HOME="/usr/java/tomcat" #tomcat安装目录

case "$1" in

start)

if [ -f $CATALINA_HOME/bin/startup.sh ];

then

echo $"Starting Tomcat"

$CATALINA_HOME/bin/startup.sh

fi

;;

stop)

if [ -f $CATALINA_HOME/bin/shutdown.sh ];

then

echo $"Stopping Tomcat"

$CATALINA_HOME/bin/shutdown.sh

fi

;;

*)

echo $"Usage: $0 {start|stop}"

exit 1

;;

esac

exit $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/jdk
export CATALINA_HOME=/usr/java/tomcat
export CATALINA_BASE=/usr/java/tomcat
export CATALINA_TMPDIR=/usr/java/tomcat/temp

5、通过service启动服务

service tomcat start
service tomcat stop

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


你可能感兴趣的:(安装)