网站搜索

Linux 中的 5 个基本 chkconfig 命令示例


这是我们正在进行的 Linux 命令系列,我们将回顾如何通过其可用参数有效地使用 chkconfig 命令。 Chkconfig命令工具允许通过命令行在/etc/rd.d/init.d脚本中配置服务自动启动和停止。让我们看一些例子。

1. 列出所有服务

使用“-list”参数将显示每个运行级别配置中的所有服务及其当前启动状态。

[root@tecmint ~]# chkconfig --list

NetworkManager  0:off   1:off   2:on    3:on    4:on    5:on    6:off
abrt-ccpp       0:off   1:off   2:off   3:on    4:off   5:on    6:off
abrt-oops       0:off   1:off   2:off   3:on    4:off   5:on    6:off
...

2. 查看特定服务的状态

以下命令显示特定服务的启动配置。它显示 HTTP 服务在所有运行级别中都关闭

[root@tecmint ~]# chkconfig --list | grep httpd
httpd           0:off   1:off   2:off   3:off   4:off   5:off   6:off

3. 如何在运行级别启动特定服务

以下“chkconfig”命令显示了我们如何仅在运行级别 35 上启动 HTTP 服务: –级别'参数。第一个命令在运行级别 35 上启动 httpd 服务,第二个命令验证运行级别 httpd 服务的状态运行级别。

[root@tecmint ~]# chkconfig --level 35 httpd on
[root@tecmint ~]# chkconfig --list | grep httpd
httpd           0:off   1:off   2:off   3:on    4:off   5:on    6:off

4. 如何查看哪些服务已开启/关闭

以下命令将显示特定运行级别5开启关闭的所有服务。

[root@tecmint ~]# chkconfig --list | grep 5:on
NetworkManager  0:off   1:off   2:on    3:on    4:on    5:on    6:off
abrt-ccpp       0:off   1:off   2:off   3:on    4:off   5:on    6:off
abrt-oops       0:off   1:off   2:off   3:on    4:off   5:on    6:off
abrtd           0:off   1:off   2:off   3:on    4:off   5:on    6:off
acpid           0:off   1:off   2:on    3:on    4:on    5:on    6:off
...
[root@tecmint ~]# chkconfig --list | grep 5:off
dnsmasq         0:off   1:off   2:off   3:off   4:off   5:off   6:off
dovecot         0:off   1:off   2:off   3:off   4:off   5:off   6:off
firstboot       0:off   1:off   2:off   3:off   4:off   5:off   6:off
kdump           0:off   1:off   2:off   3:off   4:off   5:off   6:off
mysqld          0:off   1:off   2:off   3:off   4:off   5:off   6:off
netconsole      0:off   1:off   2:off   3:off   4:off   5:off   6:off
nfs             0:off   1:off   2:off   3:off   4:off   5:off   6:off
...

5. 如何在运行级别停止特定服务

以下命令将为单个运行级别关闭名为postfix的服务。同样,我们可以一次性在多个运行级别中关闭特定服务,如下所示。

[root@tecmint ~]# chkconfig --level 3 postfix off
[root@tecmint ~]# chkconfig --level 2345 postfix off

众所周知,Linux 操作系统有七个可用的运行级别。我们将在即将发表的文章中详细介绍不同运行级别和启动顺序的重要性。所以,请继续关注。