如何查看和停止Linux启动的服务

2025-02-28 00:16:34
推荐回答(1个)
回答1:

记住不同的linux发行版不一样.

redhat/centos 7 以前的. 你可以用 ntsysv 或是 setup来设置. 这个改的是这些服务在下次启动会不会自动启动.

如果服务器 inet/xinetd启动的. 需要改相应的配置.
如果是新的 redhat/centos 7 又变化很大. 它使用了 systemd来换掉了以前系统的 init,和脚本部分.

debian对应 ntsysv的命令有一个 rcconf可以看看.
下面我复制一下我看 redhat 7时的记录.
-------------------------
### 系统服务的 ntsysv里只剩几个了. 它是一个 systemd 的系统.现在看是要老命阿!
systemctl --all 显示所有的系统unit?(现在好像有 service,socket,slice,mount,path,scope,device)
systemctl status cupsd 查看unit 状态.

systemctl disable cups
rm '/etc/systemd/system/multi-user.target.wants/cups.path'
rm '/etc/systemd/system/sockets.target.wants/cups.socket'
rm '/etc/systemd/system/printer.target.wants/cups.service'

systemctl enable postfix
ln -s '/usr/lib/systemd/system/postfix.service' '/etc/systemd/system/multi-user.target.wants/postfix.service'
enable unit(自动启动)

systemctl start postfix 启服务
systemctl stop postfix 停服务

当想禁止系统里那些不用的进程时. 也许这个命令也会很有用处.
systemctl list-dependencies

看到这儿时我快哭了.我真的很想念ntsysv和 rcconf啥地.