chkconfig [--add|--del|--list] [服務名]
chkconfig [--level <等級代號>] [服務名] [on|off|reset]
| 參數 | 說明 |
|---|---|
--add | 將服務納入 chkconfig 管理,在對應 rc.d 目錄建立啟動/關閉符號連結 |
--del | 移除服務管理,刪除所有 rc.d 符號連結 |
--list | 列出所有服務在各運行等級的啟動狀態 |
--level | 指定運行等級(0-6),如 --level 35 表示等級 3 和 5 |
chkconfig --list # 所有服務
chkconfig --list | grep 3:on # 僅顯示等級3啟動的服務
chkconfig --list sshd # 單一服務
chkconfig --add mysql # 納入管理,預設開啟 2345
chkconfig --level 35 mysql on # 明確指定 3、5 等級開啟
chkconfig --level 01246 mysql off # 其他等級關閉
chkconfig --del ip6tables
chkconfig --level 5 nfsserver off
chkconfig --level 35 nfsserver off
#!/bin/bash
# check.sh
chkconfig network && echo "Network service is configured"
chkconfig junk && echo "Junk service is configured"
# 指定等級檢測
chkconfig network --level 3 && echo "Network configured for runlevel 3"
S##name:啟動腳本(Start),數字越小越早執行。K##name:關閉腳本(Kill),數字越小越早執行。chkconfig --add 會在對應 rc.d 建立 S/K 連結;--del 則刪除。# 範例:xinetd 在等級 3、5 啟動
ls -l /etc/rc.d/rc3.d/ | grep xinetd
# lrwxrwxrwx 1 root root 12 Jun 18 00:52 K08xinetd -> ../init.d/xinetd
# lrwxrwxrwx 1 root root 12 Jun 18 00:52 S14xinetd -> ../init.d/xinetd
RHEL 7+/CentOS 7+ 採用 systemd,chkconfig 實為 systemctl enable/disable 的相容包裝。建議直接使用:
systemctl enable sshd # 等同 chkconfig sshd on
systemctl disable sshd # 等同 chkconfig sshd off
systemctl list-unit-files # 等同 chkconfig --list
chkconfig --list 輸出納入資產管理系統。chkconfig --list <服務> 確認生效。