2022-11-24 356
前言
本文主要给大家介绍了关于systemctl管理Tomcat启动、停止、重启及开机启动的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧。
1. 创建服务
用service来管理服务的时候,是在/etc/init.d/目录中创建一个脚本文件,来管理服务的启动和停止,在systemctl中,也类似,文件目录有所不同,在/lib/systemd/system目录下创建一个脚本文件tomcat,里面的内容如下:
[Unit]
Description=Tomcat
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/tomcat/pid
ExecStart=/usr/local/tomcat/bin/catalina.sh start
ExecReload=/usr/local/tomcat/bin/catalina.sh restart
ExecStop=/usr/local/tomcat/bin/catalina.sh stop
[Install]
WantedBy=multi-user.target
[Unit] 表示这是基础信息
[Service] 表示这里是服务信息
[Install] 表示这是是安装相关信息
tomcat的bin/catalina.sh中加入CATALINA_PID参数时,需要在# OS specific support.上加入
CATALINA_PID=/usr/local/tomcat/pid
# OS specific support. $var _must_ be set to either true or false.
cygwin=false
....略..
2. 创建软链接
创建软链接是为了下一步系统初始化时自动启动服务
ln -s /lib/systemd/system/tomcat.service /etc/systemd/system/multi-user.target.wants/tomcat.service
创建软链接就好比Windows下的快捷方式
ln -s 是创建软链接
ln -s 原文件 目标文件(快捷方式的决定地址)
如果创建软连接的时候出现异常,不要担心,看看/etc/systemd/system/multi-user.target.wants/ 目录是否正常创建软链接为准,有时候报错只是提示一下,其实成功了。
$ ll /etc/systemd/system/multi-user.target.wants/
total 8
drwxr-xr-x 2 root root 4096 Mar 30 15:46 ./
drwxr-xr-x 13 root root 4096 Mar 13 14:18 ../
lrwxrwxrwx 1 root root 31 Nov 23 14:43 tomcat.service -> /lib/systemd/system/tomcat.service
...略...
3. 刷新配置
刚刚配置的服务需要让systemctl能识别,就必须刷新配置
$ systemctl daemon-reload
如果没有权限可以使用sudo
$ sudo systemctl daemon-reload
4. 启动、重启、停止
启动tomcat
$ systemctl start tomcat
重启tomcat
$ systemctl restart tomcat
停止tomcat
$ systemctl stop tomcat
5. 开机自启动
tomcat服务加入开机启动
$ systemctl enable tomcat
禁止开机启动
$ systemctl disable tomcat
6. 查看状态
查看状态
$ systemctl status tomcat
总结
以上所述是小编给大家介绍的利用systemctl管理Tomcat启动、停止、重启及开机启动详解,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对77isp云服务器技术网的支持!
原文链接:https://77isp.com/post/16090.html
=========================================
https://77isp.com/ 为 “云服务器技术网” 唯一官方服务平台,请勿相信其他任何渠道。
数据库技术 2022-03-28
网站技术 2022-11-26
网站技术 2023-01-07
网站技术 2022-11-17
Windows相关 2022-02-23
网站技术 2023-01-14
Windows相关 2022-02-16
Windows相关 2022-02-16
Linux相关 2022-02-27
数据库技术 2022-02-20
抠敌 2023年10月23日
嚼餐 2023年10月23日
男忌 2023年10月22日
瓮仆 2023年10月22日
簿偌 2023年10月22日
扫码二维码
获取最新动态