Unix中init的工作__处女篇博客

来源:互联网 发布:迅雷赚钱宝 监控软件 编辑:程序博客网 时间:2024/04/28 00:35

        来CSDN一年多两年了,也是我工作年龄,哈哈~~每天都会来逛,现在,终于想到要写博客了。主要是自己比较懒,哈哈~~因为有些东西自己总是重复去网上查,还是写自己的博客好,可以经常查看,也能帮助下其他人。

       最近系统学习linux各个方面,主要是系统管理和网络编程。

===================================================================================================================================

       在开机时,首先进行内核引导,哗啦哗啦的信息一滚而过,想要再次看看?可以。不过,这个信息接近300行,可以重定向到一个文件再去看看。

       dmesg > startup_info.txt

       注意了,dmesg查看的引导信息是最近一次开机的,重新开机会被重置。而Soralis则相反。

       好了,引导完了,到init进程上场了。学过Linux的都知道,和Unix一样,所有进程的老大都是init进程,它负责所有核心系统功能的有序启动(和关闭),而且,它还为进程赋予权限。我们可以控制Linux在内核启动后,进入哪一个运行级别。

        我用的是Red Hat Enterprise 5版本,用命令看看inittab下是什么内容:< cat -n /etc/inittab >

     1  #     2  # inittab       This file describes how the INIT process should set up     3  #               the system in a certain run-level.     4  #     5  # Author:       Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>     6  #               Modified for RHS Linux by Marc Ewing and Donnie Barnes     7  #     8     9  # Default runlevel. The runlevels used by RHS are:    10  #   0 - halt (Do NOT set initdefault to this)    11  #   1 - Single user mode    12  #   2 - Multiuser, without NFS (The same as 3, if you do not have networking)    13  #   3 - Full multiuser mode    14  #   4 - unused    15  #   5 - X11    16  #   6 - reboot (Do NOT set initdefault to this)    17  #    18  id:3:initdefault:    19    20  # System initialization.    21  si::sysinit:/etc/rc.d/rc.sysinit    22    23  l0:0:wait:/etc/rc.d/rc 0    24  l1:1:wait:/etc/rc.d/rc 1    25  l2:2:wait:/etc/rc.d/rc 2    26  l3:3:wait:/etc/rc.d/rc 3    27  l4:4:wait:/etc/rc.d/rc 4    28  l5:5:wait:/etc/rc.d/rc 5    29  l6:6:wait:/etc/rc.d/rc 6    30    31  # Trap CTRL-ALT-DELETE    32  ca::ctrlaltdel:/sbin/shutdown -t3 -r now    33    34  # When our UPS tells us power has failed, assume we have a few minutes    35  # of power left.  Schedule a shutdown for 2 minutes from now.    36  # This does, of course, assume you have powerd installed and your    37  # UPS connected and working correctly.    38  pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down"    39    40  # If power was restored before the shutdown kicked in, cancel it.    41  pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"    42    43    44  # Run gettys in standard runlevels    45  1:2345:respawn:/sbin/mingetty tty1    46  2:2345:respawn:/sbin/mingetty tty2    47  3:2345:respawn:/sbin/mingetty tty3    48  4:2345:respawn:/sbin/mingetty tty4    49  5:2345:respawn:/sbin/mingetty tty5    50  6:2345:respawn:/sbin/mingetty tty6    51    52  # Run xdm in runlevel 5    53  x:5:respawn:/etc/X11/prefdm -nodaemon

        可以看到,有7种启动模式可以选择,但是,正如注释所说,第0和6种不要设为默认启动运行级别。这里我设的是第三级别,进入命令行模式的完全多用户模式,我之所以这样设置,是因为懒得在vmware下切换鼠标,启动linux后,就不管它了,然后我用的windows下的ssh软件去登录操作,这样更方便学习。

        在23到29行,分别有对应各种不同启动模式的启动脚本,对于系统管理员可以去看看里面的脚本,里面配置了进入对应级别启动和禁止的服务等。

        我们试着进入这个目录看看:cd /etc/rc.d/rc3.d ,然后看看里面有什么:ll

