Introduction to system services under Linux - init, systemd

齐天大圣
Release: 2020-11-10 14:04:58
Original
2382 people have browsed it

We often hear the words service and daemon. What do they mean? Are there any differences and connections between them? Services under Linux are programs that reside in memory and can provide some system or network functions. The literal translation of daemon is daemon process or background process. So, you can regard service and daemon as the same thing without distinguishing them.

Early init management mechanism

In centOS6, the init service management mechanism was still used. Here is a brief introduction, because some things can still be used in centOS7. Mainly look at the following features:

Starting, shutting down and status checking of services, etc.

  • Start the service: /etc/init.d/ nginx start

  • Restart the service: /etc/init.d/nginx restart

  • Close the service: /etc/init.d/nginx stop

  • Status view: /etc/init.d/nginx status

Service startup method

  • Independent startup: Most services adopt this mode, such as common mysqld, php-fpm, nginx, httpd and other services.

  • Hosted and started by super daemon: The startup of these services is hosted by another service. The service that hosts these services becomes super daemon. Common super daemons include inetd and xinetd

Execution Level

There are 7 execution levels on Linux, which are 0, 1, 2, 3, 4, 5, and 6. Commonly used ones are

  • 1 Single-player maintenance mode

  • 3 Plain text mode

  • 5 Graphics Mode

The startup scripts of each execution level are linked to /etc/init.d/daemon through /etc/rc[0-6].d/SNNdaemon.

ll /etc/rc3.d/S55nginx lrwxrwxrwx 1 root root 15 Sep 21 11:30 /etc/rc3.d/S55nginx -> ../init.d/nginx
Copy after login

S means startup, and NN means numbers. These numbers indicate the execution order of the script. The smaller the number, the first it will be executed. This execution order can well manage service dependencies.

Auto-start service at boot

  • Auto-start at boot: chkconfig on deamon

  • Close and enable auto-start Start: chkconfig off deamon

  • Check whether the service has been started: chkconfig --list daemon

##systemd management mechanism

Since centos7, the previous init management mechanism has been abandoned and systemd has been used instead. Let's take a look at what's different about systemd management.

Process all services in parallel to speed up the boot process.

Unlike init which starts services one by one, systemd can start many services at the same time. Therefore, this will greatly speed up the waiting time for booting.

Resolve service dependencies

For example, to start service B, you must first start service A. At this time, use systemd to start service B, and it will automatically check Dependency, then start service A before starting service B.

unit type

Compared with stand alone and super daemon, which have only two startup methods in init, systemd defines a unified service unit (unit), and unit Divided into: service, socket, target, path, snapshot, timer and other types.

Backwards compatible init service script

The old service startup script under /etc/inid.d/ can also be managed through systemd. Note: If you manually start the service startup script in the /etc/init.d directory, systemd will not be able to detect the running status of the service.

# systemctl status mysqld ● mysqld.service - LSB: start and stop MySQL Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled) Active: active (running) since Wed 2020-10-28 13:26:53 CST; 1 weeks 5 days ago …… # /etc/init.d/mysqld restart Shutting down MySQL.... [ OK ] Starting MySQL. [ OK ] [root@lijia ~]# systemctl status mysqld ● mysqld.service - LSB: start and stop MySQL Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled) Active: active (exited) since Wed 2020-10-28 13:26:53 CST; 1 weeks 5 days ago ……
Copy after login
Regarding init and systemd, we need to focus on mastering systemd, and we also need to understand init.

The above is the detailed content of Introduction to system services under Linux - init, systemd. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!