Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

用 chkconfig 檢視與切換 Linux 服務狀態

在 SysV init 體系下,chkconfig 是管理服務開機自啟與執行等級的標準工具。以下整理它的參數與等級含義。

參數用法

[root@ndnp /]# chkconfig --help
chkconfig version 1.3.49.3 - Copyright (C) 1997-2000 Red Hat, Inc.
usage: chkconfig [--list] [--type <type>] [name]

chkconfig --add <name>       增加系統服務
chkconfig --del <name>       刪除服務
chkconfig --override <name>  覆寫服務設定
chkconfig [--level <levels>] <name> <on|off|reset|resetpriorities>

執行等級代號

  • 0:關機
  • 1:單使用者模式
  • 2:無網路連線的多使用者命令列模式
  • 3:有網路連線的多使用者命令列模式
  • 4:保留未使用
  • 5:帶圖形介面的多使用者模式
  • 6:重新啟動

檢視所有服務

[root@ndnp /]# 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
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
atd            0:off 1:off 2:off 3:on 4:on 5:on 6:off

切換服務狀態示例

修改前:

iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off

於等級 2、3、4、5 關閉:

[root@ndnp /]# chkconfig --level 2345 iptables off

修改後:

[root@ndnp /]# chkconfig --list | grep iptables
iptables 0:off 1:off 2:off 3:off 4:off 5:off 6:off

補充:在 systemd 取代 SysV init 的版本上,這類需求通常改用 systemctl enable/disable 處理。

Copyright © Linux教程網 All Rights Reserved