Linux series (17) of system services

We know, after we landed Linux, the system provides us with many services, such as routine scheduling service crond, print services, mail services. So how are these services to start it?

The first question put about, let's first look at the Linux boot process.

1.Linux system startup

Start the process is divided into five stages: the kernel boot, run the init process, system initialization, the establishment of the terminal, the user login system.

1. kernel boot

When computer power is turned on, first the BIOS POST, the BIOS boot device in accordance with the set (typically a hard disk) to start. After the operating system to take over the hardware, first read into the kernel files in the / boot directory.

 

 2. Run the init

The init process is the starting point for all process systems. Without this process, any process in the system will not start. The init process will first go read the configuration file.

init task is to run the daemon .

init types:

 

Run Level

 

 3. The system initialization

Rc.sysinit called and executed the script file in the directory /etc/rc.d in the init configuration file.

The main work is: activate the swap partition, check the disk, the hardware module is loaded and executed a number of priority tasks.

 

 Users can chkconfig or setup in the "system services" will be set for each run level which runs the daemon daemon (is the service).

4. The establishment of the terminal

5. User Login

There are three login: command line login, ssh login, login GUI.

 

 

2.systemd service management mechanism

After centOS7.x, Linux gave up the boot process SystemV use for many years, the use systemd to start the service management mechanism.

1.systemd advantage

"1" on-demand start mode immediately upon request response: systemd service is only one instruction with matching systemctl.

"2" according to the daemon Category: systemd management service is very much in order to distinguish between functions of various services, systemd each service unit is defined as a service unit, and the unit to classify different types of service (type) were to go . systemd service unit (unit) is divided into service, socket, target, path, snapshot, timer, etc., to facilitate classification and administrators memory.

"3" is backwards compatible with the old service init script.

2.systemd configuration files are placed directory

 Service startup script configuration file : / usr / lib / systemd / system /

Service script execution system generated : / run / systemd / system /

Execute the script created by the administrator : / etc / systemd / system /

 3. Type of Service

 We can type the extension of these profiles to determine the service, each service represents a file, the file name (minus the extension) is the service (process) the name .

 4. Management Services

systemd init process only one type of instruction systemctl management services.

Start services are divided into two types: boot, "current" start.

Both types of start is a big difference

1. Start with a single service management start-up and observation status

Since the service is a process, so we can use kill to manage the service, but there are drawbacks, if you use kill to kill a service, then systemctl will not continue to monitor this service ; therefore we use here systemctl to manage.

 

unit consists of two parts: the service name, extension.

Service unit unit type is distinguished, distinguished way is to add formatting after the service; for example, system service atd the unit is atd.service, such as multi-user service target type of unit is multi-user.target .

When we want to manage a service, but we only know the service name (query by top service name), but do not know how to do the extension?

We can see systemd configuration file / usr / lib / systemd / System , an extension by extension configuration file which can determine the service .

Example 1:

  Check the status of this service atd

 

 Loaded with Active two lines of information is very important, it tells us that the service is not boot from Kai, and the current status.

Services default status classification (displayed at the Loaded red line):

By default daemon addition to enable and disable, there are other types:

"1" static: This service can not start their own, but may be other types of services enable Wake (service depends on the property).

"2" mask: this service will not be started in any case! As it has been forced to write-off (non-deleted), it can be changed back to the original state by systemctl unmask way.

Service current status classification (shown in the first word after a colon Active line):

"1" active (running): n represents one or more programs being executed in the system.

"2" active (exited): represents performed only once normal end of service.

"3" active (waiting): representation being implemented, but is still waiting for other things to continue treatment.

"4" inactive: indicates that the service is currently not running.

Close Services :

Examples 1. Close chronyd.service Service

First check the status systemctl status chronyd.service, if the service is not closed, then use systemctl stop chronyd.service close the service, then use systemctl disable chronyd.service canceled automatically start at boot the service.

 

Close above there is a problem, if this service is dependent attributes exist B service, then the service B is likely to re-awaken this service.

Close the properties dependent service A regular practice:

 If you turn off the service A, A has a property and its dependent services B, which indicates that this service automatic wake-A may be dependent service attribute B; so when you want to completely turn off this service, you need to attribute dependent service B also closed .

 Close the properties dependent irregular practices in service A:

Use systemctl mask A forced cancellation of service

format:

systemctl mask unit // unit by the service name and extension type composition

System mask atd.service e.g.

When you force cancellation of service, you can not start the service, and unless systemctl unmask atd.service canceled logout.

2. systemctl on observing system for all services

The previous section is about the launch of a single service, close observation, and dependent services to logout function. How many services do exist on that system? This requires by list-units and list-unit-files be observed ! Detailed usage is as follows:

Format :

 systemctl // equivalent systemctl list-units, a promoter of the above listed system unit

systemctl --all // list all of the unit (not included with the start of the start)

systemctl list-unit-files // all listed unit installed, the installation will have the appropriate files in / usr / lib / systemd / system / directory

Other formats can be queried according to the figure.

3. By systemctl manage different operating environments (target unit)

 

Guess you like

Origin www.cnblogs.com/z-x-p/p/11643280.html