Linux core-level system services

Source: Internet
Author: User
Tags syslog

As long as it is a Linux system, regardless of the release version, network configuration, and global system design, there are several core system services: init, inetd, syslogd, and cron. These services provide simple functions, but they are also the basis for other operations. Without them, Linux would not have the power of the present.

This article will introduce each core system service, corresponding configuration files, and recommended application methods (if any) one by one. We strongly recommend that you take some time to familiarize yourself with the implementation principles of these services. By using these services, people have already designed many creative problem solutions.

Init Service

The init process is the initiator and controller of all processes. In any Unix-based system (such as Linux), The init Process ID (PID) is always 1. If there is a problem with init, the rest of the system will collapse.

The init process has two functions. The first role is to play the role of ending the parent process. Because the init process will never be terminated, the system can always be sure of its existence and take it as a reference when necessary. If a process is terminated before the end of all its child processes, the init must be used as a reference. At this time, all child processes that have lost their parent processes will use init as their parent processes. Run the ps-af command to list the processes whose Parent Process ID (PPID) is 1.

The second role of init is to run the corresponding program when entering a specific Runlevel to manage various running levels. This function is defined by the/etc/inittab file.

1./etc/inittab File

The/etc/inittab file contains all the information required for the init startup and running level. The format of each statement in this file is as follows:

Id: runlevels: action: process

Note: The statement starting with # Is a comment statement. Look at your own/etc/inittab file and you will find that it is filled with a large number of comment statements. If you do need to make any changes to the/etc/inittab file (this is generally not the case), remember to add some comments to explain why you need to make those changes.

2. Telinit command

The mysterious force that notifies init when to switch the system running level is actually the Telinit command. This command has two command line parameters: one parameter is used to notify init to switch the previous running level; the other is-tsec, among them, the sec is the time to wait in seconds before notifying init.

Note: It is up to you to determine whether or not init really switches the running level. Obviously, it often switches, otherwise this command will not be so useful. In most Unix operating systems (including Linux), The Telinit command is actually a symbolic link to the init program. Based on this, many people prefer to use init to directly switch to the running level they want instead of Telinit. Personally, I found that using Telinit to switch the running level is easier to understand and remember.

Inetd process

The inetd program is a daemon. You may already know that daemon are special programs that voluntarily give up control of calling their own terminals after being started. The interfaces of the daemon and the rest of the system can send data items only through Interprocess Communication (IPC) channels or to the system global Log File.

The role of inetd is a "super server" for processes related to network servers such as Telnet and FTP ". This is a simple principle: not all server processes (including those that accept new Telnet and FTP connections) are called so frequently, so that a program must be running in the memory at any time. Therefore, to avoid the possibility that dozens of services are running in the memory to be used, they are all listed in the inetd configuration file/etc/inetd. conf. Instead, inetd listens for incoming connections. In this way, you only need to have a process in the memory.

