当给一个服务设置开机自启动时,就是在对应级别的脚本下面创建一个软链接,链接的名字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
# description:
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
服务器托管网机房租用,北京机房租用,IDC机房托管, http://www.fwqtg.net
相关推荐: 【AI新趋势期刊#1】GPT自动理解视频、AI法律顾问、大模型安全围栏
每天都要浏览大量AI相关新闻,是不是感到信息量爆炸,有效信息少? 这么多新产品和新工具,到底哪些是真正是有价值的,哪些只是浮躁的一时热点? 想参与AI产品和工具的开发,从哪里能够获得大量的灵感和思路? 我会把AI相关的新趋势、新想法、新思路,和成熟AI产品、工…