当给一个服务设置开机自启动时,就是在对应级别的脚本下面创建一个软链接,链接的名字S(启动)、K(关闭),数字是启动顺序,然后是服务名称,指向服务的位置;
当更改某级别启动状态时,chkconfig会自动将相对应的目录下(各启动级别目录)的软连接删除重新创建;
测试:
[root@CentOS6 ~]# chkconfig --list sshd
sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@CentOS6 ~]# ll /etc/rc.d/
total 60
drwxr-xr-x. 2 root root 4096 Jan 3 16:43 init.d
-rwxr-xr-x 1 root root 2617 Jun 20 2018 rc
drwxr-xr-x. 2 root root 4096 Jan 3 16:43 rc0.d
drwxr-xr-x. 2 root root 4096 Jan 3 16:43 rc1.d
drwxr-xr-x. 2 root root 4096 Jan 8 15:37 rc2.d
drwxr-xr-x. 2 root root 4096 Jan 8 15:37 rc3.d
drwxr-xr-x. 2 root root 4096 Jan 8 15:37 rc4.d
drwxr-xr-x. 2 root root 4096 Jan 8 15:37 rc5.d
drwxr-xr-x. 2 root root 4096 Jan 3 16:43 rc6.d
-rwxr-xr-x 1 root root 220 Jun 20 2018 rc.local
-rwxr-xr-x 1 root root 20199 Jun 20 2018 rc.sysinit
[root@CentOS6 ~]# ll /etc/rc.d/rc3.d/|grep sshd
lrwxrwxrwx 1 root root 14 Jan 8 15:37 S55sshd -> ../init.d/sshd
[root@CentOS6 ~]# chkconfig --level 3 sshd off
[root@CentOS6 ~]# chkconfig --list sshd
sshd 0:off 1:off 2:on 3:off 4:on 5:on 6:off
[root@CentOS6 ~]# ll /etc/rc.d/rc3.d/|grep sshd
lrwxrwxrwx 1 root root 14 Jan 8 15:55 K25sshd -> ../init.d/sshd
手动删除创建sshd 3级别启动状态软连接文件,查看chkconfig相对应启动级别状态
[root@CentOS6 ~]# chkconfig --list sshd
sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@CentOS6 ~]# ll /etc/rc.d/rc3.d/|grep sshd
lrwxrwxrwx 1 root root 14 Jan 8 16:00 S55sshd -> ../init.d/sshd
[root@CentOS6 ~]# cd /etc/rc.d/rc3.d/
[root@CentOS6 rc3.d]# rm -f S55sshd
[root@CentOS6 rc3.d]# ln -s /etc/init.d/sshd K25sshd
[root@CentOS6 rc3.d]# ll /etc/rc.d/rc3.d/|grep sshd
lrwxrwxrwx 1 root root 16 Jan 8 16:23 K25sshd -> /etc/init.d/sshd
[root@CentOS6 rc3.d]# chkconfig --list sshd
sshd 0:off 1:off 2:on 3:off 4:on 5:on 6:off
[root@CentOS6 rc3.d]# rm -f K25sshd
[root@CentOS6 rc3.d]# ln -s /etc/init.d/sshd S55sshd
[root@CentOS6 rc3.d]# ll /etc/rc.d/rc3.d/|grep sshd
lrwxrwxrwx 1 root root 16 Jan 8 16:24 S55sshd -> /etc/init.d/sshd
[root@CentOS6 rc3.d]# chkconfig --list sshd
sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
启动顺序数字是由服务启动文件控制的,例如:/etc/init.d/sshd
某个软件想通过chkconfig管理开机自启动,在/etc/init.d/路径下必须有可执行的启动文件,启动文件开头中必须有以下两行:
# chkconfig: 2345 55 25