- Tomcat下載下傳位址
連結:https://pan.baidu.com/s/14Wbdigg0OoNxkWm-EENnrA 提取碼:9357
- 首先,為tomcat配置pid,在bin/catalina.sh中,修改為一下:
# Copy CATALINA_BASE from CATALINA_HOME if not already set
[ -z "$CATALINA_BASE" ] && CATALINA_BASE="$CATALINA_HOME"
# 設定pid。一定要加在CATALINA_BASE定義後面,要不然pid會生成到/下面
CATALINA_PID="$CATALINA_BASE/tomcat.pid"
- 建立tomcat.service檔案
vi /lib/systemd/system/tomcat.service
内容如下:
[Unit]
Description=Tomcat
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
Environment="JAVA_HOME=/usr/local/java/jdk1.8.0_172"
PIDFile=/opt/apache-tomcat-8.0.36/tomcat.pid
ExecStart=/opt/apache-tomcat-8.0.36/bin/startup.sh
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
- 設定為開機啟動
systemctl enable tomcat.service
- 其他
修改tomcat.service檔案後需要執行下面指令使其生效:
systemctl daemon-reload
啟動nginx服務
systemctl start tomcat.service
設定開機自啟動
systemctl enable tomcat.service
停止開機自啟動
systemctl disable tomcat.service
檢視服務目前狀态
systemctl status tomcat.service
重新啟動服務
systemctl restart tomcat.service
檢視所有已啟動的服務
systemctl list-units --type=service