CentOS/Linux 下设置 tomcat开机自启动
一、方式一
1.修改Tomcat目录下面的/bin/startup.sh文件:
export JAVA_HOME=/usr/local/JDK7
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:.
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:.
export PATH=$PATH:$JAVA_HOME/bin
export CATALINA_HOME=/usr/local/tomcat7_1
/usr/local/tomcat7_1/bin/catalina.sh start
/usr/local/tomcat7_1/bin/catalina.sh start
2.在/etc/rc.d/rc.local中加入:
/usr/local/tomcat7_1/bin/startup.sh
二、方式二
1.新建一个文件 vi tomcat
2.添加下面的命令
#!/bin/bash
#
# starguo [email protected]
# /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/local/tomcat7_1"
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
3.chmod 755 tomcat 添加可执行权限
#
# starguo [email protected]
# /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/local/tomcat7_1"
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
3.chmod 755 tomcat 添加可执行权限
4.cp tomcat /etc/init.d/tomcat
5. chkconfig --add tomcat
6.在tomcat目录下面的 bin/catalina.sh文件里面添加
export JAVA_HOME=/usr/local/JDK7
export CATALINA_HOME=/usr/local/tomcat7_1
export CATALINA_BASE=/usr/local/tomcat7_1
export CATALINA_TMPDIR=/usr/local/tomcat7_1/temp
export CATALINA_HOME=/usr/local/tomcat7_1
export CATALINA_BASE=/usr/local/tomcat7_1
export CATALINA_TMPDIR=/usr/local/tomcat7_1/temp
7.service tomcat start/stop