比如说tomcat
一、先判断:是 systemd 还是 init.d 方式?
- 检查是否为 systemd 服务(现代 CentOS 7/8/9)
systemctl list-unit-files | grep -i tomcat
如果出现 tomcat.service、tomcat8.service 之类 → systemd 管理
如果什么都没出 → 不是 systemd,往下查 init.d
- 检查是否为传统 /etc/init.d 脚本(老方式)
ls /etc/init.d/ | grep -i tomcat
如果看到 tomcat / tomcat8 → init.d 脚本方式
再看自启状态:
chkconfig --list tomcat
输出类似:
tomcat 0:off 1:off 2:on 3:on 4:on 5:on 6:off
2/3/5 为 on → 开机自启已开启
- 检查是否写在 /etc/rc.local(最粗暴方式)
cat /etc/rc.local | grep -i tomcat
如果有 /opt/tomcat8/bin/startup.sh 之类 → rc.local 自启
二、对应方式:关闭开机自启(永久)
- 情况 A:systemd 服务(最常见)
- 1)查看服务名与状态
systemctl status tomcat
看 Loaded: 那一行是否 enabled。
- 2)关闭开机自启(关键命令)
bash
systemctl disable tomcat
提示:Removed symlink /etc/systemd/system/… → 成功
- 3)验证
systemctl is-enabled tomcat
输出 disabled → 已关闭
- 情况 B:/etc/init.d 脚本(chkconfig 方式)
- 1)关闭开机自启
chkconfig tomcat off
- 2)验证
chkconfig --list tomcat
2:off 3:off 5:off → 成功
- 3)(可选)彻底删除服务
chkconfig --del tomcat
rm -f /etc/init.d/tomcat
- 情况 C:写在 /etc/rc.local
vi /etc/rc.local
找到类似:
/opt/tomcat8/bin/startup.sh
注释掉(加 #)或删除这一行,保存退出。
4万+

被折叠的 条评论
为什么被折叠?



