在 Linux 系统中,关闭服务(service)的命令取决于你使用的初始化系统(init system)。以下是不同初始化系统的服务关闭方法:
# 停止服务(立即关闭)
sudo systemctl stop <服务名>
# 禁止开机自启(永久关闭)
sudo systemctl disable <服务名>
# 查看服务状态
sudo systemctl status <服务名>
示例:关闭 Nginx 服务
sudo systemctl stop nginx
sudo systemctl disable nginx
# 停止服务
sudo service <服务名> stop
# 或直接调用 init 脚本
sudo /etc/init.d/<服务名> stop
# 禁止开机自启(需使用工具如 chkconfig)
sudo chkconfig <服务名> off
示例:关闭 Apache
sudo service httpd stop
sudo chkconfig httpd off
# 停止服务
sudo stop <服务名>
sudo
或 root 权限。systemctl list-unit-files
(Systemd)或 service --status-all
(SysVinit)查看所有服务。kill
或 pkill
强制结束进程(不推荐优先使用):
bash
pkill -9 <进程名>
systemctl list-units --type=service
确认。journalctl -u <服务名>
)。根据你的系统版本选择合适的命令即可。