将tomcat添加至服务,并使其自启动
- 在/etc/init.d/目录下创建tomcat文件
2.将以下内容粘贴到文件,注意修改JAVA_HOME和CATALANA_HOME(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=tomcat8
JAVA_HOME=/usr/local/java/jdk1.8.0_211
export JAVA_HOME
CATALANA_HOME=/usr/local/dbzbpt/apache-tomcat-7.0.94/
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
3.更改权限
chmod 755 tomcat
4.启动服务
service tomcat start
5.添加开机启动
chkconfig tomcat on
6.OK了