概述
CentOS7开始,从/etc/init.d脚本改为了systemctl管理服务。今天主要记录一下怎么把tomcat8加入systemd管理的步骤。
以下基于centos7.3进行测试验证。
1、首先,需要为tomcat配置pid。
# cd /home/tomcat8090/bin# ls
编辑 catalina.sh脚本文件
# vim catalina.sh

添加 CATALINA_PID=”/var/run/tomcat.pid”,如上图
2、创建tomcat.service文件
# vim /usr/lib/systemd/system/tomcat.service
[Unit]Description=TomcatAfter=syslog.target network.target remote-fs.target nss-lookup.target[Service]Type=forkingEnvironment="JAVA_HOME=/usr/local/jdk"PIDFile=/home/tomcat8090/tomcat.pidExecStart=/home/tomcat8090/bin/startup.shExecReload=/bin/kill -s HUP $MAINPIDExecStop=/bin/kill -s QUIT $MAINPIDPrivateTmp=true[Install]WantedBy=multi-user.target
3、设置为开机启动
# systemctl enable tomcat.service
4.修改tomcat.service文件后需要执行下面命令使其生效:
# systemctl daemon-reload
5、维护命令
启动tomcat服务
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
后面会分享更多devops和DBA方面的内容,感兴趣的朋友可以关注下~