# cd /etc/rc.d/rc5.d
# ls -al
total 8
drwxr-xr-x 2 root root 4096 Jul 15 09:29 .
drwxr-xr-x 10 root root 4096 Jun 21 08:52 ..
lrwxrwxrwx 1 root root 19 Jan 1 2000 K05saslauthd -> ../init.d/saslauthd
lrwxrwxrwx 1 root root 20 Feb 1 2003 K15postgresql -> ../init.d/postgresql
lrwxrwxrwx 1 root root 13 Jan 1 2000 K20nfs -> ../init.d/nfs
lrwxrwxrwx 1 root root 14 Jan 1 2000 K24irda -> ../init.d/irda
lrwxrwxrwx 1 root root 17 Jan 1 2000 K35winbind -> ../init.d/winbind
lrwxrwxrwx 1 root root 15 Jan 1 2000 K50snmpd -> ../init.d/snmpd
……
lrwxrwxrwx 1 root root 18 Feb 8 11:15 K92iptables -> ../init.d/iptables
lrwxrwxrwx 1 root root 19 Feb 1 2003 K95firstboot -> ../init.d/firstboot
lrwxrwxrwx 1 root root 15 Jan 1 2000 S05kudzu -> ../init.d/kudzu
lrwxrwxrwx 1 root root 14 Jun 21 08:55 S09isdn -> ../init.d/isdn
lrwxrwxrwx 1 root root 17 Jan 1 2000 S10network -> ../init.d/network
lrwxrwxrwx 1 root root 16 Jan 1 2000 S12syslog -> ../init.d/syslog
lrwxrwxrwx 1 root root 17 Jan 1 2000 S13portmap -> ../init.d/portmap
lrwxrwxrwx 1 root root 17 Jan 1 2000 S14nfslock -> ../init.d/nfslock
lrwxrwxrwx 1 root root 18 Jan 1 2000 S17keytable -> ../init.d/keytable
lrwxrwxrwx 1 root root 16 Jan 1 2000 S20random -> ../init.d/random
lrwxrwxrwx 1 root root 16 Jun 21 08:52 S24pcmcia -> ../init.d/pcmcia
lrwxrwxrwx 1 root root 15 Jan 1 2000 S25netfs -> ../init.d/netfs
lrwxrwxrwx 1 root root 14 Jan 1 2000 S26apmd -> ../init.d/apmd
lrwxrwxrwx 1 root root 16 Jan 1 2000 S28autofs -> ../init.d/autofs
lrwxrwxrwx 1 root root 14 Jan 1 2000 S55sshd -> ../init.d/sshd
lrwxrwxrwx 1 root root 20 Jan 1 2000 S56rawdevices -> ../init.d/rawdevices
lrwxrwxrwx 1 root root 16 Jan 1 2000 S56xinetd -> ../init.d/xinetd
lrwxrwxrwx 1 root root 14 Feb 1 2003 S58ntpd -> ../init.d/ntpd
lrwxrwxrwx 1 root root 13 Jun 21 10:42 S60afs -> ../init.d/afs
……
lrwxrwxrwx 1 root root 18 Jan 1 2000 S80sendmail -> ../init.d/sendmail
lrwxrwxrwx 1 root root 13 Jan 1 2000 S85gpm -> ../init.d/gpm
lrwxrwxrwx 1 root root 15 Mar 22 08:24 S85httpd -> ../init.d/httpd
……
lrwxrwxrwx 1 root root 14 Jul 15 09:29 S98wine -> ../init.d/wine
lrwxrwxrwx 1 root root 13 Feb 8 17:26 S99db2 -> ../init.d/db2
lrwxrwxrwx 1 root root 11 Jun 21 08:52 S99local -> ../rc.local |
如果用户想暂时终止某一runlevel的一项服务,只要删除相对应的链接就行了。然而,对链接进行手动设置是一项繁重而又易错的工作,但有一个十分有用的帮手,它的名字叫chkconfig。
分辨没被终止的服务
要想了解哪些服务没有被终止,那么用户需要运行/sbin/chkconfig -list命令。下面展示了命令执行后的显示结果,用户可以清楚地看到每一行有八项内容。chkconfig命令还可以用来开启或终止某一服务。
afs 0:off 1:off 2:off 3:on 4:off 5:on 6:off
anacron 0:off 1:off 2:on 3:on 4:on 5:on 6:off
apmd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
atd 0:off 1:off 2:off 3:on 4:on 5:on 6:off
autofs 0:off 1:off 2:off 3:on 4:on 5:on 6:off
crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off
……… |
上面左起第一列显示的是服务的名称,接下来的第二列显示的是所在的runlevel和当前状态。例如ntpd(网络时间无交互后台程序)服务被设定只在runlevel 3和runlevel 5开启,而sshd服务则在runlevel 2、3、4和5开启。也许用户会发现,在runlevel 0和runlevel 6没有启动的服务,是因为runlevel 0 和runlevel 6表示系统终止,当然没有服务了。
从属关系
正如上文提到的,系统启动时要逐一运行每个runlevel的服务。也许用户很容易想到,如果可以使多个服务同时运行,必然会节省大量的系统启动时间。但不幸的是这种方法行不通,原因是各项服务之间都存在着从属关系。传统的Linux系统并不能给用户指明服务间的从属关系。
现在通过一个简单的例子讲解如何明确服务间的从属关系。从ntpd服务需要一个网络基础可以得出结论——ntpd服务要依靠网络服务,这一关系可以用下面的语句表示:
用户可以确定netfs服务也要依靠网络服务,autofs服务也要依靠网络服务,现在就可以列出一个简单的从属关系表:
ntpd : network
netfs : network
autofs : network |
它的含义是一旦网络服务开启完毕,可以同时运行ntpd、netfs和autofs 服务。假设启动每项服务需要10秒的时间,用传统的方法启动上面的四项服务就需要40秒的时间,而使用上面提到的方法只需要20秒就够了。事实上,各项服务的启动时间是不同的,但道理是一样的。
再例如,lpd服务(S60lpd)要在网络服务后运行,但对于一个拥有喷墨打印机接口的家用系统而言,不必先建立网络连接再安装打印机。在这种情况下,更合理的状况应该是打印机服务先于网络服务。另外crond服务(S90crond)同样应该在网络服务后运行。但是,除非用户有可以使用远端计算机文件的cron文件,否则crond服务根本不必在网络服务前运行。
可以看出,有些服务要依靠其它服务才能运行,有些服务是完全独立的,它们运行与否与其它服务毫无关系。