第一步:
vim /lib/systemd/system/tomcat.service
[Unit] Description=tomcat After=network.target [Service] Type=oneshot ExecStart=/mnt/app/tomcat-zhidu/bin/startup.sh //自已的tomcat目錄 ExecStop=/mnt/app/tomcat-zhidu/bin/shutdown.sh ExecReload=/bin/kill -s HUP $MAINPID RemainAfterExit=yes [Install] WantedBy=multi-user.target
(2).設置權限
chmod 754 tomcat.service
(3).啟動關閉服務,設置開機啟動
#啟動服務 systemctl start tomcat.service #關閉服務 systemctl stop tomcat.service #開機啟動 systemctl enable tomcat.service