在CentOS Minimal中,禁用服务可以通过以下几种方法实现:
systemctl命令查看所有服务:
systemctl list-units --type=service
禁用特定服务:
systemctl disable 服务名
例如,要禁用httpd服务:
systemctl disable httpd
禁用多个服务: 可以一次性禁用多个服务,用空格分隔服务名:
systemctl disable 服务1 服务2 服务3
禁用所有启动时自动启动的服务:
systemctl disable --now $(systemctl list-unit-files --type=service --state=enabled | awk '{print $1}')
/etc/systemd/system.conf文件打开配置文件:
sudo vi /etc/systemd/system.conf
找到并修改DefaultStartup行:
将DefaultStartup的值改为lazy或manual,以减少开机自启服务的数量。
DefaultStartup=lazy
保存并退出编辑器。
重新加载systemd配置:
sudo systemctl daemon-reload
chkconfig命令(适用于CentOS 6及更早版本)查看所有服务:
chkconfig --list
禁用特定服务:
chkconfig 服务名 off
例如,要禁用httpd服务:
chkconfig httpd off
enable命令。通过以上方法,你可以有效地管理CentOS Minimal系统中的服务,减少不必要的资源消耗。