天天看點

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