Linux services and daemons can be controlled with chkconfig
command. chkconfig
command is mainly used to set given service or daemon run level. In order to work with chkconfig
command we need root privileges. systemctl
command suite provides more and detailed features. Related tutorial can be accessed from following link.
可以使用chkconfig
命令控制Linux服务和守护程序。 chkconfig
命令主要用于设置给定服务或守护程序的运行级别。 为了使用chkconfig
命令,我们需要root特权。 systemctl
命令套件提供了更多详细的功能。 可以从以下链接访问相关教程。
列出所有现有服务和守护程序(List All Existing Service and Daemons)
We can use chkconfig
command in order to list all installed services and daemons like below. We will use --list
as option.
我们可以使用chkconfig
命令来列出所有已安装的服务和守护程序,如下所示。 我们将使用--list
作为选项。
$ chkconfig --list
列出特定的服务和守护程序 (List Specific Service and Daemon)
We can also list only specific service without listing all of them. There is two way for this first way is providing the service name with the --list
option. In this example we will list service named sshd
我们也可以只列出特定的服务,而不列出所有的服务。 第一种方式有两种方法,即为服务名称提供--list
选项。 在此示例中,我们将列出名为sshd
服务
$ chkconfig --list sshd
Second way is listing all services and daemons but filtering them with grep
command. We will provide the service name to the grep
command like below.
第二种方法是列出所有服务和守护程序,但使用grep
命令过滤它们。 我们将为grep
命令提供服务名称,如下所示。
$ chkconfig --list | grep sshd
启用服务 (Enable Service)
We can use chkconfig
command also enable services. Enabling services will make them to start automatically if specified run level activated. In this example we will enable sshd
service for run levels 2, 3, 4, 5 . We need root privileged for this command. We will use on
keyword after the service name.
我们可以使用chkconfig
命令还启用服务。 如果激活了指定的运行级别,启用服务将使它们自动启动。 在此示例中,我们将为运行级别sshd
启用sshd
服务。 我们需要对该命令具有root特权。 我们将在服务名称后使用on
关键字。
$ sudo chkconfig --level 2345 ssh on
禁用服务 (Disable Service)
We can also disable services and daemons for given run level. We will provide the off
keyword after the service name which is very similar to service enable. In this example we will disable the sshd
service for service level 2 .
我们还可以针对给定的运行级别禁用服务和守护程序。 我们将在服务名称后提供off
关键字,这与服务启用非常相似。 在此示例中,我们将为服务级别2禁用sshd
服务。
$ sudo chkconfig --level 2 ssh off
翻译自: https://www.poftut.com/linux-chkconfig-command-tutorial-examples/