跳到主要内容

Linux服务管理指令之chkconfig指令

  • 通过chkconfig可以给服务的各个运行级别设置自启动/关闭。
  • chkconfig指令管理的服务在 /etc/init.d查看。
  • 注意:在 Centos7.0Centos 7.0 以后,很多服务使用systemctl管理。

基本用法:

  • 查看服务: chkconfig --list
  • 设置服务在指定级别启动/关闭: chkconfig --level [服务名] [on/off]

示例:

[root@hxlinux init.d]# chkconfig --list

注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。

要列出 systemd 服务,请执行 'systemctl list-unit-files'
查看在具体 target 启用的服务请执行
'systemctl list-dependencies [target]'

netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关
network 0:关 1:关 2:开 3:开 4:开 5:开 6:关
vmware-tools 0:关 1:关 2:开 3:开 4:开 5:开 6:关
vmware-tools-thinprint 0:关 1:关 2:开 3:开 4:开 5:开 6:关
Shell

说明:

即, 服务network在 0 ~ 6 的Linux运行级别下的自启动状态如下:

[root@hxlinux init.d]# chkconfig --list | grep network

注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。

要列出 systemd 服务,请执行 'systemctl list-unit-files'
查看在具体 target 启用的服务请执行
'systemctl list-dependencies [target]'

network 0:关 1:关 2:开 3:开 4:开 5:开 6:关
Shell

案例: 对于network服务,进行各种操作,把network在3运行级别,关闭自启动。

[root@hxlinux init.d]# chkconfig --level 3 network off
[root@hxlinux init.d]# chkconfig --list | grep network

注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。

要列出 systemd 服务,请执行 'systemctl list-unit-files'
查看在具体 target 启用的服务请执行
'systemctl list-dependencies [target]'

network 0:关 1:关 2:开 3:关 4:开 5:开 6:关
[root@hxlinux init.d]# chkconfig --level 3 network on
Shell

注意:chkconfig重新设置服务自启动或者关闭,需要重启机器reboot生效。

请作者喝奶茶:
Alipay IconQR Code
Alipay IconQR Code
本文遵循 CC CC 4.0 BY-SA 版权协议, 转载请标明出处
Loading Comments...