Difference between revisions of "Configuring RHEL 5 Runlevels and Services"

From Techotopia
Jump to: navigation, search
(New page: In order to gain proficiency in Red Enterprise Linux 5 system administration it is important to understand the concepts of runlevels and services. The goal of this chapter, therefore, is t...)
(No difference)

Revision as of 19:47, 28 July 2010

In order to gain proficiency in Red Enterprise Linux 5 system administration it is important to understand the concepts of runlevels and services. The goal of this chapter, therefore, is to provide a basic overview of the different runlevels supported by RHEL 5 combined with an overview of how to configure the services that start at each level.


Contents


Understanding RHEL Runlevels

RHEL 5 can be configured to boot into one of a number of different runlevels. During the boot sequence, a process named init looks in the /etc/inittab file to find the default runlevel. Having identified the runlevel it proceeds to execute the corresponding startup scripts located in the /etc/rc.d sub-directory.

For example if a default runlevel of 5 is configured then the init process will work through the list of startup scripts located in /etc/rc.d/rc5.d. These startup scripts start either with the letter "S" or "K" followed by a number and then a (hopefully) descriptive word. For example the startup script for NFS (Networked File System) is typically K20nfs whilst the startup script for the sshd service might be called S55sshd.

Scripts that start with an "S" are invoked before those prefixed with a "K". The number in the filename controls the order in which the script will be executed with that group (either "S" or "K"). You wouldn't, for example, want to start NFS before the basic networking is up and running. It is also worth noting that the files in the rc.d sub-directories are not the actual scripts themselves but rather symbolic links to the actual files located in /etc/rc.d/init.d.

Understanding RHEL Services

A service is essentially a process that typically runs in the background to provide specific functionality. The sshd service, for example, is the background process (also referred to as a daemon) that provides secure shell access to the system. Different runlevels are configured to automatically launch different collections of services, depending on the functionality that is to be provided at that particular level.


RHEL Runlevels Descriptions

As previously outlined, RHEL 5 can be booted into one of a number of runlevels. The default runlevel to which the system is configured to boot will, in turn, dictate which services are started:

  • Runlevel 0 - The halt runlevel. This is the runlevel at which the system shuts down. For obvious reasons it is unlikely you would want this as your default runlevel.
  • Runlevel 1 – Causes the system to start up in a single user mode under which only the root user can log in. In this mode the system does not start any networking, X windowing or multi-user services. This run level is ideal for system administrators to perform system maintenance or repair activities.
  • Runlevel 2 - Boots the system into a multi-user mode with text based console login capability. This runlevel does not, however, start the network.
  • Runlevel 3 - Similar to runlevel 2 except that networking services are started. This is the most common runlevel for server based systems that do not require any kind of graphical desktop environment.
  • Runlevel 4 - Undefined runlevel. This runlevel can be configured to provide a custom boot state.
  • Runlevel 5 - Boots the system into a networked, multi-user state with X Window System capability. By default the graphical desktop environment will start at the end of the boot process. This is the most common run level for desktop or workstation use.
  • Runlevel 6 - Reboots the system. Another runlevel that, for obvious reasons, you are unlikely to want as your default.

Configuring the Default RHEL Runlevel

The default runlevel for an RHEL system is defined within the /etc/inittab file. To identify the current default level or change the default to a different setting, load this file into an editor (keeping in mind that root privileges will be required).

The relevant section of a sample /etc/inittab file is as follows:

# 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:

The key line in the example above is the initdefault setting:

id:3:initdefault:

This tells the init process that the default run level for the system is runlevel 3. To change to a different run level simply change the number to the desired runlevel and save the /etc/inittab file.

Changing the Current Runlevel from within a Running RHEL System

The current runlevel of a running RHEL system can be changed using the init command combined with the new target runlevel. For the sake of an example, assume that an RHEL system is currently running at runlevel 3. In order to change to level 5 (thereby activating the desktop environment), the following init command would need to be executed at the command-line prompt:

init 5

The desktop environment will then start up and the login screen will be displayed.

Identifying Services that Start at Each Runlevel

There are number of ways to identify which services get started without having to delve into the /etc/rc.d sub-directories. The command line tool chkconfig (usually located in the /sbin directory) can be used to list which services get started at boot time. To list all service settings run the following command:

/sbin/chkconfig --list

This will display a long list of services showing whether or not they are started up at various runlevels. You may want to narrow the search down using the grep tool. For example to list the entry for the sshd daemon, execute the following command:

/sbin/chkconfig --list | grep sshd

When run, the above command should result in something output similar to the following:

sshd           0:off   1:off   2:on   3:on    4:on   5:on    6:off

The above output indicates that the sshd service is started automatically at runlevels 2, 3, 4, and 5. Alternatively you may just be interested to know which services get started for runlevel 3:

/sbin/chkconfig --list | grep '3:on'

Changing the Services for a Runlevel

In addition to listing services, chkconfig can also be used to change the settings for a particular runlevel. If, for example, we wanted the httpd service to start up at runlevel 5 we would issue the following command:

/sbin/chkconfig --level 5 httpd on

A number of graphical tools are also available for administering services. On RHEL you can select the System -> Administration -> Server Settings -> Services menu option or run the following command:

system-config-services

The above graphical tool allows you to view which services will start for each runlevel, add or remove services for each runlevel and also manually start or stop services.