0041-0043.html
来自「linux-unix130.linux.and.unix.ebooks130 l」· HTML 代码 · 共 355 行
HTML
355 行
<HTML>
<HEAD>
<TITLE>Developer.com - Online Reference Library - 0672311739:RED HAT LINUX 2ND EDITION:System Startup and Shutdown</TITLE>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!-- ISBN=0672311739 //-->
<!-- TITLE=RED HAT LINUX 2ND EDITION //-->
<!-- AUTHOR=DAVID PITTS ET AL //-->
<!-- PUBLISHER=MACMILLAN //-->
<!-- IMPRINT=SAMS PUBLISHING //-->
<!-- PUBLICATION DATE=1998 //-->
<!-- CHAPTER=04 //-->
<!-- PAGES=0037-0052 //-->
<!-- UNASSIGNED1 //-->
<!-- UNASSIGNED2 //-->
<P><CENTER>
<a href="0037-0040.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0044-0046.html">Next</A>
</CENTER></P>
<A NAME="PAGENUM-41"><P>Page 41</P></A>
<UL>
<LI> Clears the mounted filesystems table,
/etc/mtab
<LI> Enters the root filesystem into
mtab
<LI> Readies the system for loading modules
<LI> Finds module dependencies
<LI> Checks filesystems for possible repairs
<LI> Mounts all other filesystems
<LI> Cleans
out several /etc files: /etc/mtab, /etc/fastboot, /etc/nologin
<LI> Deletes UUCP lock files
<LI> Deletes stale subsystem files
<LI> Deletes stale
pid files
<LI> Sets the system
clock
<LI> Turns on swapping
<LI> Initializes the serial ports
<LI> Loads modules
</UL>
<P>Whew! That's a lot of work just for the first startup script! But it's just the first step in a
number of steps needed to start your system. So far, you've seen that after the Linux kernel is
loaded, the init command is run. After the
rc.sysinit is run by init, then init runs rc.local.
If you look at the Red Hat Linux rc.local script, you'll see that it gets the operating system
name and architecture of your computer and puts it into a file called
/etc/issue, which is later used for display at the login prompt.
</P>
<P>The next task of init is to run the scripts for each runlevel. If you look at the listing of the
rc.d directory, you'll see the various rcX.d directories, where
X is a number from 0 through 6. But if you look at the files under one of these directories, you'll find that each is merely a link to
a script under init.d, with an associated name for a particular service. For example,
under the rc3.d directory, you'll find
</P>
<!-- CODE //-->
<PRE>
lrwxrwxrwx 1 root root 17 Apr 10 09:11 S10network -> ../init.d/network*
lrwxrwxrwx 1 root root 16 Apr 10 09:18 S30syslog -> ../init.d/syslog*
lrwxrwxrwx 1 root root 19 Apr 10 09:22 S40cron -> ../init.d/cron.init*
lrwxrwxrwx 1 root root 22 Apr 10 09:17 S40portmap -> ../init.d/portmap.init*
lrwxrwxrwx 1 root root 16 Apr 10 09:16 S45pcmcia -> ../init.d/pcmcia*
lrwxrwxrwx 1 root root 14 Apr 10 09:04 S50inet -> ../init.d/inet*
lrwxrwxrwx 1 root root 20 Apr 10 09:06 S55named.init -> ../init.d/named.init*
lrwxrwxrwx 1 root root 18 Jul 15 11:56 S60lpd.init -> ../init.d/lpd.init*
lrwxrwxrwx 1 root root 13 Apr 10 09:16 S60nfs -> ../init.d/nfs*
lrwxrwxrwx 1 root root 15 Apr 10 09:11 S70nfsfs -> ../init.d/nfsfs*
lrwxrwxrwx 1 root root 18 Apr 10 09:11 S75keytable -> ../init.d/keytable*
lrwxrwxrwx 1 root root 23 Apr 10 09:18 S80sendmail -> ../init.d/sendmail.init*
lrwxrwxrwx 1 root root 13 Apr 10 09:10 S85gpm -> ../init.d/gpm*
lrwxrwxrwx 1 root root 11 Apr 10 09:11 S99local -> ../rc.local*
</PRE>
<!-- END CODE //-->
<P>Note the S in front of each name. This means to start a process or service. Now, if you look
at the files under rc0.d, you'll see
</P>
<A NAME="PAGENUM-42"><P>Page 42</P></A>
<!-- CODE //-->
<PRE>
lrwxrwxrwx 1 root root 18 Apr 10 09:06 K08amd ->../init.d/amd.init*
lrwxrwxrwx 1 root root 20 Apr 10 09:06 K10named.init -> ../init.d/named.init*
lrwxrwxrwx 1 root root 15 Apr 10 09:11 K10nfsfs -> ../init.d/nfsfs*
lrwxrwxrwx 1 root root 13 Apr 10 09:10 K15gpm -> ../init.d/gpm*
lrwxrwxrwx 1 root root 13 Apr 10 09:16 K20nfs -> ../init.d/nfs*
lrwxrwxrwx 1 root root 20 Apr 10 09:06 K25httpd -> ../init.d/httpd.init*
lrwxrwxrwx 1 root root 21 Apr 10 09:11 K25news -> /etc/rc.d/init.d/news*
lrwxrwxrwx 1 root root 23 Apr 10 09:18 K30sendmail -> ../init.d Âsendmail.init*
lrwxrwxrwx 1 root root 23 Apr 10 09:14 K32mars_nwe -> ../init.d/Âmars_nwe.init*
lrwxrwxrwx 1 root root 23 Apr 10 09:24 K33yppasswd -> ../init.d/Âyppasswd.init*
lrwxrwxrwx 1 root root 21 Apr 10 09:24 K35ypserv -> ../init.d/ypserv.init*
lrwxrwxrwx 1 root root 14 Apr 10 09:04 K50inet -> ../init.d/inet*
lrwxrwxrwx 1 root root 16 Apr 10 09:16 K52pcmcia -> ../init.d/pcmcia*
lrwxrwxrwx 1 root root 19 Apr 10 09:22 K60cron -> ../init.d/cron.init*
lrwxrwxrwx 1 root root 18 Jul 15 11:56 K60lpd.init -> ../init.d/lpd.init*
lrwxrwxrwx 1 root root 22 Apr 10 09:17 K65portmap -> ../init.d/portmap.init*
lrwxrwxrwx 1 root root 16 Apr 10 09:18 K70syslog -> ../init.d/syslog*
lrwxrwxrwx 1 root root 16 Apr 10 09:11 K80random -> ../init.d/random*
lrwxrwxrwx 1 root root 17 Apr 10 09:11 K99killall -> ../init.d/killall*
lrwxrwxrwx 1 root root 14 Apr 10 09:11 S00halt -> ../init.d/halt*
</PRE>
<!-- END CODE //-->
<P>Notice the K in front of each name. This means to kill a process or service. If you look
under each of the different rcX.d directories, you'll see what services or processes are started or
stopped in each runlevel. Later in this chapter I'll come back to some of the
rc.sysinit tasks because some of the error-checking done when starting up can help pinpoint problems with your
system. For now, however, the following sections explain the
different runlevels and what basically happens in each.
</P>
<H4><A NAME="ch04_ 7">
Runlevel 0: /etc/rc.d/rc0.d
</A></H4>
<P>As you can see from the previous directory listing, this runlevel starts the shutdown
sequence. Each script is run in the order listed. Some of the tasks run include
</P>
<UL>
<LI> Killing all processes
<LI> Turning off virtual memory file swapping
<LI> Unmounting swap and mounted filesystems
</UL>
<P>As shown in this section, and discussed later in this chapter, there are some important
things done during a shutdown involving your computer, its services, and its filesystems.
Although Linux is a robust operating system with system-checking safeguards, executing a proper
shutdown is essential to maintaining the integrity of your computer's hard drive as well
as any Linux volumes or partitions.
</P>
<H4><A NAME="ch04_ 8">
Runlevel 1: /etc/rc.d/rc1.d
</A></H4>
<P>This is the single-user mode, or administrative state, traditionally used by system
administrators, or sysadmins, while performing software maintenance. No one else can log in during
this mode, and networking is turned off, although filesystems are mounted.
</P>
<A NAME="PAGENUM-43"><P>Page 43</P></A>
<H4><A NAME="ch04_ 9">
Runlevel 2: /etc/rc.d/rc2.d
</A></H4>
<P>This is the multiuser state. Networking is enabled, although NFS is disabled.
</P>
<H4><A NAME="ch04_ 10">
Runlevel 3: /etc/rc.d/rc3.d
</A></H4>
<P>This is the default runlevel, which is specified as the first line in
/etc/inittab. Remote file sharing is enabled, along with all other desired services.
</P>
<H4><A NAME="ch04_ 11">
Runlevel 4: /etc/rc.d/rc4.d
</A></H4>
<P>This directory is empty. As in other versions of UNIX, if you want to define your own
runlevel, here's where you can add the appropriate links, with directions to selectively start or stop
processes.
</P>
<H4><A NAME="ch04_ 12">
Runlevel 5: /etc/rc.d/rc5.d
</A></H4>
<P>This runlevel is much the same as the default, with the exception of
named, the Internet domain nameserver. This is also the runlevel entered when running X11
under Linux.
</P>
<H4><A NAME="ch04_ 13">
Runlevel 6: /etc/rc.d/rc6.d
</A></H4>
<P>This is the reboot runlevel. The contents of this directory contain links similar
to those in runlevel 0, but logic in the halt script under
init.d determines whether or not the system is being
shutdown or rebooted.
</P>
<P>Keeping track of which process is started or stopped in which runlevel can be difficult. In
the next section, you'll see one more reason why using
Red Hat Linux can make your system administration tasks easier.
</P>
<H3><A NAME="ch04_ 14">
tksysv and Managing Your Services
</A></H3>
<P>One of the great things about Red Hat Linux is the number of tools included in the
distribution to help you manage your system. One such handy tool is Donnie Barnes's
tksysv, which can be called from a command line in a terminal window while you're running X, or
through the control-panel client. You should use it for a number of reasons.
</P>
<P>It is not only important to know how to properly shut down your system; you should also
know how to properly start and stop services under Linux while the system is running. Although
you can selectively "kill" processes with
</P>
<!-- CODE SNIP //-->
<PRE>
# kill -9 pid
</PRE>
<!-- END CODE SNIP //-->
<P>where pid is the number of the running process, this is a crude, ineffective, and
potentially harmful way to stop processes. Using the information you have learned so far, you can also
use the following approach (a handy tip from the
tksysv help dialog), for example, to stop the Web server,
httpd:
</P>
<!-- CODE SNIP //-->
<PRE>
# /etc/rc.d/init.d/httpd.init stop
</PRE>
<!-- END CODE SNIP //-->
<P><CENTER>
<a href="0037-0040.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0044-0046.html">Next</A>
</CENTER></P>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?