Chinaunix首页 | 论坛 | 博客
  • 博客访问: 101919455
  • 博文数量: 19283
  • 博客积分: 9968
  • 博客等级: 上将
  • 技术积分: 196062
  • 用 户 组: 普通用户
  • 注册时间: 2007-02-07 14:28
文章分类

全部博文(19283)

文章存档

2011年(1)

2009年(125)

2008年(19094)

2007年(63)

分类: LINUX

2008-05-04 13:53:21

 来源:赛迪网技术社区  作者:beiyue

动手改造

如果用户决定要启动Linux系统并进入图形模式(runlevel 5),那么当init引导rc指令程序运行并将runlevel的级数告知它时,rc指令程序将对/etc/rc.d/rc5.d/进行查看,接着它将执 行从该目录中找到所有链接。rc指令程序执行链接的过程可分为两部分,首先它将执行所有名称以“K”打头的链接,将“stop”参数传递给它们,并停止这 些链接指向的所有服务。这些服务停止后,rc指令程序将执行所有名称以“S”打头的链接,并将“start”参数传递给它们,启动这些链接所指向的服务。

另外,rc指令程序可以根据链接名称的两个十进制数,确定链接的执行顺序,数字小的先执行。

下面将举一个例子,帮助用户加深理解。当用户启动系统进入runlevel 5时,首先要执行的链接是K05saslauthd,由于它是以“K”打头的,而且后两位十进制数要小于其它以“K”打头的链接。第一个要执行的启动链接 是S05kudzu。最后执行的将是S99local。下面是runlevel 5状态下指向程序的链接。


  # 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表示系统终止,当然没有服务了。
阅读(337) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~