Abstract: Systemd is controversial, but Fedora, SFedora, SUSE, and Rhel are all gradually invested in systemd. Are gradually invested in systemd. We will learn how to use the systemd control system to start systemd. We will learn how to use the systemd control system to start, manage services, and view logs. We will learn how to use the systemd control system to start and manage services. To view logs, we will learn how to use the systemd control system to start,
Abstract: Systemd is controversial, but Fedora, SFedora, SUSE, and Rhel are all gradually invested in systemd. Are gradually invested in systemd. We will learn how to use the systemd control system to start systemd. We will learn how to use the systemd control system to start, manage services, and view logs. We will learn how to use the systemd control system to start and manage services. To view logs, we will learn how to use the systemd control system to start and manage services. To view logs, we will learn how to use the systemd control system to start, manage services, view logs EMD control system startup, manage services, view log control system startup, manage services, view logs
"Getting started with SystemD"
Introduction to Systemd:
Systemd is developed by Lennart Poettering and is open-source under LGPL 2.1 and its subsequent licenses. Its development goal is to provide a better framework to represent the dependency between system services, and to achieve parallel startup of services during system initialization and reduce the system overhead of Shell, the System V and BSD init programs are replaced. (From Wikipedia)
There is a controversy over Systemd, but Fedora, Suse, and Rhel are all gradually invested in systemd. This article will use systemd on Rhel 7 to guide readers to learn how to use the systemd control system to start, view logs, and manage services.
System startup:
First, let's recall the past./sbin/init is started as the process whose PID is 1, and then fork (clone) other processes, select runlevel according to the settings in the/etc/inittab, and from/etc/rc */etc/init. d/select the corresponding STARTUP script to start the service. Now the process with PID 1 is changed to sytemd (PID 0 is the kernel process) and displayed on my machine:
[Root @ 22062 ~] # Ps-ef
UID PID PPID C STIME TTY TIME CMD
Root 1 0 0 Jan14? 00:01:51/usr/lib/systemd -- system -- deserialize 17
Other spawn processes are implemented by systemd.
While Runlevel becomes Target:
Graphical.tar get = 5
Multiuser.tar get = 3
The following are some common commands:
View default target: systemctl get-default
Modify default target: systemctl set-default []
Real-time modification: systemctl isolate []
View Start Time: systemd-analyze
View the startup time overhead of a single task: systemd-analyze blame
View dependencies between tasks: systemctl list-dependencies
(Note: The/etc/inittab is not used any more, and runlevel5.target,runlevel3.tar get is reserved for compatibility)
Management Service:
Previously, the default startup scripts were all placed under/etc/init. d/etc/rc.
Systemd uses Unit file to control services.
Control File:/usr/lib/systemd/system
Control File:/etc/systemd/system
Runtime data:/run/systemd
(Note: files under the/etc directory have a higher priority)
I installed HTTPD on this machine. Let's take a look at the HTTPD service status.
[Root @ 22062 ~] # Systemctl status httpd
Httpd. service-The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd. service; enabled)
Active: active (running) since Wed 03:46:34 EST; 4 days ago
Process: 18544 ExecReload =/usr/sbin/httpd $ OPTIONS-k graceful (code = exited, status = 0/SUCCESS)
Major PID: 10701 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup:/system. slice/httpd. service
2017-10701/usr/sbin/httpd-DFOREGROUND
2017-18556/usr/sbin/httpd-DFOREGROUND
2017-18557/usr/sbin/httpd-DFOREGROUND
2017-18558/usr/sbin/httpd-DFOREGROUND
2017-18559/usr/sbin/httpd-DFOREGROUND
2017-18560/usr/sbin/httpd-DFOREGROUND
SystemD by default, all input here are services, so
Systemctl status httpd is equivalent to systemctl status httpd. service. Rhel 7 redirects service httpd status to systemctl status httpd.
Disable httpd: systemctl stop httpd
Systemctl disable httpd (equivalent to the previous chkconfig httpd off)
Restart/reload: systemctl restart httpd/systemctl reload httpd
Check whether the httpd service is self-started: systemctl is-enable httpd
Check whether httpd is started: systemctl is-active httpd
View the httpd status: systemctl status httpd
View the status of all services: systemctl
View services in a tree: systemd-cgls
The tree structure provided by systemd-cgls is very specific. You can see the levels of Cgroup, service, and process)
Here, I omit some output. (Note: slice is not a service container)
Capacity-system. slice
─ ── Httpd. service
│ 2017-10701/usr/sbin/httpd-DFOREGROUND
│ 2017-18556/usr/sbin/httpd-DFOREGROUND
│ 2017-18557/usr/sbin/httpd-DFOREGROUND
│ 2017-18558/usr/sbin/httpd-DFOREGROUND
│ 2017-18559/usr/sbin/httpd-DFOREGROUND
│ 2017-18560/usr/sbin/httpd-DFOREGROUND
Control file:
Next let's take a look at the httpd control file, which is automatically generated during software installation. We can also generate AN httpd in/etc/systemd/system. service file, the file content of the same name under/lib/systemd/system/will be overwritten.
[Root @ 22062 ~] # Cat/lib/systemd/system/httpd. service
[Unit]
Description = The Apache HTTP Server
Afterappsnetwork.tar get remote-fs.target nss-lookup.target
[Service]
Type = Policy
EnvironmentFile =/etc/sysconfig/httpd
ExecStart =/usr/sbin/httpd $ OPTIONS-DFOREGROUND
ExecReload =/usr/sbin/httpd $ OPTIONS-k graceful
ExecStop =/bin/kill-WINCH $ {MAINPID}
# We want systemd to give httpd some time to finish gracefully, but still want
# It to kill httpd after TimeoutStopSec if something went wrong during
# Graceful stop. Normally, Systemd sends SIGTERM signal right after
# ExecStop, which wowould kill httpd. We are sending useless SIGCONT here to give
# Httpd time to finish.
KillSignal = SIGCONT
PrivateTmp = true
[Install]
Wantedbypolicmulti-user.tar get
Stop Service:
Systemctl stop httpd or systemctl kill httpd
Both commands can stop the service, but the implementation process is different.
Kill directly sends sigterm to the Cgroup, while stop is based on the configuration of the httpd Unit. ExecStop =/bin/kill-WINCH $ {MAINPID} is the command actually called by stop.
View logs:
In Systemd, it provides a log that records syslog, Kernel log, and boot messages.
You can use it as a substitute for syslog/rsyslog.
You can simply enter journalctl to view logs. Logs are saved in/run/systemd/journal/
Systemd summary:
This article is just an introduction to systemd and has made some simple experiments on Rhel 7.
The introduction of Systemd is a great change. It is reflected in the concurrent startup, cgroup management service, resource management, and container management. systemd has a lot to be explored.
CentOS7/RHEL7 systemd detailed http://www.linuxidc.com/Linux/2015-04/115937.htm
Why is systemd so quickly adopted? Http://www.linuxidc.com/Linux/2014-08/105789.htm
Systemd and sysVinit Color comparison table http://www.linuxidc.com/Linux/2014-09/106455.htm
So useful! Run the systemd command to manage the Linux system! Http://www.linuxidc.com/Linux/2014-09/106490.htm
Linux init system initialization, Part 1: Systemd http://www.linuxidc.com/Linux/2014-12/110383.htm
This article permanently updates the link address: Http://www.linuxidc.com/Linux/2015-12/126196.htm