Linux chkconfig命令教程和示例

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命令套件提供了更多详细的功能。 可以从以下链接访问相关教程。

Linux Systemctl Tutorial

Linux 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 onkeyword 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 offkeyword 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
LEARN MORE  How Change Run Levels In Linux?
了解更多信息如何更改Linux中的运行级别?

翻译自: https://www.poftut.com/linux-chkconfig-command-tutorial-examples/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值