个人工具

“Quick HOWTO : Ch07 : The Linux Boot Process/zh”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
(新页面: {{Translation}} {{From|http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch07_:_The_Linux_Boot_Process}} {{Translator|yuanyelele}} {{Languages|Quick HOWTO : Ch07 : The Linux...)
 
总结
 
(未显示12个用户的98个中间版本)
第1行: 第1行:
{{Translation}}
+
{{Copyedit translation|from=http://wiki.ubuntu.org.cn/Quick_HOWTO_:_Ch07_:_The_Linux_Boot_Process}}
{{From|http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch07_:_The_Linux_Boot_Process}}
+
{{Translator|yuanyelele}}
+
{{Languages|Quick HOWTO : Ch07 : The Linux Boot Process}}
+
  
= Introduction =
+
{{From|http://wiki.ubuntu.org.cn/Quick_HOWTO_:_Ch07_:_The_Linux_Boot_Process}}
  
Learning how Linux boots up is critical. When you have this information you can use it to alter the type of login screen you get as well as which programs start up. Read on for the details.
+
{{Translator|yuanyelele mengqitao viquu ranfow}}
  
 +
{{Verifier|ranfow}}
  
= The Linux Boot Sequence =
+
{{Languages|Quick HOWTO : Ch07 : The Linux Boot Process}}
 +
= 简介 =  
 +
了解Linux如何启动很有用,之後您就可以改变登录界面的类型,或者自由选择启动时加载哪些程序。欢迎阅读下面的细节。
  
You might remember when you installed Linux that the installation process prompted you for a list of partitions and the sizes of each in which your filesystems would be placed.
+
= Linux启动顺序 =
  
When allocating disk space for the partitions, the first sector, or data unit, for each partition is always reserved for programmable code used in booting. The very first sector of the hard disk is reserved for the same purpose and is called the master boot record (MBR).
+
您或许还记得,当初安装Linux时,安装程序显示了一份硬盘分区的列表,包含各个分区的大小,您的文件系统将安装在这些分区上。
  
When booting from a hard disk, the PC system BIOS loads and executes the boot loader code in the MBR. The MBR then needs to know which partitions on the disk have boot loader code specific to their operating systems in their boot sectors and then attempts to boot one of them.
+
当为各个分区分配磁盘空间时,每个分区的第一个数据单元,或称之为“扇区”,总是预留给启动代码。整块硬盘的第一个扇区也用于同样的目的,该扇区被称作主引导记录(MBR)。
  
Fedora Linux is supplied with the GRUB boot loader which is fairly sophisticated and therefore cannot entirely fit in the 512 bytes of the MBR. The GRUB MBR boot loader merely searches for a special boot partition and loads a second stage boot loader. This then reads the data in the <code>/boot/grub/grub.conf</code> configuration file, which lists all the available operating systems and their booting parameters. When this is complete, the second stage boot loader then displays the familiar Fedora branded splash screen that lists all the configured operating system kernels for your choice.
+
当由硬盘启动PC时,BIOS被加载,之後运行MBR中的启动引导代码。MBR需要知道哪个分区的引导扇区中包含了操作系统的启动引导代码,之後MBR会试着启动其中的一个。
  
'''Note:''' In some operating systems, such as Debian / Ubuntu, the <code>/boot/grub/grub.conf</code> file may also be referred to by the name <code>/boot/grub/menu.lst</code>.
+
Fedora Linux发行版使用了非常复杂的GRUB启动引导程序,该程序无法放入MBR的512字节中。GRUB启动引导程序仅搜寻特定的启动分区,找到後加载第二阶段的启动引导程序。GRUB从包含各类操作系统和操作系统的启动参数的配置文件/boot/grub/grub.conf中读取启动配置数据。当GRUB启动引导程序完成後,第二阶段的启动引导程序在屏幕上显示有Fedora标记的所有你选择的操作系统核心配置。
  
Figure 7-1 shows a typical grub.conf file for a system that can boot both Fedora Linux and Windows 2000. This structure of this file is discussed in Chapter 33, "[[Quick HOWTO : Ch33 : Modifying the Kernel to Improve Performance|Modifying the Kernel to Improve Performance]]".
+
'''注意:''' 在一些操作系统中,如Debian / Ubuntu,配置文件 /boot/grub/grub.conf 可能会被下面的文件取代 /boot/grub/menu.lst
  
 +
图7-1显示了能够同时启动Fedora Linux和Windows 2000系统的一个典型grub.conf文件。配置文件的结构将在第33章讨论, "[[Quick HOWTO : Ch33 : Modifying the Kernel to Improve Performance/zh|Modifying the Kernel to Improve Performance]]"。
  
=== Figure 7-1 Sample grub.conf file ===
+
=== 7-1 grub.conf 文件示例 ===
 
+
 
  default=0
 
  default=0
 
  timeout=10
 
  timeout=10
第38行: 第38行:
  
  
When Linux begins to boot with its kernel, it first runs the /sbin/init program, which does some system checks, such as verifying the integrity of the file systems, and starts vital programs needed for the operating system to function properly. It then inspects the /etc/inittab file to determine Linux's overall mode of operation or runlevel. A listing of valid runlevels can be seen in Table 7-1.
+
当Linux开始启动内核时,首先运行/sbin/init脚本程序进行一些系统检查,如文件系统完整性的确认和操作系统正常运作的重要程序的启动。 Linux开始检测/etc/initab文件,并决定Linux的全部运行模式和运行级别。有效的运行级别列表见表7-1。
 
+
  
=== Table 7-1 Linux Runlevels ===
+
=== 7-1 Linux 运行级别 ===  
  
 
{| border="1" cellpadding="5" cellspacing="0"  
 
{| border="1" cellpadding="5" cellspacing="0"  
第49行: 第48行:
 
! style="background:#008000;color:white" | Run Level Description
 
! style="background:#008000;color:white" | Run Level Description
 
|-
 
|-
|0||/etc/rc.d/rc0.d||Halt
+
|0||/etc/rc.d/rc0.d||关机
 
|-
 
|-
|1||/etc/rc.d/rc1.d||Single-user mode
+
|1||/etc/rc.d/rc1.d||单用户模式
 
|-
 
|-
|2||/etc/rc.d/rc2.d||Not used (user-definable)
+
|2||/etc/rc.d/rc2.d||未使用,用户自定义
 
|-
 
|-
|3||/etc/rc.d/rc3.d||Full multi-user mode (no GUI interface)
+
|3||/etc/rc.d/rc3.d||多用户模式,无图形界面
 
|-
 
|-
|4||/etc/rc.d/rc4.d||Not used (user-definable)
+
|4||/etc/rc.d/rc4.d||未使用(用户定义)
 
|-
 
|-
|5||/etc/rc.d/rc5.d||Full multiuser mode (with GUI interface)
+
|5||/etc/rc.d/rc5.d||多用户模式(图形界面)
 
|-
 
|-
|6||/etc/rc.d/rc6.d||Reboot
+
|6||/etc/rc.d/rc6.d||重启
 
|-
 
|-
 
|}
 
|}
  
Based on the selected runlevel, the init process then executes startup scripts located in subdirectories of the <code>/etc/rc.d</code> directory. Scripts used for runlevels 0 to 6 are located in subdirectories <code>/etc/rc.d/rc0.d</code> through <code>/etc/rc.d/rc6.d</code>, respectively.
+
init程序依据选定的运行级别执行在子目录 <code>/etc/rc.d</code> 下的脚本程序.。运行级别0-6分别对应子目录中的 <code>/etc/rc.d/rc0.d</code> -<code>/etc/rc.d/rc6.d</code>
  
Here is a directory listing of the scripts in the <code>/etc/rc.d/rc3.d</code> directory:
+
以下是<code>/etc/rc.d/rc3.d</code>目录下的脚本文件列表
+
  
 
  [root@bigboy tmp]# ls /etc/rc.d/rc3.d
 
  [root@bigboy tmp]# ls /etc/rc.d/rc3.d
第79行: 第77行:
 
  [root@bigboy tmp]#
 
  [root@bigboy tmp]#
  
As you can see, each filename in these directories either starts with an "S" which signifies the script should be run at startup, or a K, which means the script should be run when the system is shutting down. If a script isn't there, it won't be run.
+
如上,你会发现,这些目录中的每个文件名要么是以“S”开头,以表明这些脚本是在系统启动的时候运行,或以“K”开头,表示这类脚本在系统正在关闭的时候被调用。如果一个脚本不在此目录,那么此脚本不会被运行。
  
Most Linux packages place their startup script in the <code>/etc/init.d</code> directory and place symbolic links (pointers) to this script in the appropriate subdirectory of <code>/etc/rc.d</code>. This makes file management a lot easier. The deletion of a link doesn't delete the file, which can then be used for another day.
+
大多数linux软件包将它们的启动脚本放在<code>/etc/init.d</code>目录下,相应的符号连接放在相应的<code>/etc/rc.d</code>子目录中。如此使得文件管理更为容易。比如说,删除文件的符号连接,而不会删除真实文件,这样以後你还可以使用它。
  
The number that follows the K or S specifies the position in which the scripts should be run in ascending order. In our example, <code>kudzu</code> with a value 05 will be started before <code>wlan</code> with a value of 09.
+
跟在K或者S後的数字按升序排列也就是这些脚本运行的次序。如,<code>kudzu</code>(後05)将比<code>wlan</code>(後09)先运行。幸运的是,你不必需要一个总的脚本,或者符号连接来保证所有脚本运行正常。因为Fedora中有一个名为<code>chkconfig</code>的组件,Debian/Ubuntu使用<code>update-rc.d</code>命令来帮你做所有的事情。我们等会在详细讲它。
Fortunately you don't have to be a scripting/symbolic linking guru to make sure everything works right because Fedora comes with a nifty utility called <code>chkconfig</code> while Debian / Ubuntu uses the <code>update-rc.d</code> command to do it all for you. This is explained later.
+
  
= Determining the Default Boot runlevel =
+
= 设置默认的启动级别 =
  
 +
系统默认启动级别在文件/etc/inittab,变量initdefault中设置。当被设置为3时,系统以文本模式启动;
  
The default boot runlevel is set in the file /etc/inittab with the initdefault variable. When set to 3, the system boots up with the text interface on the VGA console; when set to 5, you get the GUI. Here is a snippet of the file (delete the initdefault line you don't need):
+
当被设置为5时,系统将会以图形界面模式启动。这里是此文件的一部分(删除你不需要的initdefault行):
  
 
  # Default runlevel. The runlevels used by RHS are:
 
  # Default runlevel. The runlevels used by RHS are:
第102行: 第100行:
 
  id:3:initdefault:                        # Console Text Mode
 
  id:3:initdefault:                        # Console Text Mode
 
  id:5:initdefault:                        # Console GUI Mode
 
  id:5:initdefault:                        # Console GUI Mode
 
Note the following:
 
  
* Most home users boot up with a Windows like GUI (runlevel 5)
+
注意:
* Most techies will tend to boot up with a plain text-based command-line-type interface (runlevel 3)
+
* 大多数用户以如windows的图形界面启动(运行级别 5)
* Changing initdefault from 3 to 5, or vice-versa, has an effect upon your next reboot. See the following section on how to get a GUI login all the time until the next reboot.
+
* 大多数techies倾向于基于文本的命令行模式启动(运行级别 3)
* Of course, don't set the initdefault value to 6 or your system will constantly reboot. Setting it to 0 will never allow it to start!
+
* 将默认启动值从3改为5,或者反过来,对下次重启有影响。查看下列章节:如何设置始终图形界面登录直到下次重启。
 +
* 当然,不要设置默认启动值为6,否则你会不断重启;设置默认启动值0会导致永远开不了机。
  
 +
= 获取一个GUI控制界面 =
  
= Getting a GUI Console =
+
'''手动方法:''' 每次需要运行X终端GUI应用程序时,通过在VGA控制台模式下运行startx命令启动X终端。记住登出後你将再次返回到基于文本的控制台.
 
+
 
+
'''Manual Method:''' You can start the X terminal GUI application each time you need it by running the startx command at the VGA console. Remember that when you log out you will get the regular text-based console again.
+
  
 
  [root@bigboy tmp]# startx
 
  [root@bigboy tmp]# startx
  
'''Automatic Method:''' You can have Linux automatically start the X terminal GUI console for every login attempt until your next reboot by using the init command. You will need to edit your initdefault variable in your /etc/inittab file, as mentioned in the preceding section to keep this functionality even after you reboot.
+
'''自动方法:'''可以让Linux在每次登录时自动载入X终端GUI界面,除非用init命令重新启动系统。像在先前的文章中提到一样,为使系统重新启动后仍保持这些功能,你需要编辑/etc/inittab文件中的initdefault变量。
  
 
  [root@bigboy tmp]# init 5
 
  [root@bigboy tmp]# init 5
  
When the CPU capacity or available memory on your server is low or you want to maximize all system resources, you might want to operate in text mode runlevel 3 most of the time, using the GUI only as necessary with the startx command.
+
当你的机器的CPU性能或可用内存低的时候,或者你需要最大化利用你的资源,大部分时候你需要在runlevel 3文本模式下运行系统,必要时通过startx命令启动GUI。
 
+
Servers that double as personal workstations, or servers that might have to be operated for an extended period of time by relatively nontechnical staff, may need to be run at runlevel 5 all the time through the init 5 command. Remember you can make runlevel 5 permanent even after a reboot by editing the /etc/inittab file.
+
 
+
 
+
= Get a Basic Text Terminal Without Exiting the GUI =
+
 
+
There are a number of ways for you to get a command prompt when running a Linux GUI. This can be important if you need quick access to commands or you are not familiar with the GUI menu option layout.
+
 
+
=== Using a GUI Terminal Window ===
+
  
You can open a GUI-based window with a command prompt inside by doing the following:
+
无论是作为个人工作站还是服务器,机器可用要运行较长时间,非技术员工可能需要通过init 5命令让其一直运行在运行级别 5。记住,你能通过修改/etc/initab文件让系统一直运行在运行级别 5,即使是重新启动。
  
* Click on the Fedora logo button in the bottom left hand corner of the screen.
+
= 获取一个在GUI环境下的文本终端 =
* Click on Systems Tools and then Terminal
+
运行在Linux GUI环境中,有很多方法可以开启终端程序。当想要快速使用命令或者对GUI菜单选项不熟悉,这些方法很重要。
  
=== Using Virtual Consoles ===
+
=== 使用一个GUI终端窗口 ===  
  
By default, Linux runs six virtual console or TTY sessions running on the VGA console. These are defined by the mingetty statements in the /etc/inittab file. The X terminal GUI console creates its own virtual console using the first available TTY that is not controlled by mingetty. This makes the GUI run as number 7:
+
通过下面方法,开启一个基于GUI的终端窗口:
 +
* 点击屏幕左边底部的Fedora标志按钮。
 +
* 点击系统工具(System Tools),然後点击终端(Terminal)。
  
* You can step through each virtual console session by using the Ctl-Alt-F1 through F6 key sequence. You'll get a new login prompt for each attempt.
+
=== 使用虚拟控制台终端 ===
* You can get the GUI login with the sequence Ctl-Alt-F7 only in run level 5, or if the GUI is running after launching startx.
+
  
= System Shutdown and Rebooting =
+
默认情况下,在VGA控制台模式下,Linux运行6个虚拟控制台或TTY 会话。这些是通过在/etc/inittab文件中的mingetty语句来定义的。X终端GUI控制台通过第一个可用TTY(不受mingetty控制)创建自己的虚拟终端。 这使得GUI运行在第7个虚拟控制台上:
 +
* 可以通过按下Ctl-Alt-F1到F6键来依次查看各个虚拟控制台,每个虚拟控制台都是一个新login提示符 。
 +
* 可以通过按下Ctrl-Alt-F7键得到GUI登录界面,不过系统需要运行在runlevel 5下或者已经通过startx命令运行了GUI。
  
It is usually not a good idea to immediately power off your system when you are finished using it.  This can cause files that are being updated to become corrupted, or worse, you could corrupt the filesystem directory structure. Linux has a number of ways to gracefully shut down and reboot your system which will be outlined in this section.
+
= 系统关闭与重启 =
  
 +
当你使用完毕後,直接关闭电源不是一个好方法。这有可能会的更新的文件被破坏,甚至于破坏文件系统目录结构。Linux有许多安全的关机与重启系统的方法,在这一节中将概述这些方法。
  
=== Halt/Shut Down The System ===
+
=== 终止或关闭系统 ===
  
The init command will allow you to change the current runlevel, and for a shutdown, that value is 0. Here is an example:
+
init命令允许修改当前的runlevel,对于关闭系统,runlevel值是0,下面是例子:
  
 
  [root@bigboy tmp]# init 0
 
  [root@bigboy tmp]# init 0
  
Fedora also has a shutdown command which can also be used to the same effect. It often prompts you as to whether you are sure you want to execute the command, which can be avoided with the -y switch. The -h switch forces the system to halt, and the first argument tells it how long to wait before starting the procedure, in this case 0 minutes. You can also specify shutting down at a specific time of the day; please refer to the man pages for details. Another advantage of the shutdown command is that it warns people that the shutdown is going to occur.
+
Fedora也使用shutdown命令来完成相同的功能。常需要确认是否确定执行shutdown命令,可以通过使用-y开关来取消shutdown命令的执行。-h开关表示立即强迫系统停止运行,第一个参数确认开始程序运行后等待多长时间执行命令,此处例子为0分钟。也可以指定一天中的某个时间关闭系统,细节请查看man页。另一个有用的功能是shutdown命令将通知使用者系统即将关闭。
  
 
  [root@bigboy tmp]# shutdown -hy 0
 
  [root@bigboy tmp]# shutdown -hy 0
 
   
 
   
  Broadcast message from root (pts/0) (Sat Nov 6 13:15:27 2004):
+
  Broadcast message from root (pts/0)  
 +
(Sat Nov 6 13:15:27 2004): The system is going down for system halt NOW!
 
   
 
   
The system is going down for system halt NOW!
 
 
  [root@bigboy tmp]#
 
  [root@bigboy tmp]#
  
=== Reboot The System ===
+
=== 重新启动系统 ===
  
You can also use the init command to reboot the system immediately by entering runlevel 6.
+
可以通过init命令立刻修改runlevel为6重新启动系统 。
  
 
  [root@bigboy tmp]# init 6
 
  [root@bigboy tmp]# init 6
+
 
The "reboot" command has the same effect, but it also sends a warning message to all users.
+
reboot命令有同样的功能,并且对所有使用者发送一条警告消息。
+
 
 
  [root@bigboy tmp]# reboot
 
  [root@bigboy tmp]# reboot
 
   
 
   
第180行: 第170行:
 
  [root@bigboy tmp]#
 
  [root@bigboy tmp]#
  
More graceful reboots can be done with the shutdown command using the -r switch and specifying a delay, which in this case is 10 minutes.
+
更好的重启系统方法是使用shutdown的-r开关,并可指定一个重启延时时间,本例为10分钟。
+
 
 
  [root@bigboy root]# shutdown -ry 10
 
  [root@bigboy root]# shutdown -ry 10
 
   
 
   
第198行: 第188行:
 
  The system is going down for reboot NOW!
 
  The system is going down for reboot NOW!
  
=== Entering Single-user Mode ===
+
=== 进入单用户模式 ===  
  
Some activities require you to force the system to log off all users, third-party applications and networking so that only the systems administrator has access to the system from the VGA console. A typical scenario is the addition of a new hard disk, as mentioned in Chapter 27, "[[Quick HOWTO : Ch27 : Expanding Disk Capacity|Expanding Disk Capacity]]", or the troubleshooting of a failed boot process.
+
一些任务需要强迫你退出所有用户,结束第三方应用程序和断开网络连接,以便单独以系统管理员身份通过VGA控制台进入系统。 典型的任务是添加新硬盘(如第27章"[[Quick HOWTO : Ch27 : Expanding Disk Capacity|Expanding Disk Capacity]]"所述)或者针对启动过程失败的故障维护。 另一个使用原因是恢复你的root密码。
  
Another reason is the recovery of your root password.
+
==== 选择单用户模式 ====
  
==== Switching to Single-user Mode ====
+
当系统正常运行,可以使用init命令进入runlevel 1 。最好在当前终端运行此命令,因为如果你在一个远程终端运行这个命令时,用户将登出当前会话。
 
+
When the system is running normally, this can be done by using the init command to enter runlevel 1. It is best to do this from the console, because if you do it from a remote terminal session you'll be logged out.
+
  
 
  [root@bigboy root]# init 1
 
  [root@bigboy root]# init 1
第213行: 第201行:
 
  bash-2.05b#
 
  bash-2.05b#
  
Unfortunately, this gives no prior warning to users, and the shutdown command doesn't have a single-user mode option. This can be overcome by running the shutdown command with a delay in minutes as the only argument.
+
不幸的是,这个对用户并没有前瞻性的警告作用,shutdown命令没有单用户模式选项。可以通过运行带延迟1分钟作为唯一参数的shutdown命令来克服上面的困难。
  
 
  [root@bigboy tmp]# shutdown 1
 
  [root@bigboy tmp]# shutdown 1
第229行: 第217行:
 
  bash-2.05b#
 
  bash-2.05b#
  
==== Entering Single-user Mode At The Grub Splash Screen ====
+
==== 在Grub屏幕下选择单用户模式 ====
  
 +
可以在启动系统后直接进入当单用户模式。步骤如下:
  
You can enter single user mode directly after turning on the power to your system. The steps to do this are listed below.
 
  
1. Power on your system. Wait for the "Grub loading" message to appear and, depending on your Linux distribution, get ready to hit either any key or the ESC key to enter the grub boot menu.
+
1. 开启系统,等待产生“Grub loading”消息。准备按下任意键或ESC键进入grub启动菜单,这取决于您Linux发行版。
 
  Grub loading, please wait ...
 
  Grub loading, please wait ...
 
  Press ESC to enter the menu
 
  Press ESC to enter the menu
or
+
或者
 
  Grub loading, please wait ...
 
  Grub loading, please wait ...
 
  Press any key to enter the menu
 
  Press any key to enter the menu
  
2. You will then get grub's main menu which will display a list of available kernels. Use the arrow keys to scroll to your desired version of the kernel and then press e for "edit".
+
2. 获取的grub主菜单是一份可用内核的列表。通过方向键滚动到你想要的内核版本,按下e键开始编辑。
  
 
  Fedora Core (2.6.18-1.2239.fc5smp)
 
  Fedora Core (2.6.18-1.2239.fc5smp)
 
  Fedora Core (2.6.18-1.2200.fc5smp)
 
  Fedora Core (2.6.18-1.2200.fc5smp)
  
3. The kernel's boot menu will appear. Use the arrow keys to scroll to the "kernel" line and then press e for "edit".
+
3. 内核启动菜单然后出现,使用方向键滚动到“kernel”行,按下e键开始编辑。
  
 
  root (hd0,0)
 
  root (hd0,0)
第252行: 第240行:
 
  initrd /initrd-2.6.18-1.2239.fc5smp.img
 
  initrd /initrd-2.6.18-1.2239.fc5smp.img
  
4. A grub edit prompt will appear. Use the arrow keys to move to the end of the line and add the word "single" to the end, separated by a space. Change
+
4. 一个grub edit器出现,通过方向键移动到行最后面,然后在行后添加“single”,中间用空格隔开。
 
+
 
  grub edit> kernel /vmlinuz-2.6.18-1.2239.fc5smp ro root=LABEL=/
 
  grub edit> kernel /vmlinuz-2.6.18-1.2239.fc5smp ro root=LABEL=/
  
to
+
修改为
 
   
 
   
 
  grub edit> kernel /vmlinuz-2.6.18-1.2239.fc5smp ro root=LABEL=/ single
 
  grub edit> kernel /vmlinuz-2.6.18-1.2239.fc5smp ro root=LABEL=/ single
  
5. Press enter to save your changes, and then b for "boot".
+
5. 按下enter回车键保存修改,按下b键开始“boot”启动。
6. The system will continue to boot, but will go straight to the root # prompt without first asking for a username and password.
+
  
==== Reverting To Your Default runlevel From Single User Mode ====
+
6. 系统继续启动,但将直接进入root#提示符下,没有用户名和密码的询问。
  
The exit command forces the system to exit runlevel 1 and revert to the default runlevel for the system. You can also use the init command (for example init 3 and init 5) to alter this default behavior:
+
==== 从单用户模式转入默认运行级别 ====
  
 +
exit命令强制系统退出runlevel 1,转入系统默认的runlevel。也可以通过使用init命令(如init 3和init 5)选择默认行为:
 
  bash-2.05b# exit
 
  bash-2.05b# exit
 
  INIT: Entering runlevel: 3
 
  INIT: Entering runlevel: 3
第276行: 第264行:
 
  bigboy login:
 
  bigboy login:
  
==== Root Password Recovery ====
+
==== Root密码恢复 ====
  
Sometimes you might forget the root password, or the previous systems administrator may move on to a new job without giving it to you. To do this, follow these steps:
+
有时你可能会忘记root密码,或者先前的系统管理员调到一个新工作但密码并没有给你。通过下面的步骤恢复密码:
  
# Go to the VGA console and press Ctrl-Alt-Del. The system will then shut down in an orderly fashion.
+
# 到VGA控制台,按下 Ctrl-Alt-Del键.系统将会正常关闭。
# Reboot the system and enter single-user mode.
+
# 重新启动系统,进入单用户模式。
# Once at the command prompt, change your password. Single user mode assumes the person at the console is the systems administrator root, so you don't have to specify a root username.
+
# 在命令提示符下,修改密码。单用户模式下鉴定控制台下的用户为系统管理员的root,因此不用指定root用户名。
# Return to your default runlevel by using the exit command.
+
# 使用exit命令返回到默认runlevel。
  
=Starting and Stopping  Daemons=
+
= 启动和停止守护进程 =  
A simple definition of a daemon is a programs that runs unattended even when nobody is logged into your system. Common examples of daemons are the <code>syslog</code> daemon which receives system error messages and writes them to a log file; the <code>apache</code> or <code>httpd</code> daemon that serves web pages to Internet web browsers and the <code>sendmail</code> daemon that places email it receives into your inbox.
+
对于守护进程,一个比较简单的定义是:守护进程是一种即使没有人登录进入你的系统也会在无人值守的情况下运行的程序。比较常见的守护进程有<code>syslog</code> 守护进程用于收集系统出错信息并将其写入日志文件; 还有 <code>apache</code> <code>httpd</code> 守护进程用于为互联网浏览器提供所需浏览的网页以及<code>sendmail</code> 守护进程用于将服务器所收到的电子邮件推送至你的收件箱。
  
The startup scripts I have been mentioning in the <code>/etc/init.d</code> directory govern the activation of daemons that were installed with some of your Linux packages. The commands to start and stop them are universal.
+
位于<code>/etc/init.d</code>目录下的启动脚本管理着随Linux包安装的守护进程的活动状态,启动和停止命令对于所有这些脚本是通用的。
  
==Starting a Daemon==
+
== 启动守护进程 ==  
If a startup script exists in the <code>/etc/init.d</code> directory, then its daemon can be started by specifying its filename followed by the keyword "start" as seen here:
+
如果在 <code>/etc/init.d</code> 目录中存在一个启动脚本,那么它的守护进程将通过指定它的文件名并在后面加上关键词“start”的方式启动,如以下显示:
  
 
  root@u-bigboy:~# /etc/init.d/apache start
 
  root@u-bigboy:~# /etc/init.d/apache start
第297行: 第285行:
 
     ...done.
 
     ...done.
 
  root@u-bigboy:~#
 
  root@u-bigboy:~#
 
+
== 停止守护进程 ==  
==Stopping a Daemon==
+
守护进程可以通过指定它的文件名并在后面加上关键词“stop”的方式停止;
Daemons can be stopped by specifying its script filename followed by the keyword "stop":
+
 
+
 
  root@u-bigboy:~# /etc/init.d/apache stop
 
  root@u-bigboy:~# /etc/init.d/apache stop
 
   * Stopping apache 1.3 web server...
 
   * Stopping apache 1.3 web server...
 
     ...done.
 
     ...done.
 
  root@u-bigboy:~#
 
  root@u-bigboy:~#
 
+
== 重启守护进程 ==  
==Restarting a Daemon==
+
通常情况守护进程只在启动时读取相应的配置文件,因此,如果你改写它的配置文件,为了使其生效,你将不得不重启守护进程。带有关键词“restart”的命令将帮你实现重启操作:
Daemons usually only read their configuration files when they are started, therefore if you edit the file, you have to restart the daemon for the new settings to become active. This can be done with the keyword "restart":
+
  
 
  root@u-bigboy:~# /etc/init.d/apache restart
 
  root@u-bigboy:~# /etc/init.d/apache restart
第313行: 第298行:
 
     ...done.
 
     ...done.
 
  root@u-bigboy:~#
 
  root@u-bigboy:~#
 +
别为配置你的守护进程担心。稍后我们将介绍一些常用的守护程序并通过一些简单的例子来具体了解它们。
 +
 +
== 关于服务命令 ==
  
Don’t worry about configuring your daemons. Later we'll be covering some commonly used daemons and will discuss them with ample examples.
+
一些操作系统例如:Fedora 和 Rathat 也同样具有快捷的服务命令,允许你使用 "start", "stop" "restart" 这些关键词来控制守护进程, 但是使用更少的字符。 这里是一些实现该功能的快捷的,直观的例子:
==The service command==
+
Some operating systems such as Fedora and Redhat also come with the shortcut <code>service</code> command which allows you to control daemons with the "start", "stop" and "restart" keywords, but with less typing. Here are some quick, intuitive examples of doing this:
+
  
 
  [root@bigboy ~]# service httpd start
 
  [root@bigboy ~]# service httpd start
第322行: 第308行:
 
  [root@bigboy ~]# service httpd restart
 
  [root@bigboy ~]# service httpd restart
  
The service command also has the "status" keyword which will provide a brief report on what the daemon is doing.
+
服务命令同样也具有“status”这个关键字,用来提供一个关于守护进程目前工作的简洁的报告。
  
 
  [root@bigboy ~]# service httpd status
 
  [root@bigboy ~]# service httpd status
第328行: 第314行:
 
  [root@bigboy ~]#
 
  [root@bigboy ~]#
  
= Using chkconfig to Start Daemons at Each runlevel =
+
= 在各个运行级别上使用chkconfig命令启动守护进程 =
  
As stated earlier, the chkconfig command can be used to adjust which applications start at each runlevel. You can use this command with the --list switch to get a full listing of packages listed in /etc/init.d and the runlevels at which they will be on or off:
+
正如先前所说, chkconfig命令行可以用来调节程序在哪个运行级别启动.你可以使用这个命令带 --list 参数来列出/etc/init.d下的包列表以及其在各个运行级别上是运行还是停止:  
  
 
  [root@bigboy tmp]# chkconfig --list
 
  [root@bigboy tmp]# chkconfig --list
第346行: 第332行:
 
  ...
 
  ...
  
=== chkconfig Examples ===
 
  
You can use chkconfig to change runlevels for particular packages. Here we see sendmail will start with a regular startup at runlevel 3 or 5. Let's change it so that sendmail doesn't startup at boot.
+
=== chkconfig举例 ===
  
==== Use Chkconfig to Get a Listing of sendmail's Current Startup Options ====
+
你可以使用chkconfig来为一个包改变运行级别.这里你会看到sendmail在运行级别3或5中常规启动.让我们把sendmail改成不在系统启动时运行.
 +
 
 +
==== 用chkconfig来得到sendmail的当前运行操作列表 ====
 +
 
 +
chkconfig命令可以和grep结合使用,来确定sendmail在哪个运行级别可以运行.我们看到这里它可以行动在级别3和5.
  
The chkconfig command can be used with grep to determine the run levels in which sendmail will run. Here we see it will run at levels 3 and 5.
 
  
 
  [root@bigboy tmp]# chkconfig --list | grep mail
 
  [root@bigboy tmp]# chkconfig --list | grep mail
第358行: 第346行:
 
  [root@bigboy tmp]#
 
  [root@bigboy tmp]#
  
==== Switch Off sendmail Starting Up in Levels 3 and 5 ====
+
==== 用命令行工具来获得邮件服务器当前启动项的列表====
 +
 
 +
命令行工具和文档搜索工具的配合使用可以让你决定邮件服务器的运行等级. 下面的命令可以让邮件服务器运行在3级和5级.
 +
 
 +
 
 +
[root@bigboy tmp]# chkconfig --level 35 sendmail off
 +
[root@bigboy tmp]#
 +
 
 +
==== 使sendmail不在运行级别3和5启动 ====
  
The chkconfig command with the --level switch indicates that some action needs to be done at the runlevels entered as its values. The first argument in the command is the package you want to affect and the second defines whether you want it on or off. In this case we want sendmail not to be started when entering runlevels 3 and 5:
+
chkconfig带--level参数可以指示在该运行级别上的相关操作.命令中的第一个参数是你相设置的包的名称第二个参数则让你选择是on或off.在这里我们使sendmail不要在运行级别3和5中启动:
  
 
  [root@bigboy tmp]# chkconfig --level 35 sendmail off
 
  [root@bigboy tmp]# chkconfig --level 35 sendmail off
 
  [root@bigboy tmp]#
 
  [root@bigboy tmp]#
  
By not specifying the runlevels with the --level switch, chckconfig will make the changes for runlevels 3 and 5 automatically:
+
如果没有指定--level后的运行级别,chkconfig会在运行级别3,5上作自动修改.
  
  [root@bigboy tmp]# chkconfig sendmail off
+
  [root@bigboy tmp]# chkconfig sendmail off  
  
Because the intention is to permanently shutdown sendmail permanently, we might also have to stop it from running now.
+
因为是要永久的关闭sendmail,我们当然要关闭正在运行的sendmail.
  
 
  [root@bigboy tmp]# service sendmail stop
 
  [root@bigboy tmp]# service sendmail stop
第376行: 第372行:
 
  [root@bigboy tmp]#
 
  [root@bigboy tmp]#
  
==== Double-check that sendmail Will Not Start Up ====
+
====对邮件服务器不能启动的检查 ====
  
We can then use chkconfig to double-check our work.
+
我们可以使用chkconfig命令来检查
  
 
  [root@bigboy tmp]# chkconfig --list | grep mail
 
  [root@bigboy tmp]# chkconfig --list | grep mail
第384行: 第380行:
 
  [root@bigboy tmp]#
 
  [root@bigboy tmp]#
  
==== Turn On sendmail Again ====
+
==== 重新启动邮件服务器====
  
To reactivate sendmail, we can use chkconfig once more, but with the on argument. Start sendmail again to get it running immediately, not just after the next reboot.
+
为了让邮件服务器恢复功能, 我们可以再次使用chkconfig命令,不过用的是on参数. 再一次启动邮件服务器以让它立即运行, 而不是傻傻地等到系统的重新启动.
  
 
  [root@bigboy tmp]# chkconfig sendmail on
 
  [root@bigboy tmp]# chkconfig sendmail on
第396行: 第392行:
 
  [root@bigboy tmp]#
 
  [root@bigboy tmp]#
  
=== Using chkconfig to Improve Security ===
+
=== 使用命令行工具来提高系统的安全性===
  
A default Fedora installation automatically starts a number of daemons that you may not necessarily need for a Web server. This usually results in your system listening on a variety of unexpected TCP/IP ports that could be used as doors into your system by hackers.
+
一个Fedora安装程序不会自行启动一些对于一个网络服务器来说并不需要的保护程序。这可能造成的结果就是你的系统被无数恶意TCP/IP端口监听,而这可能会为黑客的攻击大开方便之门
  
The screen output of the netstat -an command below shows a typical case. Some ports are relatively easy to recognize. TCP ports 25 and 22 are for mail and SSH, respectively, but some others are less obvious. Should you use the chkconfig command and the scripts in the /etc/init.d directory to shut these down permanently?
+
屏幕上会显示出网络状态--下面的命令就是一个典型的例子。有些端口相对容易去识别. TCP 端口25和22分别是邮件和远程登录协议, 但是其它的就不是那么明显了. 你会用位于 /etc/init.d 目录树中的命令和脚本 去把它们永久关闭吗?
  
 
  [root@bigboy tmp]# netstat -an
 
  [root@bigboy tmp]# netstat -an
第421行: 第417行:
 
  [root@bigboy tmp]#
 
  [root@bigboy tmp]#
 
   
 
   
For example, how do you know which startup script is responsible for TCP port 111? The answer is to use the lsof command which lists all open, or actively used, files and can be given additional options to extend its scope to include the TCP/IP protocol stack.
+
例如,你怎么知道哪个启动脚本是针对TCP端口111的? 答案就是用lsof命令让系统列出所有被打开的和被频繁使用的文件,同时还可以通过进一步的设置将它的处理范围扩展到TCP/IP协议栈。
  
In the next examples we see that TCP ports 111 and 32769, and UDP port 123 are being used by the portmap, xinetd and ntp daemons respectively. The portmap daemon is required for the operation of NFS and NIS, topics that are covered in Chapters 29, "[[Quick HOWTO : Ch29 : Remote Disk Access with NFS|Remote Disk Access with NFS]]", and 30, "[[Quick HOWTO : Ch30 : Configuring NIS|Configuring NIS]]". portmap also has many known security flaws that makes it advisable to be run on a secured network. If you don't need any of these three applications, it's best to shut down portmap permanently. NTP, which is covered in Chapter 24, "[[Quick HOWTO : Ch24 : The NTP Server|The NTP Server]]", is required for synchronizing your time with a reliable time source, and may be necessary. A number of network applications are reliant on xinetd, as explained in Chapter 16, "[[Quick HOWTO : Ch16 : Telnet, TFTP, and xinetd|Telnet, TFTP, and xinetd]]", and it might be required for their operation:
+
下面我们分别来看看portmap、xinetd和ntp守护进程对TCP端口111、32769和UDP端口123的使用。portmap守护进程是NFS和NIS(关于NFS和NIS请参考第29章"[[Quick HOWTO : Ch29 : Remote Disk Access with NFS|Remote Disk Access with NFS]]"和第30章"[[Quick HOWTO : Ch30 : Configuring NIS|Configuring NIS]]")操作所必须的。portmap存在很多已知的安全问题,建议在安全网络内运行。如果你不需要这些应用程序,最好关闭portmap。NTP(具体请看第24章 "[[Quick HOWTO : Ch24 : The NTP Server|The NTP Server]]")要求将你的系统时间与时间源同步,这可能是必须的。很多网络应用依赖于xinetd,如第16章"[[Quick HOWTO : Ch16 : Telnet, TFTP, and xinetd|Telnet, TFTP, and xinetd]]"所述,xinetd是这些应用程序正常运行所必须的:
  
 
  [root@ bigboy tmp]# lsof -i tcp:111
 
  [root@ bigboy tmp]# lsof -i tcp:111
第442行: 第438行:
 
  [root@bigboy root]#
 
  [root@bigboy root]#
  
In some cases it's tricky to determine the application based on the results of the lsof command. In the example below, we've discovered that TCP port 32768 is being used by rpc.statd, but there is no rpc.statd file in the /etc/init.d directory. The simple solution is to use the grep command to search all the files for the string rpc.statd to determine which one is responsible for its operation. We soon discover that the nfslock daemon uses it. If you don't need nfslock, then shut it down permanently.
+
有时候通过lsof命令查看应用程序是比较棘手的。在下面的例子中,我们发现TCP端口32768被rpc.statd占用,而/etc/init.d目录下没有rpc.statd文件。简单的解决方法是用grep命令在/etc/init.d目录下的所有文件中查找"rpc.statd"字符串,从而找出对应的文件。很快,我们发现nfslock守护进程使用rpc.statd。如果你不需要nfslock,就把它永久性关闭吧。
  
 
  [root@bigboy tmp]# lsof -i tcp:32768
 
  [root@bigboy tmp]# lsof -i tcp:32768
第455行: 第451行:
 
  [root@bigboy tmp]#
 
  [root@bigboy tmp]#
  
As a rule of thumb, applications listening only on the loopback interface (IP address 127.0.0.1) are usually the least susceptible to network attack and probably don't need to be stopped for network security reasons. Those listening on all interfaces, depicted as IP address 0.0.0.0, are naturally more vulnerable and their continued operation should be dependent on your server's needs. I usually shutdown nfs, nfslock, netfs, portmap, and cups printing as standard practice on Internet servers. I keep sendmail running as it is always needed to send and receive mail (see Chapter 21, "[[Quick HOWTO : Ch21 : Configuring Linux Mail Servers|Configuring Linux Mail Servers]]", for details). Your needs may be different.
+
根据经验,只监听本地回路接口 (IP地址为127.0.0.1)的应用程序通常不易受网络攻击影响,无须为安全原因而将其停止。而那些监听所有接口,如IP地址为0.0.0.0的应用程序,自然很容易受到网络攻击,其关闭与否取决于你的服务器的需要。我的习惯做法是关闭Internet服务器上的nfs、nfslock、netfs、portmap和cups打印服务,保留sendmail服务,因为邮件的收发总是必需的(具体请看第21章"[[Quick HOWTO : Ch21 : Configuring Linux Mail Servers|Configuring Linux Mail Servers]]"),你的需求可能和我不一样。
  
Remember to thoroughly research your options thoroughly before choosing to shut down an application. Use the Linux man pages, reference books and the Internet for information. Unpredictable results are always undesirable.
+
在关闭应用程序之前务必周密地考虑你的需求。你可以通过Linux用户手册、参考书或者Internet获取更多与应用程序相关的信息。不可预料的结果是我们都不希望看到的。
  
Shutting down applications is only a part of server security. Firewalls, physical access restrictions, password policies, and patch updates need to be considered. Full coverage of server and network security is beyond the scope of this book, but you should always have a security reference guide on hand to guide your final decisions.
+
关闭应用程序只是保障服务器安全的一个环节。防火墙、物理访问限制、密码策略和补丁更新也是保障服务器安全所必须考虑的。关于服务器和网络安全的详细讨论已经超出了本书的范围,在此不做赘述,不管怎样,你手头上必须有一些安全参考手册以供不时之需。
  
=== Final Tips on chkconfig ===
+
=== chkconfig小贴士 ===
  
Remember the following:
+
记住:
  
* In most cases, you want to modify runlevels 3 and 5 simultaneously and with the same values.
+
* 在大多数情况下,你必须同时修改运行级别为3和5的配置且配置结果要一致。
* Don't add/remove anything to other runlevels unless you absolutely know what you are doing. Don't experiment, unless in a test environment.
+
* 不要添加/删除其他运行级别的任何东西,除非你很清楚地知道你在做什么。不要试图体验,除非在测试环境中。
* chkconfig doesn't start the programs in the /etc/init.d directory, it just configures them to be started or ignored when the system boots up. The commands for starting and stopping the programs covered in this book are covered in each respective chapter.
+
* chkconfig不会启动/etc/init.d目录下的任何项目,它只是编辑它们是否随系统启动。启动和停止这些项目的命令在本书各章节中分别有介绍。
  
=Using sysv-rc-conf to Start Daemons at Each runlevel=
+
=用sysv-rc-conf启动各运行级别下的守护进程=
  
With Debian / Ubuntu Linux, the <code>update-rc.d</code> command replaces <code>chkconfig</code> as the default package for modifying <code>/etc/init.d</code> script links. Unfortunately, the utility was written to facilitate link modification when packages are installed or removed, but is less friendly when you need to alter links for existing packages you want to keep.
+
在Debian/Ubuntu linux中,<code>update-rc.d</code>命令取代<code>chkconfig</code>作为默认的编辑<code>/etc/init.d</code>脚本链接的包。可惜该工具主要用于编辑当前安装或删除的服务链接,而对已存在的包的链接的编辑的支持很差。
  
Fortunately there is hope for the harried systems administrator in the form of the <code>sysv-rc-conf</code> package which uses an almost identical syntax to <code>chkconfig</code>, and has a GUI mode if you run it from the command line without any arguments. This section will show you some important tips in using <code>sysv-rc-conf</code>.
+
不过幸运的是与<code>chkconfig</code>语法几乎一致的包<code>sysv-rc-conf</code>给苦恼的管理员带来了希望,你可以通过执行它的无参命令来启动它的GUI模式。这一节将为你展示使用<code>sysv-rc-conf</code>的一些重要技巧。
  
==Installing sysv-rc-conf==
+
==安装sysv-rc-conf==
The <code>sysv-rc-conf</code> package can be installed easily using <code>apt-get</code>. Here is an example.
+
<code>sysv-rc-conf</code>包可以通过<code>apt-get</code>安装。如下所示:
  
 
  root@u-bigboy:~# apt-get install sysv-rc-conf
 
  root@u-bigboy:~# apt-get install sysv-rc-conf
  
==Listing the runlevels for Daemons==
+
==列出守护进程的运行级别==
This can be done with the <code>--list</code> option. In this example below we get a listing for only the apache daemon.
+
这可以通过添加<code>--list</code>选项实现。在下面的例子中我们将列出apache守护进程的运行级别。
  
 
  root@u-bigboy:~#  sysv-rc-conf  --list apache
 
  root@u-bigboy:~#  sysv-rc-conf  --list apache
第487行: 第483行:
 
  root@u-bigboy:~#
 
  root@u-bigboy:~#
  
Here we get a listing for everything.
+
我们再来看看所有守护进程的运行级别。
  
 
  root@u-bigboy:~#  sysv-rc-conf  --list
 
  root@u-bigboy:~#  sysv-rc-conf  --list
第500行: 第496行:
 
  root@u-bigboy:~#
 
  root@u-bigboy:~#
  
==Setting the runlevels for Daemons==
+
==设置守护进程的运行级别==
  
The <code>sysv-rc-conf</code> program has further similarities to the <code>chkconfig</code> syntax. Here we set the <code>apache</code> daemon to start automatically at levels 2 through 5.
+
<code>sysv-rc-conf</code><code>chkconfig</code>语法很相似。让我们来设置<code>apache</code>守护进程在运行级别2至5中自动启动。
  
 
  root@u-bigboy:~# sysv-rc-conf  apache on
 
  root@u-bigboy:~# sysv-rc-conf  apache on
  
Similarly, we can set the <code>apache</code> daemon not to start at levels 2 through 5 with this command:
+
同样,我们可以通过以下命令设置<code>apache</code>在运行级别2至5中不启动:
  
 
  root@u-bigboy:~# sysv-rc-conf  apache off
 
  root@u-bigboy:~# sysv-rc-conf  apache off
  
Finally we can use set the <code>apache</code> daemon to start only at levels 3 and 5.
+
最后,我们设置<code>apache</code>只在运行级别3和5中启动。
  
 
  root@u-bigboy:~# sysv-rc-conf  --level 35 apache on
 
  root@u-bigboy:~# sysv-rc-conf  --level 35 apache on
  
= Conclusion =
+
= 总结 =
  
The topics discussed in this chapter might seem simple, but like syslog, which was covered in Chapter 5, "[[Quick HOWTO : Ch05 : Troubleshooting Linux with syslog|Troubleshooting Linux with syslog]]", they are an essential part of Linux administration that gets frequently overlooked especially when new software is installed.
+
本章所谈论的话题看似简单,但它和第5章"[[Quick HOWTO : Ch05 : Troubleshooting Linux with syslog|Troubleshooting Linux with syslog]]"中谈到的syslog一样,是Linux管理的基础,通常会被忽略,特别是新软件安装时。
  
Whenever possible, always try to reboot your system to make sure all the newly installed applications start up correctly. Sometimes they start but give errors listed only in the /var/log directory. Taking the time to configure and test your startup scripts could prevent you from being awakened in the middle of the night while you are on vacation! It is really important.
+
只要有可能,尽量重启一下你的系统以确保新安装的应用程序的正常运行。有时它们启动后只将错误写入/var/log目录。花点时间配置并测试一下你的启动脚本可以避免你在休假时被半夜叫醒!这的确是很重要的。
 +
[[Category:Quick_HOWTO]]

2010年7月18日 (日) 16:06的最新版本


简介

了解Linux如何启动很有用,之後您就可以改变登录界面的类型,或者自由选择启动时加载哪些程序。欢迎阅读下面的细节。

Linux启动顺序

您或许还记得,当初安装Linux时,安装程序显示了一份硬盘分区的列表,包含各个分区的大小,您的文件系统将安装在这些分区上。

当为各个分区分配磁盘空间时,每个分区的第一个数据单元,或称之为“扇区”,总是预留给启动代码。整块硬盘的第一个扇区也用于同样的目的,该扇区被称作主引导记录(MBR)。

当由硬盘启动PC时,BIOS被加载,之後运行MBR中的启动引导代码。MBR需要知道哪个分区的引导扇区中包含了操作系统的启动引导代码,之後MBR会试着启动其中的一个。

Fedora Linux发行版使用了非常复杂的GRUB启动引导程序,该程序无法放入MBR的512字节中。GRUB启动引导程序仅搜寻特定的启动分区,找到後加载第二阶段的启动引导程序。GRUB从包含各类操作系统和操作系统的启动参数的配置文件/boot/grub/grub.conf中读取启动配置数据。当GRUB启动引导程序完成後,第二阶段的启动引导程序在屏幕上显示有Fedora标记的所有你选择的操作系统核心配置。

注意: 在一些操作系统中,如Debian / Ubuntu,配置文件 /boot/grub/grub.conf 可能会被下面的文件取代 /boot/grub/menu.lst

图7-1显示了能够同时启动Fedora Linux和Windows 2000系统的一个典型grub.conf文件。配置文件的结构将在第33章讨论, "Modifying the Kernel to Improve Performance"。

图 7-1 grub.conf 文件示例

default=0
timeout=10
splashimage=(hd0,0)/grub/splash.xpm.gz
title Fedora Core (2.6.8-1.521)
        root (hd0,0)
        kernel /vmlinuz-2.6.8-1.521 ro root=LABEL=/
        initrd /initrd-2.6.8-1.521.img
title Windows 2000
      rootnoverify (hd0,1)
      chainloader +1


当Linux开始启动内核时,首先运行/sbin/init脚本程序进行一些系统检查,如文件系统完整性的确认和操作系统正常运作的重要程序的启动。 Linux开始检测/etc/initab文件,并决定Linux的全部运行模式和运行级别。有效的运行级别列表见表7-1。

表 7-1 Linux 运行级别

Mode Directory Run Level Description
0 /etc/rc.d/rc0.d 关机
1 /etc/rc.d/rc1.d 单用户模式
2 /etc/rc.d/rc2.d 未使用,用户自定义
3 /etc/rc.d/rc3.d 多用户模式,无图形界面
4 /etc/rc.d/rc4.d 未使用(用户定义)
5 /etc/rc.d/rc5.d 多用户模式(图形界面)
6 /etc/rc.d/rc6.d 重启

init程序依据选定的运行级别执行在子目录 /etc/rc.d 下的脚本程序.。运行级别0-6分别对应子目录中的 /etc/rc.d/rc0.d -/etc/rc.d/rc6.d

以下是/etc/rc.d/rc3.d目录下的脚本文件列表

[root@bigboy tmp]# ls /etc/rc.d/rc3.d
...    ...    K75netfs      K96pcmcia    ...    ...
...    ...    K86nfslock    S05kudzu     ...    ...
...    ...    K87portmap    S09wlan      ...    ...
...    ...    K91isdn       S10network   ...    ...
...    ...    K92iptables   S12syslog    ...    ...
...    ...    K95firstboot  S17keytable  ...    ...
[root@bigboy tmp]#

如上,你会发现,这些目录中的每个文件名要么是以“S”开头,以表明这些脚本是在系统启动的时候运行,或以“K”开头,表示这类脚本在系统正在关闭的时候被调用。如果一个脚本不在此目录,那么此脚本不会被运行。

大多数linux软件包将它们的启动脚本放在/etc/init.d目录下,相应的符号连接放在相应的/etc/rc.d子目录中。如此使得文件管理更为容易。比如说,删除文件的符号连接,而不会删除真实文件,这样以後你还可以使用它。

跟在K或者S後的数字按升序排列也就是这些脚本运行的次序。如,kudzu(後05)将比wlan(後09)先运行。幸运的是,你不必需要一个总的脚本,或者符号连接来保证所有脚本运行正常。因为Fedora中有一个名为chkconfig的组件,Debian/Ubuntu使用update-rc.d命令来帮你做所有的事情。我们等会在详细讲它。

设置默认的启动级别

系统默认启动级别在文件/etc/inittab,变量initdefault中设置。当被设置为3时,系统以文本模式启动;

当被设置为5时,系统将会以图形界面模式启动。这里是此文件的一部分(删除你不需要的initdefault行):

# Default runlevel. The runlevels used by RHS are:
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
# 
id:3:initdefault:                         # Console Text Mode
id:5:initdefault:                         # Console GUI Mode

注意:

  • 大多数用户以如windows的图形界面启动(运行级别 5)
  • 大多数techies倾向于基于文本的命令行模式启动(运行级别 3)
  • 将默认启动值从3改为5,或者反过来,对下次重启有影响。查看下列章节:如何设置始终图形界面登录直到下次重启。
  • 当然,不要设置默认启动值为6,否则你会不断重启;设置默认启动值0会导致永远开不了机。

获取一个GUI控制界面

手动方法: 每次需要运行X终端GUI应用程序时,通过在VGA控制台模式下运行startx命令启动X终端。记住登出後你将再次返回到基于文本的控制台.

[root@bigboy tmp]# startx

自动方法:可以让Linux在每次登录时自动载入X终端GUI界面,除非用init命令重新启动系统。像在先前的文章中提到一样,为使系统重新启动后仍保持这些功能,你需要编辑/etc/inittab文件中的initdefault变量。

[root@bigboy tmp]# init 5

当你的机器的CPU性能或可用内存低的时候,或者你需要最大化利用你的资源,大部分时候你需要在runlevel 3文本模式下运行系统,必要时通过startx命令启动GUI。

无论是作为个人工作站还是服务器,机器可用要运行较长时间,非技术员工可能需要通过init 5命令让其一直运行在运行级别 5。记住,你能通过修改/etc/initab文件让系统一直运行在运行级别 5,即使是重新启动。

获取一个在GUI环境下的文本终端

运行在Linux GUI环境中,有很多方法可以开启终端程序。当想要快速使用命令或者对GUI菜单选项不熟悉,这些方法很重要。

使用一个GUI终端窗口

通过下面方法,开启一个基于GUI的终端窗口:

  • 点击屏幕左边底部的Fedora标志按钮。
  • 点击系统工具(System Tools),然後点击终端(Terminal)。

使用虚拟控制台终端

默认情况下,在VGA控制台模式下,Linux运行6个虚拟控制台或TTY 会话。这些是通过在/etc/inittab文件中的mingetty语句来定义的。X终端GUI控制台通过第一个可用TTY(不受mingetty控制)创建自己的虚拟终端。 这使得GUI运行在第7个虚拟控制台上:

  • 可以通过按下Ctl-Alt-F1到F6键来依次查看各个虚拟控制台,每个虚拟控制台都是一个新login提示符 。
  • 可以通过按下Ctrl-Alt-F7键得到GUI登录界面,不过系统需要运行在runlevel 5下或者已经通过startx命令运行了GUI。

系统关闭与重启

当你使用完毕後,直接关闭电源不是一个好方法。这有可能会的更新的文件被破坏,甚至于破坏文件系统目录结构。Linux有许多安全的关机与重启系统的方法,在这一节中将概述这些方法。

终止或关闭系统

init命令允许修改当前的runlevel,对于关闭系统,runlevel值是0,下面是例子:

[root@bigboy tmp]# init 0

Fedora也使用shutdown命令来完成相同的功能。常需要确认是否确定执行shutdown命令,可以通过使用-y开关来取消shutdown命令的执行。-h开关表示立即强迫系统停止运行,第一个参数确认开始程序运行后等待多长时间执行命令,此处例子为0分钟。也可以指定一天中的某个时间关闭系统,细节请查看man页。另一个有用的功能是shutdown命令将通知使用者系统即将关闭。

[root@bigboy tmp]# shutdown -hy 0

Broadcast message from root (pts/0) 
(Sat Nov 6 13:15:27 2004): The system is going down for system halt NOW!

[root@bigboy tmp]#

重新启动系统

可以通过init命令立刻修改runlevel为6重新启动系统 。

[root@bigboy tmp]# init 6

reboot命令有同样的功能,并且对所有使用者发送一条警告消息。

[root@bigboy tmp]# reboot

Broadcast message from root (pts/0) (Sat Nov  6 12:39:31 2004):

The system is going down for reboot NOW!
[root@bigboy tmp]#

更好的重启系统方法是使用shutdown的-r开关,并可指定一个重启延时时间,本例为10分钟。

[root@bigboy root]# shutdown -ry 10

Broadcast message from root (pts/0) (Sat Nov  6 13:26:39 2004):

The system is going DOWN for reboot in 10 minutes!

Broadcast message from root (pts/0) (Sat Nov  6 13:27:39 2004):

The system is going DOWN for reboot in 9 minutes!
...
...
...
Broadcast message from root (pts/0) (Sat Nov  6 13:36:39 2004):

The system is going down for reboot NOW!

进入单用户模式

一些任务需要强迫你退出所有用户,结束第三方应用程序和断开网络连接,以便单独以系统管理员身份通过VGA控制台进入系统。 典型的任务是添加新硬盘(如第27章"Expanding Disk Capacity"所述)或者针对启动过程失败的故障维护。 另一个使用原因是恢复你的root密码。

选择单用户模式

当系统正常运行,可以使用init命令进入runlevel 1 。最好在当前终端运行此命令,因为如果你在一个远程终端运行这个命令时,用户将登出当前会话。

[root@bigboy root]# init 1
...
...
bash-2.05b#

不幸的是,这个对用户并没有前瞻性的警告作用,shutdown命令没有单用户模式选项。可以通过运行带延迟1分钟作为唯一参数的shutdown命令来克服上面的困难。

[root@bigboy tmp]# shutdown 1

Broadcast message from root (pts/0) (Sat Nov  6 13:44:59 2004):

The system is going DOWN to maintenance mode in 1 minute!

Broadcast message from root (pts/0) (Sat Nov  6 13:45:59 2004):

The system is going down to maintenance mode NOW!

...
...
bash-2.05b#

在Grub屏幕下选择单用户模式

可以在启动系统后直接进入当单用户模式。步骤如下:


1. 开启系统,等待产生“Grub loading”消息。准备按下任意键或ESC键进入grub启动菜单,这取决于您Linux发行版。

Grub loading, please wait ...
Press ESC to enter the menu

或者

Grub loading, please wait ...
Press any key to enter the menu

2. 获取的grub主菜单是一份可用内核的列表。通过方向键滚动到你想要的内核版本,按下e键开始编辑。

Fedora Core (2.6.18-1.2239.fc5smp)
Fedora Core (2.6.18-1.2200.fc5smp)

3. 内核启动菜单然后出现,使用方向键滚动到“kernel”行,按下e键开始编辑。

root (hd0,0)
kernel /vmlinuz-2.6.18-1.2239.fc5smp ro root=LABEL=/
initrd /initrd-2.6.18-1.2239.fc5smp.img

4. 一个grub edit器出现,通过方向键移动到行最后面,然后在行后添加“single”,中间用空格隔开。 把

grub edit> kernel /vmlinuz-2.6.18-1.2239.fc5smp ro root=LABEL=/

修改为

grub edit> kernel /vmlinuz-2.6.18-1.2239.fc5smp ro root=LABEL=/ single

5. 按下enter回车键保存修改,按下b键开始“boot”启动。

6. 系统继续启动,但将直接进入root#提示符下,没有用户名和密码的询问。

从单用户模式转入默认运行级别

exit命令强制系统退出runlevel 1,转入系统默认的runlevel。也可以通过使用init命令(如init 3和init 5)选择默认行为:

bash-2.05b# exit
INIT: Entering runlevel: 3
...
...
...
Fedora Core release 2 (Tettnang)
Kernel 2.6.8-1.521 on an i686
bigboy login:

Root密码恢复

有时你可能会忘记root密码,或者先前的系统管理员调到一个新工作但密码并没有给你。通过下面的步骤恢复密码:

  1. 到VGA控制台,按下 Ctrl-Alt-Del键.系统将会正常关闭。
  2. 重新启动系统,进入单用户模式。
  3. 在命令提示符下,修改密码。单用户模式下鉴定控制台下的用户为系统管理员的root,因此不用指定root用户名。
  4. 使用exit命令返回到默认runlevel。

启动和停止守护进程

对于守护进程,一个比较简单的定义是:守护进程是一种即使没有人登录进入你的系统也会在无人值守的情况下运行的程序。比较常见的守护进程有syslog 守护进程用于收集系统出错信息并将其写入日志文件; 还有 apachehttpd 守护进程用于为互联网浏览器提供所需浏览的网页以及sendmail 守护进程用于将服务器所收到的电子邮件推送至你的收件箱。

位于/etc/init.d目录下的启动脚本管理着随Linux包安装的守护进程的活动状态,启动和停止命令对于所有这些脚本是通用的。

启动守护进程

如果在 /etc/init.d 目录中存在一个启动脚本,那么它的守护进程将通过指定它的文件名并在后面加上关键词“start”的方式启动,如以下显示:

root@u-bigboy:~# /etc/init.d/apache start
 * Starting apache 1.3 web server...
   ...done.
root@u-bigboy:~#

停止守护进程

守护进程可以通过指定它的文件名并在后面加上关键词“stop”的方式停止;

root@u-bigboy:~# /etc/init.d/apache stop
 * Stopping apache 1.3 web server...
   ...done.
root@u-bigboy:~#

重启守护进程

通常情况守护进程只在启动时读取相应的配置文件,因此,如果你改写它的配置文件,为了使其生效,你将不得不重启守护进程。带有关键词“restart”的命令将帮你实现重启操作:

root@u-bigboy:~# /etc/init.d/apache restart
 * Restarting apache 1.3 web server...
   ...done.
root@u-bigboy:~#

别为配置你的守护进程担心。稍后我们将介绍一些常用的守护程序并通过一些简单的例子来具体了解它们。

关于服务命令

一些操作系统例如:Fedora 和 Rathat 也同样具有快捷的服务命令,允许你使用 "start", "stop" 和"restart" 这些关键词来控制守护进程, 但是使用更少的字符。 这里是一些实现该功能的快捷的,直观的例子:

[root@bigboy ~]# service httpd start
[root@bigboy ~]# service httpd stop
[root@bigboy ~]# service httpd restart

服务命令同样也具有“status”这个关键字,用来提供一个关于守护进程目前工作的简洁的报告。

[root@bigboy ~]# service httpd status
httpd (pid 6135 6133 6132 6131 6130 6129 6128 6127 1561) is running...
[root@bigboy ~]#

在各个运行级别上使用chkconfig命令启动守护进程

正如先前所说, chkconfig命令行可以用来调节程序在哪个运行级别启动.你可以使用这个命令带 --list 参数来列出/etc/init.d下的包列表以及其在各个运行级别上是运行还是停止:

[root@bigboy tmp]# chkconfig --list
keytable 0:off 1:on  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
syslog   0:off 1:off 2:on  3:on 4:on  5:on 6:off
gpm      0:off 1:off 2:on  3:on 4:on  5:on 6:off
kudzu    0:off 1:off 2:off 3:on 4:on  5:on 6:off
wlan     0:off 1:off 2:on  3:on 4:on  5:on 6:off
sendmail 0:off 1:off 2:off 3:on 4:off 5:on 6:off
netfs    0:off 1:off 2:off 3:on 4:on  5:on 6:off
network  0:off 1:off 2:on  3:on 4:on  5:on 6:off
random   0:off 1:off 2:on  3:on 4:on  5:on 6:off
...
...


chkconfig举例

你可以使用chkconfig来为一个包改变运行级别.这里你会看到sendmail在运行级别3或5中常规启动.让我们把sendmail改成不在系统启动时运行.

用chkconfig来得到sendmail的当前运行操作列表

chkconfig命令可以和grep结合使用,来确定sendmail在哪个运行级别可以运行.我们看到这里它可以行动在级别3和5.


[root@bigboy tmp]# chkconfig --list | grep mail
sendmail 0:off 1:off 2:off 3:on 4:off 5:on 6:off
[root@bigboy tmp]#

用命令行工具来获得邮件服务器当前启动项的列表

命令行工具和文档搜索工具的配合使用可以让你决定邮件服务器的运行等级. 下面的命令可以让邮件服务器运行在3级和5级.


[root@bigboy tmp]# chkconfig --level 35 sendmail off
[root@bigboy tmp]#

使sendmail不在运行级别3和5启动

chkconfig带--level参数可以指示在该运行级别上的相关操作.命令中的第一个参数是你相设置的包的名称第二个参数则让你选择是on或off.在这里我们使sendmail不要在运行级别3和5中启动:

[root@bigboy tmp]# chkconfig --level 35 sendmail off
[root@bigboy tmp]#

如果没有指定--level后的运行级别,chkconfig会在运行级别3,5上作自动修改.

[root@bigboy tmp]# chkconfig sendmail off 

因为是要永久的关闭sendmail,我们当然要关闭正在运行的sendmail.

[root@bigboy tmp]# service sendmail stop
Shutting down sendmail: [  OK  ]
Shutting down sm-client: [  OK  ]
[root@bigboy tmp]#

对邮件服务器不能启动的检查

我们可以使用chkconfig命令来检查

[root@bigboy tmp]# chkconfig --list | grep mail
sendmail 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@bigboy tmp]#

重新启动邮件服务器

为了让邮件服务器恢复功能, 我们可以再次使用chkconfig命令,不过用的是on参数. 再一次启动邮件服务器以让它立即运行, 而不是傻傻地等到系统的重新启动.

[root@bigboy tmp]# chkconfig sendmail on
[root@bigboy tmp]# chkconfig --list | grep mail
sendmail 0:off 1:off 2:off 3:on 4:off 5:on 6:off
[root@bigboy tmp]# service sendmail start
Starting sendmail: [  OK  ]
Starting sm-client: [  OK  ]
[root@bigboy tmp]#

使用命令行工具来提高系统的安全性

一个Fedora安装程序不会自行启动一些对于一个网络服务器来说并不需要的保护程序。这可能造成的结果就是你的系统被无数恶意TCP/IP端口监听,而这可能会为黑客的攻击大开方便之门

屏幕上会显示出网络状态--下面的命令就是一个典型的例子。有些端口相对容易去识别. TCP 端口25和22分别是邮件和远程登录协议, 但是其它的就不是那么明显了. 你会用位于 /etc/init.d 目录树中的命令和脚本 去把它们永久关闭吗?

[root@bigboy tmp]# netstat -an
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address
State
tcp    0    0 0.0.0.0:32768    0.0.0.0:*     LISTEN
tcp    0    0 127.0.0.1:32769  0.0.0.0:*     LISTEN
tcp    0    0 0.0.0.0:111      0.0.0.0:*     LISTEN
tcp    0    0 127.0.0.1:631    0.0.0.0:*     LISTEN
tcp    0    0 127.0.0.1:25     0.0.0.0:*     LISTEN
tcp    0    0 :::22            :::*          LISTEN
udp    0    0 0.0.0.0:32768    0.0.0.0:*
udp    0    0 0.0.0.0:930      0.0.0.0:*
udp    0    0 0.0.0.0:68       0.0.0.0:*
udp    0    0 0.0.0.0:111      0.0.0.0:*
udp    0    0 0.0.0.0:631      0.0.0.0:*
...
...
[root@bigboy tmp]#

例如,你怎么知道哪个启动脚本是针对TCP端口111的? 答案就是用lsof命令让系统列出所有被打开的和被频繁使用的文件,同时还可以通过进一步的设置将它的处理范围扩展到TCP/IP协议栈。

下面我们分别来看看portmap、xinetd和ntp守护进程对TCP端口111、32769和UDP端口123的使用。portmap守护进程是NFS和NIS(关于NFS和NIS请参考第29章"Remote Disk Access with NFS"和第30章"Configuring NIS")操作所必须的。portmap存在很多已知的安全问题,建议在安全网络内运行。如果你不需要这些应用程序,最好关闭portmap。NTP(具体请看第24章 "The NTP Server")要求将你的系统时间与时间源同步,这可能是必须的。很多网络应用依赖于xinetd,如第16章"Telnet, TFTP, and xinetd"所述,xinetd是这些应用程序正常运行所必须的:

[root@ bigboy tmp]# lsof -i tcp:111
COMMAND  PID USER   FD   TYPE DEVICE SIZE NODE NAME
portmap 1165  rpc    4u  IPv4   2979       TCP *:sunrpc (LISTEN)
[root@ bigboy tmp #
 
[root@bigboy tmp]# lsof -i tcp:32769
COMMAND  PID USER   FD   TYPE DEVICE SIZE NODE NAME
xinetd  1522 root    5u  IPv4   2764       TCP probe-001:32769 (LISTEN)
[root@bigboy tmp]#
 
[root@bigboy root]# lsof -i udp:123
COMMAND  PID USER   FD   TYPE DEVICE SIZE NODE NAME
ntpd    1321  ntp    4u  IPv4   3390       UDP *:ntp
...
...
[root@bigboy root]#

有时候通过lsof命令查看应用程序是比较棘手的。在下面的例子中,我们发现TCP端口32768被rpc.statd占用,而/etc/init.d目录下没有rpc.statd文件。简单的解决方法是用grep命令在/etc/init.d目录下的所有文件中查找"rpc.statd"字符串,从而找出对应的文件。很快,我们发现nfslock守护进程使用rpc.statd。如果你不需要nfslock,就把它永久性关闭吧。

[root@bigboy tmp]# lsof -i tcp:32768
COMMAND    PID    USER   FD   TYPE DEVICE SIZE NODE NAME
rpc.statd 1178 rpcuser    6u  IPv4   2400       TCP *:32768 (LISTEN)
[root@bigboy tmp]# ls /etc/init.d/rpc.statd
ls: /etc/init.d/rpc.statd: No such file or directory
[root@bigboy tmp]# grep -i statd /etc/init.d/*
/etc/init.d/nfslock:[ -x /sbin/rpc.statd ] || exit 0
...
...
[root@bigboy tmp]#

根据经验,只监听本地回路接口 (IP地址为127.0.0.1)的应用程序通常不易受网络攻击影响,无须为安全原因而将其停止。而那些监听所有接口,如IP地址为0.0.0.0的应用程序,自然很容易受到网络攻击,其关闭与否取决于你的服务器的需要。我的习惯做法是关闭Internet服务器上的nfs、nfslock、netfs、portmap和cups打印服务,保留sendmail服务,因为邮件的收发总是必需的(具体请看第21章"Configuring Linux Mail Servers"),你的需求可能和我不一样。

在关闭应用程序之前务必周密地考虑你的需求。你可以通过Linux用户手册、参考书或者Internet获取更多与应用程序相关的信息。不可预料的结果是我们都不希望看到的。

关闭应用程序只是保障服务器安全的一个环节。防火墙、物理访问限制、密码策略和补丁更新也是保障服务器安全所必须考虑的。关于服务器和网络安全的详细讨论已经超出了本书的范围,在此不做赘述,不管怎样,你手头上必须有一些安全参考手册以供不时之需。

chkconfig小贴士

记住:

  • 在大多数情况下,你必须同时修改运行级别为3和5的配置且配置结果要一致。
  • 不要添加/删除其他运行级别的任何东西,除非你很清楚地知道你在做什么。不要试图体验,除非在测试环境中。
  • chkconfig不会启动/etc/init.d目录下的任何项目,它只是编辑它们是否随系统启动。启动和停止这些项目的命令在本书各章节中分别有介绍。

用sysv-rc-conf启动各运行级别下的守护进程

在Debian/Ubuntu linux中,update-rc.d命令取代chkconfig作为默认的编辑/etc/init.d脚本链接的包。可惜该工具主要用于编辑当前安装或删除的服务链接,而对已存在的包的链接的编辑的支持很差。

不过幸运的是与chkconfig语法几乎一致的包sysv-rc-conf给苦恼的管理员带来了希望,你可以通过执行它的无参命令来启动它的GUI模式。这一节将为你展示使用sysv-rc-conf的一些重要技巧。

安装sysv-rc-conf

sysv-rc-conf包可以通过apt-get安装。如下所示:

root@u-bigboy:~# apt-get install sysv-rc-conf

列出守护进程的运行级别

这可以通过添加--list选项实现。在下面的例子中我们将列出apache守护进程的运行级别。

root@u-bigboy:~#  sysv-rc-conf  --list apache
apache       0:off      1:off   2:on    3:on    4:on    5:on    6:off
root@u-bigboy:~#

我们再来看看所有守护进程的运行级别。

root@u-bigboy:~#  sysv-rc-conf  --list
acpi-support 0:off      1:off   2:on    3:on    4:on    5:on    6:off
acpid        0:off      1:off   2:on    3:on    4:on    5:on    6:off
alsa-utils   0:off      6:off
…
…
…
vbesave      2:on       3:on    4:on    5:on
x11-common   S:on
root@u-bigboy:~#

设置守护进程的运行级别

sysv-rc-confchkconfig语法很相似。让我们来设置apache守护进程在运行级别2至5中自动启动。

root@u-bigboy:~# sysv-rc-conf  apache on

同样,我们可以通过以下命令设置apache在运行级别2至5中不启动:

root@u-bigboy:~# sysv-rc-conf  apache off

最后,我们设置apache只在运行级别3和5中启动。

root@u-bigboy:~# sysv-rc-conf  --level 35 apache on

总结

本章所谈论的话题看似简单,但它和第5章"Troubleshooting Linux with syslog"中谈到的syslog一样,是Linux管理的基础,通常会被忽略,特别是新软件安装时。

只要有可能,尽量重启一下你的系统以确保新安装的应用程序的正常运行。有时它们启动后只将错误写入/var/log目录。花点时间配置并测试一下你的启动脚本可以避免你在休假时被半夜叫醒!这的确是很重要的。