centos设置tomat开机自启

1、将Tomcat安装为service以方便管理,并配置开机自启动
在/etc/init.d/目录下创建tomcat文件,并编辑
touch /etc/init.d/tomcat
vim /etc/init.d/tomcat
输入文件内容:(注意此处JAVA_HOME的路径,根据自己实际情况修改)
#!/bin/bash
#chkconfig: 2345 10 90
#description: tomcat service
JAVA_HOME=/usr/java/jdk1.8.0_171
PATH=$JAVA_HOME/bin:$PATH
CATALINA_HOME=/usr/local/apache-tomcat-7.0.91
export JAVA_HOME
export PATH
export CATALINA_HOME
case $1 in
start)
sh $CATALINA_HOME/bin/startup.sh
;;
stop)
sh $CATALINA_HOME/bin/shutdown.sh
;;
restart)
sh $CATALINA_HOME/bin/shutdown.sh
sh $CATALINA_HOME/bin/startup.sh
;;
esac
exit 0
2、将创建的/etc/init.d/tomcat文件添加权限,设置自启动
#增加tomcat服务控制脚本执行权限
chmod +x /etc/init.d/tomcat
#通过chkconfig命令将tomcat服务加入到自启动服务中
chkconfig --add tomcat
#开启自启动服务
chkconfig tomcat on
关闭chkconfig tomcat on
#查看是否添加成功
chkconfig --list tomcat

猜你喜欢

转载自www.cnblogs.com/foreverstudy/p/13187024.html