第一步:创建 service文件vim /lib/systemd/system/tomcat.service/lib 与 /usr/lib 我这里配置时是一样的,在那个文件夹配置都可以
第二步:编写 启动脚本[Unit]
Description=tomcat service
After=network.target
[Service]
Type=forking
ExecStart=/opt/apache-tomcat-8.5.59/bin/startup.sh
ExecStop=/opt/apache-tomcat-8.5.59/bin/shutdown.sh
PrivateTmp=true
[Install]
WantedBy=multi-user.target
查看编写好的脚本
脚本介绍
Description
服务描述
After
如果该字段指定的 Unit 也要启动,那么必须在当前 Unit 之前启动
Type=forking
后台运行
PIDFile=
.pid 文件需要在,tomcat配置文件中查找。如果查不多,不配置此属性也可以
如果type是后台运行,那么建议将此属性加上。指定pid。
ExecStart=/opt/apache-tomcat-8.5.59/bin/startup.sh
启动脚本
ExecReload=
重启脚本
ExecStop=/opt/apache-tomcat-8.5.59/bin/shutdown.sh
停止脚本
PrivateTmp=true
是否使用私有tmp目录
WantedBy=multi-user.target
运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3
第三步:保存退出,重新加载systemdsystemctl daemon-reload
重新加载,使 systemd生效
第四步:验证脚本# 查看服务状态systemctl status tomcat.service
# 停止服务systemctl stop tomcat.service
# 启动服务systemctl start tomcat.service
# 重启服务 不知道tomcat重启的命令
服务器重启后,查看tomcat服务状态
停止tomcat服务
第五步:配置开机自启#开启开机自启systemctl enable tomcat.service
#取消开机自启systemctl disable tomcat.service
Centos8 关于服务的命令服务的启动/停止/刷新配置文件/查看状态# systemctl start tomcat.service 启动nginx服务
# systemctl stop tomcat.service 停止服务
# systemctl restart tomcat.service 重新启动服务
# systemctl list-units --type=service 查看所有已启动的服务
# systemctl status tomcat.service 查看服务当前状态
# systemctl enable tomcat.service 设置开机自启动
# systemctl disable tomcat.service 停止开机自启动