<p>chkconfig是专为SysV init设计的服务管理工具,适用于CentOS 6及更早版本,通过修改/etc/rc[0-6].d/符号链接控制运行级别自启,服务脚本须置于/etc/init.d/且含# chkconfig: 2345 90 10等标准注释,常用命令包括--list、--add、--level和on/off,修改后需重启或切换运行级别生效。</p>

chkconfig 是专为 SysV init 系统设计的服务管理工具,主要适用于 CentOS 6、RHEL 6 及更早版本。它不直接启动或停止服务,而是通过修改 /etc/rc[0-6].d/ 目录下的符号链接,来控制服务在不同运行级别(runlevel)是否自启。
服务脚本需满足前提条件
要被 chkconfig 管理,服务脚本必须放在 /etc/init.d/ 目录下,并且开头包含标准的 chkconfig 注释块,格式如下:
# chkconfig: 2345 90 10
# description: My custom service
# processname: myapp
其中:
• 2345 表示默认启用的运行级别(2:无网络多用户;3:有网络命令行;4:未使用;5:图形界面)
• 90 是启动优先级(数字越小越早启动)
• 10 是停止优先级(数字越小越早停止)
常用操作命令
• 查看所有服务当前各运行级别的启停状态:
chkconfig --list
• 查看指定服务(如 nginx)的配置:
chkconfig --list nginx
• 将服务加入 chkconfig 管理列表(首次添加必需):
chkconfig --add nginx
• 启用服务在默认级别(2345)开机自启:
chkconfig nginx on
• 精确控制在运行级别 3 和 5 自启:
chkconfig --level 35 nginx on
• 禁用自启:
chkconfig nginx off
• 从 chkconfig 管理中彻底移除(同时删除所有 rc?.d 下的链接):
chkconfig --del nginx
注意事项与常见问题
• chkconfig 修改后不会立即生效,需重启系统或切换运行级别才能触发;若想立刻运行服务,需单独执行 service nginx start 或 /etc/init.d/nginx start
• 运行级别 0(关机)、1(单用户)、6(重启)通常不设自启,避免意外行为
• 在 systemd 系统(如 CentOS 7+)中运行 chkconfig,默认会重定向到 systemctl;如需强制操作传统符号链接,加 --no-redirect 参数
• 若执行 chkconfig --add 报错 “service xxx does not support chkconfig”,说明脚本缺少正确注释头或权限不足(确保 /etc/init.d/xxx 具备可执行权限:chmod +x)


















