In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, the editor will share with you the relevant knowledge points about how to use Linux's systemd. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.
Systemd is a set of basic building blocks of the Linux system. It provides a system and service manager that runs as PID 1 and starts the rest of the system. Provides active parallelization, using sockets and D-Bus activation to start services, starting daemons on demand, and tracking processes using Linux control groups.
Use control groups to manage processes
One of the major differences between systemd and SystemV is the way processes are managed. SystemV treats each process as a separate entity. Systemd centralizes related processes into a control group, abbreviated as cgroup, and manages system resources as a whole. This means that resources can be managed based on the application, rather than by the processes that make up the application.
The control unit of the control group is called the slice unit slice unit. Slicing allows systemd to control program order in a tree format, thus simplifying the conceptualization of management.
View Control Group
I'll start with some commands that allow you to view different types of control group information. The systemctl status command displays slicing information for a specific service, including slicing for the service. This example shows the at daemon:
[root@testvm1] # systemctl status atd.service ● atd.service-Deferred execution scheduler Loaded: loaded (/ usr/lib/systemd/system/atd.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2020-09-23 12:18:24 EDT 1 day 3h ago Docs: man:atd (8) Main PID: 1010 (atd) Tasks: 1 (limit: 14760) Memory: 440.0K CPU: 5ms CGroup: / system.slice/atd.service └─ 1010 / usr/sbin/atd-fSep 23 12:18:24 testvm1.both.org systemd [1]: Started Deferred execution scheduler. [root@testvm1] #
This is a great example of why I think systemd is better to use than SystemV and the old initializer. The information here is much richer than SystemV can provide. Among the hierarchies included in the CGroup entry, system.slice is systemd (PID 1), and atd.service is at the next level and is part of system.slice. The second line of the CGroup entry also shows the process ID (PID) and the command used to start the daemon.
The systemctl command can list multiple control group items, and the-- all parameter lists all slices, including those that are not currently active:
[root@testvm1 ~] # ps xawf-eo pid,user,cgroup Args PID USER CGROUP COMMAND 2 root-[kthreadd] 3 root -\ _ [rcu_gp] 4 root -\ _ [rcu_par_gp] 6 root- \ _ [kworker/0:0H-kblockd] 9 root -\ _ [mm_percpu_wq] 10 root -\ _ [ksoftirqd/0] 11 root -\ _ [rcu_sched] 12 root- \ _ [migration/0] 13 root -\ _ [cpuhp/0] 14 root -\ _ [cpuhp/1] 625406 root -\ _ [kworker/3:0-ata_sff] 625409 root- \ _ [kworker/u8:0-events_unbound] 1 root 0::/init.scope / usr/lib/systemd/systemd--switched-root-- system-- deserialize 30588 root 0::/system.slice/systemd-jo / usr/lib/systemd/systemd-journald 599 root 0::/system.slice/systemd-ud / usr/lib/systemd/systemd-udevd 741 root 0::/system. Slice/auditd.ser / sbin/auditd 743 root 0::/system.slice/auditd.ser\ _ / usr/sbin/sedispatch 764 root 0::/system.slice/ModemManag / usr/sbin/ModemManager 765 root 0::/system.slice/NetworkMan / usr/sbin/NetworkManager-- no-daemon 767 root 0::/system.slice/irqbalance / usr/sbin/irqbalance-- foreground 779 root 0::/system.slice/mcelog.ser / Usr/sbin/mcelog-- ignorenodev-- daemon-- foreground 781 root 0::/system.slice/rngd.servi / sbin/rngd-f 782 root 0::/system.slice/rsyslog.se / usr/sbin/rsyslogd-n 893 root 0::/system.slice/sshd.servi sshd: / usr/sbin/sshd-D [listener] 0 of 10-100 startups 1130 root 0::/user.slice/user-0.slice\ _ sshd: root [ Priv] 1147 root 0::/user.slice/user-0.slice |\ _ sshd: root@pts/0 1148 root 0::/user.slice/user-0.slice |\ _-bash 1321 root 0::/user.slice/user-0.slice |\ _ screen 1322 root 0::/user.slice/user-0.slice |\ _ SCREEN 1323 root 0::/user .slice/user-0.slice |\ _ / bin/bash498801 root 0::/user.slice/user-0.slice | |\ _ man systemd.resource-control498813 root 0::/user.slice/user-0.slice | |\ _ less 1351 root 0::/user.slice/user-0.slice | \ _ / bin/bash123293 root 0::/user.slice/user-0.slice | |\ _ man systemd.slice123305 root 0::/user.slice/user-0.slice | |\ _ less 1380 root 0::/user.slice/user-0.slice |\ _ / bin/bash625412 root 0::/user.slice/ User-0.slice | |\ _ ps xawf-eo pid User,cgroup Args625413 root 0::/user.slice/user-0.slice | |\ _ less246795 root 0::/user.slice/user-0.slice |\ _ / bin/bash625338 root 0::/user.slice/user-0.slice |\ _ / usr/bin/mc-P / var/tmp/mc-root/mc.pwd.246795625340 root 0::/user.slice/user-0.slice |\ _ bash-rcfile .bashrc 1218 root 0::/user.slice/user-1000.sl\ _ sshd: dboth [priv] 1233 dboth 0::/user.slice/user-1000.sl\ _ sshd: dboth@pts/1 1235 dboth 0::/user.slice/user-1000.sl\ _-bash 1010 root 0::/system.slice/atd.servic / usr/sbin/atd-f 1011 root 0::/system.slice/crond.serv / usr/sbin/crond-n 1098 root 0::/system.slice/lxdm.servi / usr/sbin/lxdm-binary 1106 root 0::/system.slice/lxdm.servi\ _ / usr/libexec/Xorg-background none: 0 vt01-nolisten tcp-novtswitch-auth / var/run/lxdm/lxdm-:0.auth370621 root 0 : / user.slice/user-1000.sl\ _ / usr/libexec/lxdm-session370631 dboth 0::/user.slice/user-1000.sl\ _ xfce4-session370841 dboth 0::/user.slice/user-1000.sl\ _ / usr/bin/ssh-agent / bin/sh-c exec-l bash-c "/ usr/bin/startxfce4" 370911 dboth 0::/user.slice/user-1000.sl\ _ xfwm4-- display: 0.0-- sm-client-id 2dead44ab-0b4d-4101-bca4-e6771f4a8ac2370930 dboth 0::/user.slice/user-1000.sl\ _ xfce4-panel-- display: 0.0-- sm-client-id 2ce38b8ef-86fd-4189-ace5-deec1d0e0952370942 dboth 0::/user.slice/user-1000.sl |\ _ / usr/lib64/xfce4/panel/wrapper-2.0 / usr/lib64/xfce4/panel/ Plugins/libsystray.so 6 23068680 systray Notification Area Area where notification icons appear370943 dboth 0::/user.slice/user-1000.sl |\ _ / usr/lib64/xfce4/panel/wrapper-2.0 / usr/lib64/xfce4/panel/plugins/libpulseaudio-plugin.so 8 23068681 pulseaudio PulseAudio Plugin Adjust the audio volume of the PulseAudio sound system370944 dboth 0::/user.slice/user-1000.sl |\ _ / usr/lib64/xfce4/panel/wrapper-2. 0 / usr/lib64/xfce4/panel/plugins/libxfce4powermanager.so 9 23068682 power-manager-plugin Power Manager Plugin Display the battery levels of your devices and control the brightness of your display370945 dboth 0::/user.slice/user-1000.sl |\ _ / usr/lib64/xfce4/panel/wrapper-2.0 / usr/lib64/xfce4/panel/plugins/libnotification-plugin.so 10 23068683 notification-plugin Notification Plugin Notification plugin for the Xfce panel370948 dboth 0::/user.slice/user-1000. Sl |\ _ / usr/lib64/xfce4/panel/wrapper-2.0 / usr/lib64/xfce4/panel/plugins/libactions.so 14 23068684 actions Action Buttons Log out Lock or other system actions370934 dboth 0::/user.slice/user-1000.sl\ _ Thunar-- sm-client-id 2cfc809d8-4e1d-497a-a5c5-6e4fa509c3fb-- daemon370939 dboth 0::/user.slice/user-1000.sl\ _ xfdesktop-- display: 0.0-- sm-client-id 299be0608-4dca-4055-b4d6-55ec6e73a324370962 dboth 0::/user.slice/user-1000.sl\ _ nm-applet
The first thing to notice about this data is that it shows user slices of UID 0 (root) and UID 1000, where UID 1000 is the user I logged in. The slice parts that make up each slice are listed here, not the service. It also shows that a slice is created for each user when he or she logs in, which provides a way to manage all tasks of a user as a single control group item.
Explore the hierarchical structure of control groups
So far so good, but the control group is hierarchical, and all the service units run as members of one of the control groups. To see this hierarchy is simple, use an old command and a new command from systemd.
The ps command can be used to map the process's and its control group hierarchy. Note that you need to specify the data columns you want when using the ps command. I drastically reduced the output of the following commands, but tried to keep enough data so that you could feel the output on your system:
[root@testvm1] # systemctl-t slice-- all UNIT LOAD ACTIVE SUB DESCRIPTION-.slice loaded active active Root Slice system-getty.slice loaded active active system-getty.slice system-lvm2\ x2dpvscan.slice loaded active active system -lvm2\ x2dpvscan.slice system-modprobe.slice loaded active active system-modprobe.slice system-sshd\ x2dkeygen.slice loaded active active system-sshd\ x2dkeygen.slice system-systemd\ x2dcoredump.slice loaded inactive dead system-systemd\ x2dcoredump.slice system-systemd\ x2dfsck.slice loaded active active system-systemd\ x2dfsck.slice system.slice loaded active active System Slice User-0.slice loaded active active User Slice of UID 0 user-1000.slice loaded active active User Slice of UID 1000 user.slice loaded active active User and Session Slice LOAD = Reflects whether the unit definition was properly loaded.ACTIVE = The high-level unit activation state I.e. Generalization of SUB.SUB = The low-level unit activation state, values depend on unit type.11 loaded units listed.To show all installed unit files use 'systemctl list-unit-files'. [root@testvm1 ~] #
You can use the systemd-cgls command to view the entire hierarchy, which does not require any complex parameters and is simpler.
I also greatly shortened the tree structure, but retained enough output so that you could understand the total amount of data and the type of items you should see when executing this command on your system. I executed this command on one of my virtual machines and the output was about 200 lines; the output of my main workstation was about 250 lines.
[root@testvm1 ~] # systemd-cglsControl group /: -. Slice ├─ user.slice │ ├─ user-0.slice │ │ ├─ session-1.scope │ ├─ 1130 sshd: root [priv] │ ├─ 1147 sshd: root@pts/0 │ ├─ 1148-bash │ ├─ 1321 screen │ ├─ 1322 SCREEN │ ├─ 1323 / bin / bash │ ├─ 1351 / bin/bash │ ├─ 1380 / bin/bash │ ├─ 123293 man systemd.slice │ ├─ 123305 less │ ├─ 246795 / bin/bash │ ├─ 371371 man systemd-cgls │ ├─ 371383 less │ ├─ 371469 systemd-cgls │ └─ 371470 less │ user@0.service … │ │ ├─ dbus-broker.service │ ├─ 1170 / usr/bin/dbus-broker-launch-scope user │ └─ 1171 dbus-broker--log 4-controller 12-machine-id 3bccd1140fca488187f8a1439c832f07-max-bytes 100000000000000-max-fds 25000000000000-max- > │ │ ├─ gvfs-daemon.service │ └─ 1173 / usr/libexec/gvfsd │ init.scope │ ├─ 1137 / usr/lib/systemd/systemd-user │ │ └─ 1138 (sd-pam) │ └─ user-1000.slice │ ├─ user@1000.service … │ │ ├─ dbus\ x2d:1.2\ x2dorg.xfce.Xfconf.slice │ └─ dbus-:1.2-org.xfce.Xfconf@0.service │ │ └─ 370748 / usr/lib64/xfce4/xfconf/xfconfd │ │ ├─ dbus\ x2d:1.2\ x2dca.desrt.dconf.slice │ └─ dbus-:1.2-ca.desrt.dconf@0.service │ │ └─ 371262 / usr/libexec/dconf-service │ │ ├─ dbus-broker.service │ ├─ 1260 / usr/bin/dbus-broker-launch-scope user │ └─ 1261 dbus-broker--log 4-controller 11-machine-id │ │ └─ gvfs-mtp-volume-monitor.service │ │ └─ 370987 / usr/libexec/gvfs-mtp-volume-monitor session- 3.scope │ │ ├─ 1218 sshd: dboth [priv] │ │ ├─ 1233 sshd: dboth@pts/1 │ │ └─ 1235-bash │ └─ session-7.scope │ ├─ 370621 / usr/libexec/lxdm-session │ ├─ 370631 xfce4-session │ ├─ 370805 / usr/bin/VBoxClient-- clipboard │ ├─ 370806 / usr/bin/VBoxClient-clipboard 370817 / usr/bin / VBoxClient-- seamless │ ├─ 370818 / usr/bin/VBoxClient-- seamless │ ├─ 370824 / usr/bin/VBoxClient-- draganddrop │ ├─ 370825 / usr/bin/VBoxClient-- draganddrop │ ├─ 370841 / usr/bin/ssh-agent / bin/sh-c exec-l bash-c "/ usr/bin/startxfce4" │ ├─ 370910 / bin/gpg-agent-sh--daemon-write-env-file / home/dboth/. Cache/gpg-agent-info │ ├─ 370911 xfwm4-- display: 0.0-- sm-client-id 2dead44ab-0b4d-4101-bca4-e6771f4a8ac2 │ ├─ 370923 xfsettingsd-- display: 0.0-- sm-client-id 261b4a437-3029-461c-9551-68c2c42f4fef │ ├─ 370930 xfce4-panel-- display: 0.0-- sm-client-id 2ce38b8ef-86fd-4189-ace5-deec1d0e0952 │ ├─ 370934 Thunar-- sm-client-id 2cfc809d8-4e1d -497a-a5c5-6e4fa509c3fb-- daemon │ ├─ 370939 xfdesktop-- display: 0.0-sm-client-id 299be0608-4dca-4055-b4d6-55ec6e73a324 └─ system.slice ├─ rngd.service │ └─ 1650 / sbin/rngd-f ├─ irqbalance.service │ └─ 1631 / usr/sbin/irqbalance-- foreground ├─ fprintd.service │ └─ 303383 / usr/libexec/fprintd ├─ systemd-udevd.service │ └─ 303383 / usr/lib/systemd/systemd-udevd ├─ Systemd-journald.service │ └─ 1010 / usr/lib/systemd/systemd-journald ├─ atd.service │ └─ 1010 / usr/sbin/atd-f ├─ system-dbus\ x2d:1.10\ x2dorg.freedesktop.problems.slice │ └─ dbus-:1.10-org.freedesktop.problems@0.service │ └─ 371197 / usr/sbin/abrt-dbus-t133 ├─ sshd.service │ └─ sshd: / usr/sbin/sshd-D [listener] 0 of 10 -100 startups ├─ vboxservice.service │ └─ 1011 / usr/sbin/VBoxService-f ├─ crond.service │ └─ 1011 / usr/sbin/crond-n ├─ NetworkManager.service │ └─ 765 / usr/sbin/NetworkManager-no-daemon ├─ switcheroo-control.service │ └─ 787 / usr/libexec/switcheroo-control
This tree view shows all the user and system slices, as well as the services and programs running within each control group. Notice the unit called scope, which combines the related programs into a snap-in, which is user-1000.slice in the results listed above. The user-1000.slice/session-7.scope control group contains the GUI desktop program hierarchy, starting with a LXDM display Manager session and all its subtasks, including programs such as the Bash command line interpreter and the Thunar GUI file manager.
The scope unit is not defined in the configuration file, but is generated programmatically as a result of starting the relevant program group. The scope unit does not create or start processes that run as part of the control group. All processes within the scope are equal and have no internal hierarchy. The life cycle of a scope begins when the first process is created and ends when the last process is destroyed.
Open multiple windows on your desktop, such as terminal emulator, LibreOffice, or whatever you want, then switch to an available virtual console and start a program like top or Midnight Commander. Run the systemd-cgls command on the host and pay attention to the overall hierarchy and scope units.
The hierarchical representation of the control group provided by the systemd-cgls command (and the details that make up the control group unit) is more complete than any other instruction I have ever seen. I like the more concise tree representation of the ps command than the output provided by the systemd-cgls command.
These are all the contents of the article "how to use Linux's systemd". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.