Chapter 2 daemon and inetd Superserver

Source: Internet
Author: User
Tags openlog syslog

1. daemon processes run in the background and are not controlled by terminals. Even if the daemon runs on a certain terminal, after entering the daemon status, the daemon will not be controlled by this terminal, and the terminal signal generated on the terminal, does not affect the daemon process previously started on this terminal (for example, the interrupt signal Ctrl + C)

2. Daemon startup method:

When the system starts, many daemon processes are started by the system initialization script.

Many network servers are started by inetd superservers, and iNet is started by the system initialization script.

Cron regularly executes some programs. The startup method of the cron daemon is also a script.

At command timed start

In addition, you can control the startup at the terminal.

3. the daemon has no control terminal. All printed logs are sent to the Syslog daemon.

Syslog daemon

The SYSLOG device depends on two important files: the/etc/syslogd daemon and the/etc/syslog. conf configuration file. Generally, most syslog information is written to the/var/adm or the information file (messages. *) in the/var/log directory .*). A typical syslog record includes the name of the generated program and a text message. It also includes a device and a priority range.

The basic syntax of syslog. conf is as follows:

Message type. Priority Action domain

The asterisk (*) indicates that all log messages generated by this service are sent to the location specified by the operation. Just as it acts in Rule expressions, asterisks represent "everything ". In the preceding example, "mail. *" sends all priority messages to the/var/log/mail file specified by the operation. The effect of using the "*" qualifier is exactly the same as that of using the "debug" priority. The latter will also send all types of messages to the specified location.

The equal sign (=) indicates that only log messages of this priority generated by this service are sent to the location specified by the operation. For example, you can use the "=" qualifier to send only debugging messages, instead of other more urgent messages (this reduces the burden on the application ). When you only need to send a message with a specific priority, you need to use the equal sign qualifier.

Exclamation point (!) The meaning is that all log messages generated by this service are sent to the location specified by the Operation action, but messages with this priority are not included.

The following configuration file is the syslog. conf RedHat Enterprise 5syslog configuration file.

# Log all kernel messages to the console.# Logging much else clutters up the screen.#kern.*                                             /dev/console# Log anything (except mail) of level infoor higher.# Don't log private authenticationmessages!*.info;mail.none;authpriv.none;cron.none            /var/log/messages# The authpriv file has restricted access.authpriv.*                                          /var/log/secure# Log all the mail messages in one place.mail.*                                                -/var/log/maillog# Log cron stuffcron.*                                               /var/log/cron# Everybody gets emergency messages*.emerg                                             *# Save news errors of level crit and higherin a special file.uucp,news.crit                                          /var/log/spooler# Save boot messages also to boot.loglocal7.*                                      /var/log/boot.log

Syslog Interface

In actual use, we can use syslog through the configuration file and view the corresponding log file. However, in many application scenarios, we often need to generate output information and record it through the program, that is, to write some information into a log file, under normal circumstances, people running the program do not need to care about the content in the log. They only view the content in the log file when a problem occurs to confirm the problem. Therefore, the following describes in detail how to use a program to use syslog through the API provided by the syslog log system.

1. Main Functions

In Linux, four system calls are provided for the syslog log system:

Openlog: Open the Log Device for reading and writing, similar to open called by the file system;

Syslog: writes logs, similar to the write called by the file system;

Closelog: Close the Log Device, similar to the close called by the file system;

Vsyslog: similar to syslog, it is responsible for writing logs, but the parameter format is different.

The following is an example of using the above functions to write logs for your reference:

# Include <syslog. h> # include <sys/klog. h> # include <stdio. h> int main (void) {int log_test;/* open log */openlog ("log_test", log_pid | log_cons, log_user);/* write log */syslog (log_info, "PID information, pid = % d", getpid (); syslog (log_debug, "Debug message");/* close log */closelog ();}

Inetd daemon

During network programming, we will find that the first steps are basically the same. For the server end, we will use socket, bind, listen, and accept in the same basic steps, can we make a summary of these steps? when there is an application link, we call a process link and execute the corresponding program based on the different application fork subprocesses? The answer is to only use the inetd daemon.

The inetd daemon is Linux. As a daemon process that processes requests, what we need to do is to provide it with some link, the program to be started when an interface is requested.

It is generally configured in/etc/inetd. conf.

For example:

Ftp stream tcp Nowait root/usr/bin/ftpd-l

The following is an explanation of the above parameters, one-to-one correspondence.

Service-name must be the service name defined in the/etc/services file

Socket-Tye stream (TCP) or dgram (UDP)

Protocol is not allowed to be defined in the/etc/protocols file: TCP or UDP

Wait-flag generally uses TCP as Nowait and UDP as wait

Username in login-name/etc/passwd, usually root

Full path name used by server-program Exec

Parameters Used by server-Program-arguments Exec

 

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.