Tomcat to Linux Service
--------------------Software Environment
· CentOS6.6 64bit
· Apche-Tomcat-8.0
--------------------Operation Steps
[1] Download Tomcat-7
URL:http://tomcat.apache.org/download-70.cgi
Tips:此处仅介绍关于Tomcat7配置Linux Service的部分,Tomcat的基础配置请参阅《Tomcat安装与配置》
[2] Configure Tomcat-7
[root@localhost ~]cd /tomcat7
[root@localhost tomcat7]cd /bin
[root@localhost bin]cp catalina.sh /etc/init.d
[root@localhost tomcat7]cd /etc/init.d
[root@localhost init.d]pwd
/etc/init.d
[root@localhost init.d]mv catalina.sh tomcat
[root@localhost init.d]vi tomcat
--------------------
在#!/bin/bash下输入
# chkconfig: 2345 10 90
# description:Tomcat service
在#OS specific support................上输入
CATALINA_HOME=/tomcat7
JAVA_HOME=/usr/java/jdk1.6.0_10
保存并退出文件
--------------------
[root@localhost init.d]chmod +x tomcat
[root@localhost init.d]cd /
[root@localhost /]vi /etc/profile
--------------------
在最后一行输入
#CATALINA_HOME
CATALINA_HOME=/tomcat7
export CATALINA_HOME
保存并退出文件
--------------------
[root@localhost /]source /etc/profile
[3] Add tomcat to service list
[root@localhost /]chkconfig --add tomcat
[4] Check service list
[root@localhost /]chkconfig --list tomcat
tomcat0:关闭1:关闭2:启用3:启用 4:启用 5:启用 6:关闭
[5] Test tomcat service
[root@localhost /]service tomcat
--------------------
Using CATALINA_BASE: /tomcat7
Using CATALINA_HOME: /tomcat7
Using CATALINA_TMPDIR: /tomcat7/temp
Using JRE_HOME: /usr/java/jdk1.6.0_10
Using CLASSPATH: /tomcat7/bin/bootstrap.jar:/tomcat7/bin/tomcat-juli.jar
Usage: catalina.sh ( commands ... )
.
.
.
.
.
--------------------
[6] Start tomcat service
[root@localhost /]service tomcat start
[7] OK!
以下这种方式也可以:
新建 /etc/init.d/tomcat_8785 chmod 755 /etc/init.d/tomcat_8785
#!/bin/sh
# chkconfig: 2345 10 90
# description: Tomcat service
CATALINA_HOME=/usr/tomcat/8.0.30-8785
JAVA_HOME=/usr/jdk/jdk1.8.0_45
export CATALINA_HOME
export JAVA_HOME
if [ $# != 1 ]; then
echo "Usage: $0 start|stop|restart"
exit 1
fi
if [ $1 = "start" ]; then
/usr/tomcat/8.0.30-8785/bin/startup.sh
elif [ $1 = "stop" ]; then
/usr/tomcat/8.0.30-8785/bin/shutdown.sh
elif [ $1 = "restart" ]; then
/usr/tomcat/8.0.30-8785/bin/shutdown.sh
sleep 5
/usr/tomcat/8.0.30-8785/bin/startup.sh
fi
sleep 5
chkconfig --add tomcat_8785