lrwxrwxrwx 1 root root 24 Jul 22 22:13 K02avahi-dnsconfd -> ../init.d/avahi-dnsconfdlrwxrwxrwx 1 root root 16 Jul 22 22:13 K02dhcdbd -> ../init.d/dhcdbdlrwxrwxrwx 1 root root 24 Jul 22 22:15 K02NetworkManager -> ../init.d/NetworkManagerlrwxrwxrwx 1 root root 34 Jul 22 22:15 K02NetworkManagerDispatcher -> ../init.d/NetworkManagerDispatcherlrwxrwxrwx 1 root root 16 Jul 22 22:14 K05conman -> ../init.d/conmanlrwxrwxrwx 1 root root 19 Jul 22 22:13 K05saslauthd -> ../init.d/saslauthdlrwxrwxrwx 1 root root 19 Jul 22 22:16 K10dc_server -> ../init.d/dc_serverlrwxrwxrwx 1 root root 16 Jul 22 22:14 K10psacct -> ../init.d/psacctlrwxrwxrwx 1 root root 19 Jul 22 22:16 K12dc_client -> ../init.d/dc_clientlrwxrwxrwx 1 root root 15 Jul 22 22:16 K15httpd -> ../init.d/httpdlrwxrwxrwx 1 root root 13 Jul 22 22:14 K20nfs -> ../init.d/nfslrwxrwxrwx 1 root root 15 Jul 22 22:15 K20rwhod -> ../init.d/rwhodlrwxrwxrwx 1 root root 14 Jul 22 22:14 K24irda -> ../init.d/irdalrwxrwxrwx 1 root root 15 Jul 22 22:16 K25squid -> ../init.d/squidlrwxrwxrwx 1 root root 13 Jul 22 22:16 K35smb -> ../init.d/smblrwxrwxrwx 1 root root 19 Jul 22 22:18 K35vncserver -> ../init.d/vncserverlrwxrwxrwx 1 root root 17 Jul 22 22:20 K35winbind -> ../init.d/winbindlrwxrwxrwx 1 root root 16 Jul 22 22:16 K36mysqld -> ../init.d/mysqldlrwxrwxrwx 1 root root 20 Jul 22 22:13 K50netconsole -> ../init.d/netconsolelrwxrwxrwx 1 root root 13 Jul 22 22:16 K50tux -> ../init.d/tux................................................................ lrwxrwxrwx 1 root root 16 Jul 22 22:14 S28autofs -> ../init.d/autofslrwxrwxrwx 1 root root 15 Jul 22 22:14 S44acpid -> ../init.d/acpidlrwxrwxrwx 1 root root 15 Jul 22 22:14 S50hplip -> ../init.d/hpliplrwxrwxrwx 1 root root 14 Jul 22 22:14 S55sshd -> ../init.d/sshdlrwxrwxrwx 1 root root 14 Jul 22 22:13 S56cups -> ../init.d/cupslrwxrwxrwx 1 root root 16 Jul 22 22:16 S56xinetd -> ../init.d/xinetdlrwxrwxrwx 1 root root 18 Jul 22 22:13 S80sendmail -> ../init.d/sendmaillrwxrwxrwx 1 root root 13 Jul 22 22:12 S85gpm -> ../init.d/gpmlrwxrwxrwx 1 root root 15 Jul 22 22:13 S90crond -> ../init.d/crondlrwxrwxrwx 1 root root 13 Jul 22 22:18 S90xfs -> ../init.d/xfslrwxrwxrwx 1 root root 17 Jul 22 22:12 S95anacron -> ../init.d/anacronlrwxrwxrwx 1 root root 13 Jul 22 22:13 S95atd -> ../init.d/atdlrwxrwxrwx 1 root root 15 Jul 22 22:15 S97rhnsd -> ../init.d/rhnsdlrwxrwxrwx 1 root root 22 Jul 22 22:14 S97yum-updatesd -> ../init.d/yum-updatesdlrwxrwxrwx 1 root root 22 Jul 22 22:13 S98avahi-daemon -> ../init.d/avahi-daemonlrwxrwxrwx 1 root root 19 Jul 22 22:15 S98haldaemon -> ../init.d/haldaemonlrwxrwxrwx 1 root root 19 Jul 22 22:15 S99firstboot -> ../init.d/firstbootlrwxrwxrwx 1 root root 11 Jul 22 22:13 S99local -> ../rc.locallrwxrwxrwx 1 root root 16 Jul 22 22:15 S99smartd -> ../init.d/smartd
        可以看到,开头文件主要有“K”和“S”两种,下面说明其作用:

        Start with "K":同进程相关的脚本在进入指定的运行模式时候终止,以stop参数调用

        Start with "S":同进程相关的脚本在进入指定的运行模式时候终止,以start参数调用

         注意到,它们都是链接文件,为什么这么做呢?假如我们不小心删除了rc.d目录下的文件,在init.d目录下的文件还在,这样可以避免误操作。因此,假如我们自己创建运行shell脚本的话,也应该首先在init.d目录下写好shell脚本,再在rc.d对应运行级别上创建链接文件。

       

0 0