列出运行级别中定义的服务

要显示所有服务,我们只需执行命令chkconfigchkconfig --list即可显示服务的当前状态及其与相关运行级别的关系:

john@john-desktop:~$ chkconfig ntop
ntop  on
john@john-desktop:~$ chkconfig --list ntop
ntop                      0:off  1:off  2:on   3:on   4:on   5:on   6:off

在基于Red Hat和基于SUSE的系统下,默认情况下会收到详细的输出。

john@john-desktop:~$ chkconfig --list
acpi-support              0:off  1:off  2:on   3:on   4:on   5:on   6:off
acpid                     0:off  1:off  2:off  3:off  4:off  5:off  6:off
alsa-restore              0:off  1:off  2:off  3:off  4:off  5:off  6:off
alsa-store                0:off  1:off  2:off  3:off  4:off  5:off  6:off
anacron                   0:off  1:off  2:off  3:off  4:off  5:off  6:off
apparmor                  0:off  1:off  2:off  3:off  4:off  5:off  6:off  S:on 
apport                    0:off  1:off  2:off  3:off  4:off  5:off  6:off

要列出特定的运行级别,我们可以将同一命令与grep结合使用:

john@john-desktop:~$ chkconfig --list | grep 3:on
acpi-support              0:off  1:off  2:on   3:on   4:on   5:on   6:off
atop                      0:off  1:off  2:on   3:on   4:on   5:on   6:off
dns-clean                 0:off  1:on   2:on   3:on   4:on   5:on   6:off
grub-common               0:off  1:off  2:on   3:on   4:on   5:on   6:off
kerneloops                0:off  1:off  2:on   3:on   4:on   5:on   6:off

开启和关闭服务

root@john-desktop:~# chkconfig --list | grep ntop
ntop                      0:off  1:off  2:on   3:on   4:on   5:on   6:off

root@john-desktop:~# chkconfig --level 2345 ntop off

root@john-desktop:~# chkconfig --list | grep ntop
ntop                      0:off  1:off  2:off  3:off  4:off  5:off  6:off

root@john-desktop:~# chkconfig --level 2345 ntop on

root@john-desktop:~# chkconfig --list | grep ntop
ntop                      0:off  1:off  2:on   3:on   4:on   5:on   6:off

在此示例中,首先查看了服务ntop通常以什么运行级别启动。
然后执行chkconfig --level 2345 ntop off,禁用ntop。

在Linux系统上管理服务

chkconfig

chkconfig命令是一个受欢迎的软件包,可以安装该软件包,该软件包允许您启用或禁用系统服务。chkconfig允许您轻松地操纵在某些运行级别下启动的服务。本身不带附加参数的命令将导致显示任何已知服务及其当前状态和运行级别。在运行级别中配置的任何服务的状态均为。在运行级别中未配置的所有服务的状态均为关闭

chkconfig是基于Red Hat的系统和SUSE系统的标准配置。

chkconfig命令

添加和删​​除服务

chkconfig也可以用于在运行级别中添加和删除服务。(在安装服务后才能添加)

# chkconfig --del ntop

# chkconfig --add ntop
日期:2019-04-29 03:17:31 来源:oir作者:oir