13个systemd与systemctl命令详解(linux)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了13个systemd与systemctl命令详解(linux)相关的知识,希望对你有一定的参考价值。

CPU Utilization (Shares) of a Service

25. Get the current CPU Shares of a Service (say httpd).

# systemctl show -p CPUShares httpd.service
CPUShares=1024

Note: The default each service has a CPUShare = 1024. You may increase/decrease CPU share of a process.

26. Limit the CPU Share of a service (httpd.service) to 2000 CPUShares/

# systemctl set-property httpd.service CPUShares=2000
# systemctl show -p CPUShares httpd.service
CPUShares=2000

Note: When you set CPUShare for a service, a directory with the name of service is created (httpd.service.d) which contains a file 90-CPUShares.conf which contains the CPUShare Limit information. You may view the file as:

# vi /etc/systemd/system/httpd.service.d/90-CPUShares.conf 
[Service]
CPUShares=2000

27. Check all the configuration details of a service.

# systemctl show httpd
Id=httpd.service
Names=httpd.service
Requires=basic.target
Wants=system.slice
WantedBy=multi-user.target
Conflicts=shutdown.target
Before=shutdown.target multi-user.target
After=network.target remote-fs.target nss-lookup.target systemd-journald.socket basic.target system.slice
Description=The Apache HTTP Server
LoadState=loaded
ActiveState=active
SubState=running
FragmentPath=/usr/lib/systemd/system/httpd.service
....

28. Analyze critical chain for a services(httpd).

# systemd-analyze critical-chain httpd.service
The time after the unit is active or started is printed after the "@" character.
The time the unit takes to start is printed after the "+" character.
httpd.service +142ms
└─network.target @11.168s
└─network.service @9.456s +1.712s
└─NetworkManager.service @8.858s +596ms
└─firewalld.service @4.931s +3.926s
└─basic.target @4.916s
└─sockets.target @4.916s
└─dbus.socket @4.916s
└─sysinit.target @4.905s
└─systemd-update-utmp.service @4.864s +39ms
└─auditd.service @4.563s +301ms
└─systemd-tmpfiles-setup.service @4.485s +69ms
└─rhel-import-state.service @4.342s +142ms
└─local-fs.target @4.324s
└─boot.mount @4.286s +31ms
└─[email protected]\x2duuid-79f594ad\x2da332\x2d4730\x2dbb5f\x2d85d196080964.service @4.092s +149ms
└─dev-disk-by\x2duuid-79f594ad\x2da332\x2d4730\x2dbb5f\x2d85d196080964.device @4.092s

29. Get a list of dependencies for a services (httpd).

# systemctl list-dependencies httpd.service
httpd.service
├─system.slice
└─basic.target
├─firewalld.service
├─microcode.service
├─rhel-autorelabel-mark.service
├─rhel-autorelabel.service
├─rhel-configure.service
├─rhel-dmesg.service
├─rhel-loadmodules.service
├─paths.target
├─slices.target
│ ├─-.slice
│ └─system.slice
├─sockets.target
│ ├─dbus.socket
....

30. List control groups hierarchically.

# systemd-cgls├─1 /usr/lib/systemd/systemd --switched-root --system --deserialize 23
├─user.slice
│ └─user-0.slice
│   └─session-1.scope
│     ├─2498 sshd: [email protected]/0    
│     ├─2500 -bash
│     ├─4521 systemd-cgls
│     └─4522 systemd-cgls
└─system.slice
├─httpd.service
│ ├─4440 /usr/sbin/httpd -DFOREGROUND
│ ├─4442 /usr/sbin/httpd -DFOREGROUND
│ ├─4443 /usr/sbin/httpd -DFOREGROUND
│ ├─4444 /usr/sbin/httpd -DFOREGROUND
│ ├─4445 /usr/sbin/httpd -DFOREGROUND
│ └─4446 /usr/sbin/httpd -DFOREGROUND
├─polkit.service
│ └─721 /usr/lib/polkit-1/polkitd --no-debug
....

31. List control group according to CPU, memory, Input and Output.

# systemd-cgtop
Path                                                              Tasks   %CPU   Memory  Input/s Output/s
/                                                                    83    1.0   437.8M        -        -
/system.slice                                                         -    0.1        -        -        -
/system.slice/mariadb.service                                         2    0.1        -        -        -
/system.slice/tuned.service                                           1    0.0        -        -        -
/system.slice/httpd.service                                           6    0.0        -        -        -
/system.slice/NetworkManager.service                                  1      -        -        -        -
/system.slice/atop.service                                            1      -        -        -        -
/system.slice/atopacct.service                                        1      -        -        -        -
/system.slice/auditd.service                                          1      -        -        -        -
/system.slice/crond.service                                           1      -        -        -        -
/system.slice/dbus.service                                            1      -        -        -        -
/system.slice/firewalld.service                                       1      -        -        -        -
/system.slice/lvm2-lvmetad.service                                    1      -        -        -        -
/system.slice/polkit.service                                          1      -        -        -        -
/system.slice/postfix.service                                         3      -        -        -        -
/system.slice/rsyslog.service                                         1      -        -        -        -
/system.slice/system-getty.slice/[email protected]                   1      -        -        -        -
/system.slice/systemd-journald.service                                1      -        -        -        -
/system.slice/systemd-logind.service                                  1      -        -        -        -
/system.slice/systemd-udevd.service                                   1      -        -        -        -
/system.slice/webmin.service                                          1      -        -        -        -
/user.slice/user-0.slice/session-1.scope                              3      -        -        -        -

Control System Runlevels

32. How to start system rescue mode.

# systemctl rescue
Broadcast message from [email protected] on pts/0 (Wed 2015-04-29 11:31:18 IST):
The system is going down to rescue mode NOW!

33. How to enter into emergency mode.

# systemctl emergency
Welcome to emergency mode! After logging in, type "journalctl -xb" to view
system logs, "systemctl reboot" to reboot, "systemctl default" to try again
to boot into default mode.

34. List current run levels in use.

# systemctl get-defaultmulti-user.target

35. How to start Runlevel 5 aka graphical mode.

# systemctl isolate runlevel5.target
OR
# systemctl isolate graphical.target

36. How to start Runlevel 3 aka multiuser mode (commandline).

# systemctl isolate runlevel3.target
OR
# systemctl isolate multiuser.target

36. How to set multiusermode or graphical mode as default runlevel.

# systemctl set-default runlevel3.target
# systemctl set-default runlevel5.target

37. How to reboot, halt, suspend, hibernate or put system in hybrid-sleep.

# systemctl reboot
# systemctl halt
# systemctl suspend
# systemctl hibernate
# systemctl hybrid-sleep

For those who may not be aware of runlevels and what it does.

  1. Runlevel 0 : Shut down and Power off the system.

  2. Runlevel 1 : Rescue?Maintainance Mode.

  3. Runlevel 3 : multiuser, no-graphic system.

  4. Runlevel 4 : multiuser, no-graphic system.

  5. Runlevel 5 : multiuser, graphical system.

  6. Runlevel 6 : Shutdown and Reboot the machine.


本文出自 “瑞航启程--下一代企业应用” 博客,谢绝转载!

以上是关于13个systemd与systemctl命令详解(linux)的主要内容,如果未能解决你的问题,请参考以下文章

systemctl 命令详解及使用教程

systemctl 命令详解及使用教程

Systemctl 详解

红冒系列-Systemctl命令详解说明

Centos7中systemctl命令详解

systemd和systemctl详解