如果我們使用war 包進行部署項目的時候,需要把包放進Tomcat的目錄下,為了使我們的服務能夠在服務器重啟的時候自動啟動起來,我們需要把Tomcat設置成自起服務。
配置 Tomcat 服務
新建服務腳本
1
|
[root@localhost ~] # vim /etc/init.d/tomcat |
添加腳本內容
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#!/bin/bash # description: Tomcat7 Start Stop Restart # processname: tomcat7 # chkconfig: 234 20 80 CATALINA_HOME= /usr/local/tomcat/apache-tomcat-7 .0.77 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 ;; *) echo 'please use : tomcat {start | stop | restart}' ;; esac exit 0 |
執行腳本,啟動、停止 和 重啟服務。
啟動:service tomcat start
停止:service tomcat stop
重啟:service tomcat restart
Tomcat 配置開機自啟動
向chkconfig添加 tomcat 服務的管理
1
|
[root@localhost ~] # chkconfig --add tomcat |
設置tomcat服務自啟動
1
|
[root@localhost ~] # chkconfig tomcat on |
查看tomcat的啟動狀態
1
|
[root@localhost ~] # chkconfig --list | grep tomcat |
狀態如下:
1
|
[root@localhost ~] # chkconfig –list | grep tomcat |
tomcat 0:off 1:off 2:on 3:on 4:on 5:on 6:off
關閉tomcat服務自啟動:
1
|
chkconfig tomcat off |
刪除tomcat服務在chkconfig上的管理:
1
|
chkconfig –del tomcat |
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:https://www.cnblogs.com/dowhile/p/pei-zhi-Tomcat-fu-wu-he-zi-qi-dong.html