Another advantage of inetd is that programmers do not want to write processes that require network connection to the system. The inetd program processes network code and transmits the incoming network data stream to the process as Standard-In (Stdin. The output (Stdout) of these processes will be sent back to the host that is connected to the process.

Note: Unless you are programming, you do not need to connect to the Stdin/Stdout function of inetd. On the other hand, if someone intends to write a simple command script program and make it appear on the network, it is worth further research into this extremely powerful function.

1. etc/inetd. conf file

The etc/inetd. conf file is the configuration file of inetd. Its structure is simple: each line of statements represents a service. The format of the service definition statement is as follows:

Srvce_name sock_type protocol [no] wait user srvr_prog srvr_prog_args

2. Security and inetd. conf files

You will find that many services are enabled by default in most Linux installations. If your system is open to the Internet (including connections through the dial-up Point-to-Point Protocol), the first thing you want to do is to turn everything off! Never assume that no one else will find it because your system does not publicize the public. In the opposite direction, it is easy to find and use tools and software that have security attack risks.

The first step to disable the service is to change all unnecessary service description statements in the etc/inetd. conf file to annotation statements.

In general, you will find that the following method is easier to use: first, change everything to a comment Statement (completely disable the network service), and then select the desired service.

After modifying the etc/inetd. conf file, you need to report to the daemon that the configuration file has been modified. This is achieved by sending an HUP signal to the daemon. First, use the following command to find the process ID corresponding to inetd. conf:

[Root @ ford/root] # ps auxw | grep inetd | grep-v grep

The output of this command is similar to the following:

Root 359 0.0 0.1 1232 168? S Jun21 0: 00 inetd

The second column in the output shows the process ID (359 ). To send the HUP signal, we need to use the Kill command (the number of Kill called by this program is somewhat misleading. In fact, it only sends signals to the process. By default, it sends a request to terminate a program ).

The following describes how to use the Kill command to send the HUP signal:

$ Kil-1 359

Replace "359" in the preceding command with the process number obtained from your system.
Syslogd daemon

A lot of things will happen at the same time, especially for network services that are disconnected in the terminal window. Therefore, it is necessary to provide a standard mechanism for recording special events and messages. Linux uses the syslogd daemon to provide this service.

The syslogd daemon provides a standard method for recording system activities and messages. Many other types of Unix operating systems also use compatible daemon. This provides a method for cross-platform recording in the network. In a large network environment, this is more valuable. In such an environment, it is necessary to collect various records of data in order to obtain the accuracy of system operation. You can compare this logging subsystem to the SystemLogger of Windows NT.

The record files used by syslogd to store data are concise text files, which are generally stored in the/var/log subdirectory. Each data item forms a line, including the date, time, host name, process name, process PID, and messages from the process. A global function in the Standard C function library provides a simple mechanism for generating and recording messages. If you do not like writing program code but want to generate data items in the record file, you can use the Logger command. As you can imagine, an important tool like syslogd should be started as part of the boot command script program. Any Linux release version you want to use in the server environment has been set for you.

1. Call syslogd

If you need to manually start syslogd, or modify the command script program to start it during boot, you must pay attention to the command line parameters of syslogd. Please refer to the relevant books for details.

2./etc/syslog. conf file

The/etc/syslog. conf file contains the configuration information required to run syslogd. The format of this file is somewhat unusual, but the existing default configuration file is enough to meet your needs, unless you need to find specific information in a specific file, or you need to send the information to the remote recording computer.

● Record information classification

Before learning about the format of the/etc/syslog. conf file, you must first understand how messages are classified. Each message has a function value (Facility) and a Priority value (Priority ). The function value tells us which subsystem generates the message, and the priority value tells us how important the message is. These two values are separated by periods and both have equivalent strings, making them easy to remember.

●/Etc/syslog. conf file format

The format of each statement in the configuration file is as follows:

Facility/priority combinations separated by commas file
/Process/host to log

Example:

Kern.info/ver/log/kerned

Syslogd can also flexibly send recorded messages to different storage destinations. It can save messages as files, send messages to FIFO queues, send messages to a group of users, or (when messages are recorded in a large site) send messages to a central record host. To differentiate these destinations, the following rules are used at the destination entry:

◆ If the start character of the destination is a slash (/), the message is sent to a file.

◆ If the start character of the destination is vertical (|), the message is sent to a FIFO queue.

◆ If the start character of the destination is "@", the message will be sent to a host.

The cron program allows any user in the system to schedule a program to run on time at any date and time, accurate to minutes. Using cron is an extremely effective method that enables your system to generate reports automatically, periodically, and execute other scheduled tasks. Like other services we have discussed in this article, cron is started by the boot command script program and should have been configured. A quick check on the process list shows that it is running silently in the background. The principle of the cron service is to wake up every minute and check the crontab file of each user. The content of this file is a list of activities that the user wants to execute at specific times. Any activity that matches the current date and time will be transferred for execution.

The cron command itself does not require any command line parameters, and does not require any signal to indicate its status changes. The crontab tool is used to edit the settings executed by cron. The principle is to verify whether you have the permission to modify cron settings, and then call a text editor to modify the settings. After the modification is complete, crontab places the file in the correct position and takes you back to the prompt.

Whether you have proper permissions is determined by crontab checking the files/etc/cron. allow and/etc/cron. deny. No matter which of the two files exists, your operations can take effect only when you explicitly column them. For example, if the/etc/cron. allow file exists, you can edit cron data items only when your user name is listed in this file. If/etc/cron. the deny file exists and/etc/cron. the Allow file does not exist. If your user name does not appear in this file, it indicates that you are allowed to edit your cron data items.

The format of the cronjobs file (usually the crontab file) is as follows: minute hour day month dayofweek command. All values must be integers.

If you want to set multiple values in a column (for example, you want to run the same program three times in the morning at, noon at, and afternoon ), these time data must be separated by commas (,) in the corresponding column, but no space can be added to this column. The data items in the Hour column should be 4, 12, and 17 if the same program needs to be run three times in the morning: 00, 12: 00, and 5: 00.

In the DayOf Week data item, 0 indicates Sunday, 1 indicates Monday, and so on, until 6 indicates Saturday. If a data item contains an asterisk (*) wildcard, it indicates that any minute, hour, date, month, or day of the week in the corresponding column matches. When the date and time in the file meet the current date and time, the command set in this statement runs as the user who sets the data item, any output will be returned to that user by email. Obviously, this may cause the message in the mailbox to fill up, so it is important to quickly respond to the mail report. A good way to control the message volume is to output only errors, and other inevitable outputs are sent to the/dev/null device.

Let's look at some examples. The following data items run the/usr/bin/ping zaphod command every four hours:

0, ***/usr/bin/ping zaphod

The following data items run the program/usr/local/scripts/backup-level-0 at 10: 00 every Friday evening:

0 22 ** 5/usr/local/scripts/backup_level_0

Finally, the following data item sent an email at a.m. on April 9, April 1 (no matter the day of the week:

1 4 1 4 */bin/mail dad@domain.com

This article discusses four core services required for each Linux system. These services do not require network support and will change with the host. This makes them very useful, because they can work well no matter whether the computer system is in multi-user mode or not.

From: ccidnet

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.