Linux设置tomcat开机自启
一、创建 tomcat 服务配置文件
vim /etc/init.d/tomcat
添加以下内容
注:JAVA_HOME
、CATALINA_HOME
改成自己本地对应的路径
#!/bin/bash
# description: Tomcat Start Stop Restart
# processname: tomcat
# chkconfig: 2345 20 80
#idea - tomcat config start
#!/bin/bash
# description: Tomcat Start Stop Restart
# processname: tomcat
# chkconfig: 2345 20 80
JAVA_HOME=/home/data/jdk1.8.0_211
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
CATALINA_HOME=/home/data/tomcat-9.0.40-8088
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
#chmod 755 tomcat
#chkconfig --add tomcat
#chkconfig --level 2345 tomcat on
二、给文件授权
chmod +x /etc/init.d/tomcat
三、添加到服务列表
chkconfig --add /etc/init.d/tomcat
四、查看服务列表
chkconfig --list
[root@arcgis bin]# chkconfig --list
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
tomcat 0:off 1:off 2:on 3:on 4:on 5:on 6:off
2,3,4,5都是开表示随系统而启动
五、启动 tomcat命令
service tomcat start