管理 SysV init 服务在各运行级别的自启动状态。
chkconfig 是 RHEL/CentOS 系的 SysV 服务管理工具,通过修改 /etc/rc.d/rcN.d/ 下的 S/K 符号链接,控制服务在运行级别 0 到 6 是否启动。--list 查看状态,--add/--del 注册或移除脚本,--level 指定级别。
RHEL 7 起系统改用 systemd,chkconfig 主要保留给旧 init 脚本兼容;原生 systemd 服务要用 systemctl enable、disable 和 is-enabled。两者管理的不是同一套状态:chkconfig 改 SysV 链接,systemctl 改 unit 的 wants 链接。
# 查看所有 SysV 服务及运行级别
chkconfig --list
# 让 sshd 在 2/3/4/5 级别开机启动
sudo chkconfig --level 2345 sshd on
# 注册新的 init 脚本
sudo chkconfig --add myapp
--add 报 "No such file or directory":脚本不在 /etc/init.d/、不可执行,或缺少 # chkconfig: 与 # description: 头;注册后用 chkconfig --list myapp 复核。chkconfig --list 看不到 nginx 等服务:它只列 SysV 脚本,用 systemctl list-unit-files --type=service 查原生 unit。systemctl status 和 systemctl is-enabled 交叉确认。update-rc.d,不要把 RHEL 用法直接照搬。合上页面,先回答,再展开对照。
chkconfig 与 systemctl 管理的是同一套状态吗?chkconfig --list 看不到 nginx,是什么原因?chkconfig --add 报 “No such file or directory” 的常见原因有哪些?rcN.d 链接,systemctl 修改 unit 的 wants 链接。systemctl list-unit-files --type=service 查看。/etc/init.d/、不可执行,或缺少 # chkconfig: 与 # description: 头。
小程序版
微信扫码,随时查命令