chkconfig原理
  kCmFobNLwURY 2023年11月13日 18 0

当给一个服务设置开机自启动时,就是在对应级别的脚本下面创建一个软链接,链接的名字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原理_开机自启动

某个软件想通过chkconfig管理开机自启动,在/etc/init.d/路径下必须有可执行的启动文件,启动文件开头中必须有以下两行:

# chkconfig: 2345 55 25

# description:

chkconfig原理_启动文件_02


【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月13日 0

暂无评论

推荐阅读