Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Linux+ Certification Bible.pdf
Скачиваний:
46
Добавлен:
15.03.2015
Размер:
3.78 Mб
Скачать

Chapter 11 Linux System Commands 357

The Linux system administrator is responsible for the day-to-day operations of the Linux server. This chapter deals with some basic Linux system commands and services that administrators use in their daily tasks. One of the administrator’s

most important responsibilities is to stop, start, and restart services and daemons when needed. Configuring these services to automatically start at boot time involves an intricate knowledge of the different runlevels and startup scripts that Linux uses to maintain the system. This chapter also deals with setting up print spools and queues, which are very common tasks. tar and vi are also discussed in great detail.

Linux Runlevels

4.13 Manage runlevels using init and shutdown

Linux systems operate in different types of runlevels. A runlevel is a certain mode of operation for a system, which defines the services and processes that start for that particular runlevel.

As a Linux system boots, one process must be the first to start in order to be able to startup all other processes, daemons, and system-critical programs. This first process is called init.

init

init is the first process on a Linux system and is assigned a PID (Process Identification) of 1. The operating system kernel starts init and is responsible for starting all other services provided by the system. The services started by init are detailed in its configuration file, which is located in /etc/inittab.

The inittab file, located in /etc, is the primary configuration file for the init process. The inittab file controls how your system starts up and configures the different runlevels.

The following is a sample of an inittab file:

#

# inittab This file describes how the INIT process should set # up the system in a certain run-level.

#

 

# Author:

Miquel van Smoorenburg,

#Modified for RHS Linux by Marc Ewing and

#

Donnie Barnes

#

 

#Default runlevel. The runlevels used by RHS are:

#0 - halt (Do NOT set initdefault to this)

#1 - Single user mode

358 Part IV Administration

#

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:

#System initialization.

si::sysinit:/etc/rc.d/rc.sysinit l0:0:wait:/etc/rc.d/rc 0 l1:1:wait:/etc/rc.d/rc 1

l2:2:wait:/etc/rc.d/rc 2 l3:3:wait:/etc/rc.d/rc 3 l4:4:wait:/etc/rc.d/rc 4 l5:5:wait:/etc/rc.d/rc 5 l6:6:wait:/etc/rc.d/rc 6

#Things to run in every runlevel. ud::once:/sbin/update

#Trap CTRL-ALT-DELETE ca::ctrlaltdel:/sbin/shutdown -t3 -r now

#When our UPS tells us power has failed, assume we have a # # few minutes of power left. Schedule a shutdown for 2

#minutes from now.

#This does, of course, assume you have powerd installed and # your UPS connected and working correctly.

pf::powerfail:/sbin/shutdown -f -h +2 “Power Failure; System Shutting Down”

#If power was restored before the shutdown kicked in, cancel # it. pr:12345:powerokwait:/sbin/shutdown -c “Power Restored; Shutdown Cancelled”

#Run gettys in standard runlevels

1:12345:respawn:/sbin/mingetty tty1 2:2345:respawn:/sbin/mingetty tty2 3:2345:respawn:/sbin/mingetty tty3 4:2345:respawn:/sbin/mingetty tty4 5:2345:respawn:/sbin/mingetty tty5 6:2345:respawn:/sbin/mingetty tty6

# Run xdm in runlevel 5 x:5:respawn:/usr/bin/X11/xdm -nodaemon

The most important line in this file is:

id:3:initdefault:

Chapter 11 Linux System Commands 359

This line sets the default runlevel to 3. Therefore, when your Linux system starts, it will always boot into that runlevel.

Never set your default runlevel as 0, which halts the system. If you do, your Linux system will automatically shut down when booted up!

You can set a number of other default runlevels, which are summarized in Table 11-1.

Table 11-1

Linux Runlevels

Runlevel Description

0Halt the system.

1Single user mode. All file systems mounted, only small set of kernel processes running. Only root can login.

2Multi-user mode, without remote file sharing.

3Multi-user mode with remote file sharing, processes, and daemons.

4User definable system state.

5Used to start X-windows on boot.

6Shutdown and reboot.

To initiate a runlevel from the command prompt, simply enter the following command:

init [runlevel]

To bring your system to a halt, use the following command:

init 0

Most systems have their default runlevel set to 3 because they usually don’t need X windows to run. If you want your system to boot and start X windows, set the default runlevel to 5 by modifying the default runlevel entry to:

id:5:initdefault:

Know all of the characteristics of each runlevel, and when they should be used.

360 Part IV Administration

Login terminals

This section of the inittab file defines your terminal login sessions:

# Run gettys in standard runlevels 1:12345:respawn:/sbin/mingetty tty1 2:2345:respawn:/sbin/mingetty tty2 3:2345:respawn:/sbin/mingetty tty3 4:2345:respawn:/sbin/mingetty tty4 5:2345:respawn:/sbin/mingetty tty5 6:2345:respawn:/sbin/mingetty tty6

Startup scripts

This section of the inittab file defines the location for your startup scripts for each runlevel:

# System initialization.

si::sysinit:/etc/rc.d/rc.sysinit l0:0:wait:/etc/rc.d/rc 0 l1:1:wait:/etc/rc.d/rc 1

l2:2:wait:/etc/rc.d/rc 2 l3:3:wait:/etc/rc.d/rc 3 l4:4:wait:/etc/rc.d/rc 4 l5:5:wait:/etc/rc.d/rc 5 l6:6:wait:/etc/rc.d/rc 6

The /etc/rc.d directory contains several subdirectories named after the runlevel that they represent. Each subdirectory contains scripts that are run for that particular runlevel. These scripts start a number of services and also perform a number of configuration checks, including checking the disk file systems for errors, mounting the file systems, defining swap space, cleaning out temporary files, and starting up system daemons.

Each directory contains several scripts starting with the letter “S” or the letter “K.” These letters represent start and kill scripts. Depending on your current runlevel and the runlevel that you want to switch to, the system must determine which processes need to be killed and which ones need to be started.

For example, the following are some of the scripts within the /etc/rc.d/rc 3 directory:

K20nfs

K34yppasswdd

S10network

S30syslog

S60lpd

S99linuxconf

As the system switches to runlevel 3, the K20nfs will kill the nfs process, and the S10network script will start the network services.

Соседние файлы в предмете Операционные системы