systemctl command instructions

1, Command Overview

Systemctl systemd is a tool primarily responsible for controlling the systemd system and service manager.

Systemd is a collection of system management daemon, tools and libraries, to replace System V init process. Systemd function is centralized management and configuration for UNIX-like systems.

In the Linux ecosystem, Systemd been deployed to most standard Linux distributions, only a few releases have not been deployed. Systemd usually the parent of all other daemons, but not always.

After CentOS7 completely replaced by systemd init from the boot mode, start the service mechanism systemd is mainly handled by systemctl service management system of this Directive. systemctl in usage also include most of the functionality service / chkconfig / setup / init's.

2, the command syntax

systemctl [options] [service] 

3, command options

status: check the service status
start: Start the service
stop: stop the service
restart: restart the service
enable: a service boot from the start
disable: Disables a service boot from Kai
list-units: list all running unit
list-unit-files: list All available unit
list-unit-files --type = service : List all services (including enabling and disabling)
List Files-unit---type = Mount: List all system mount point
list-unit-files -type = socket: lists all available system socket
list-failed: List all failed to start service
is-enabled: see whether a service boot from Kai
is-active: to see whether a service is now open
kill: kill a service
reload: reload a service profile
show: a service check of all configuration details
list-dependencies: obtaining a service dependency list of
get-default: lists the current system run level
mask: mask (it can not start ) a service
umask: unblock

4, an example of command

4.1 status view service status firewalld

 1 [root@localhost ~]# systemctl status firewalld.service
 2 ● firewalld.service - firewalld - dynamic firewall daemon  3 Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)  4 Active: active (running) since 二 2019-10-08 15:58:24 CST; 1 weeks 1 days ago  5 Docs: man:firewalld(1)  6 Main PID: 12434 (firewalld)  7 CGroup: /system.slice/firewalld.service  8 └─12434 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid  9 10 10月 08 15:58:24 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon... 11 10月 08 15:58:24 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon. 12 [root@localhost ~]#

4.2 start service start firewalld

1 [root@localhost ~]# systemctl start firewalld.service

4.3 stop stop firewalld Service

1 [root@localhost ~]# systemctl stop firewalld.service

4.4 restart to restart the service firewalld

1 [root@localhost ~]# systemctl restart firewalld.service

4.5 enable open firewalld service at startup

1 [root@localhost ~]# systemctl enable firewalld.service

4.6 disable close firewalld service at startup

1 [root@localhost ~]# systemctl disable firewalld.service
2 Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service. 3 Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service. 4 [root@localhost ~]#

4.7 list-units: units include all runs

1 [root@localhost ~]# systemctl list-units

4.8 list-unit-files: list of all available units

1 [root@localhost ~]# systemctl list-unit-files

4.9 --list-failed: List all failed service

1 [root@localhost ~]# systemctl --failed
2 0 loaded units listed. Pass --all to see loaded but inactive units, too.
3 To show all installed unit files use 'systemctl list-unit-files'.
4 [root@localhost ~]# 

If 4.10 is-enabled view firewalld service boot

1 [root@localhost ~]# systemctl is-enabled firewalld.service
2 enabled 3 [root@localhost ~]#

4.11 kill kill firewalld Service

 1 [root@localhost ~]# systemctl kill firewalld.service
 2 [root@localhost ~]# systemctl status firewalld.service
 3 ● firewalld.service - firewalld - dynamic firewall daemon
 4    Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
 5    Active: inactive (dead) since 四 2019-10-17 15:15:24 CST; 21s ago
 6      Docs: man:firewalld(1)
 7   Process: 3659 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS)
 8  Main PID: 3659 (code=exited, status=0/SUCCESS)
 9 
10 10月 17 15:07:56 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
11 10月 17 15:07:56 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
12 [root@localhost ~]# 

4.12 reload reload firewalld Service

1 [root@localhost ~]# systemctl reload firewalld.service

4.13 is-active to see whether the service is now open firewalld

1 [root@localhost ~]# systemctl is-active firewalld.service
2 active
3 [root@localhost ~]# 

4.14 list-unit-files --type = service: All services listed

1 [root@localhost ~]# systemctl list-unit-files --type=service

4.15 list-unit-files --type = mount: List all system mount point

 1 [root@localhost ~]# systemctl list-unit-files --type=mount
 2 UNIT FILE                     STATE   
 3 dev-hugepages.mount           static  
 4 dev-mqueue.mount              static  
 5 proc-sys-fs-binfmt_misc.mount static  
 6 sys-fs-fuse-connections.mount static  
 7 sys-kernel-config.mount       static  
 8 sys-kernel-debug.mount        static  
 9 tmp.mount                     disabled
10 
11 7 unit files listed.
12 [root@localhost ~]# 

4.16 and unmounting, remounting, overload and system mount point mount point state inspection system 

# systemctl start tmp.mount
# systemctl stop tmp.mount
# systemctl restart tmp.mount
# systemctl reload tmp.mount
# systemctl status tmp.mount
# systemctl is-active tmp.mount
# systemctl enable tmp.mount
# systemctl disable tmp.mount

4.17 lists all available system socket

1 [root@localhost ~]# systemctl list-unit-files –type=socket
2 UNIT FILE STATE
3 
4 0 unit files listed.
5 [root@localhost ~]# 

4.18 inspect a service (firewalld) of all configuration details 

1 [root@localhost ~]# systemctl show firewalld.service

4.19 obtain a service (firewalld) the list of dependencies

1 [root@localhost ~]# systemctl list-dependencies firewalld.service

4.20 get-default: lists the current system run level

1 [root@localhost ~]# systemctl get-default
2 multi-user.target
3 [root@localhost ~]# 

4.21 to obtain a share of the current CPU service

. 1 [the root @ localhost ~] # systemctl Show - P CPUShares firewalld.service
 2 CPUShares = 18446744073709551615 
. 3 [the root @ localhost ~] # systemctl Show - P CPUShares sshd.service
 . 4 CPUShares = 18446744073709551615 
. 5 [the root @ localhost ~] # 
Note: default values for each service are CPUShare = 1024. You can increase / decrease the share of CPU process.

CPU 4.22 share of the service (httpd) is limited to 2000 CPUShares /

1 [root@localhost ~]# systemctl set-property httpd.service CPUShares=2000

Note: When setting CPUShare for the service, will create a directory named service (httpd.service.d), which contains the file that contains a 90-CPUShares.conf CPUShare Limit information. You can file as:
# CAT /etc/systemd/system/httpd.service.d/90-CPUShares.conf
[Service]
CPUShares = 2000

4.23 Analysis of key chain services (firewalld.service):

 1 [root@localhost ~]# systemd-analyze critical-chain firewalld.service
 2 The time after the unit is active or started is printed after the "@" character.
 3 The time the unit takes to start is printed after the "+" character.
 4 
 5 firewalld.service +267ms
 6 └─dbus.service @1.643s
 7   └─basic.target @1.627s
 8     └─sockets.target @1.627s
 9       └─dbus.socket @1.627s
10         └─sysinit.target @1.626s
11           └─systemd-update-utmp.service @1.615s +10ms
12             └─systemd-tmpfiles-setup.service @1.288s +14ms
13               └─rhel-import-state.service @1.232s +55ms
14                 └─local-fs.target @1.232s
15                   └─boot.mount @1.186s +45ms
16                     └─dev-disk-by\x2duuid-806549af\x2dd314\x2d4cb2\x2db124\x2d8599a95e12bd.device @1.186s
17 [root@localhost ~]# 

4.24 hierarchical list control group

 1 [root@localhost ~]# systemd-cgls 
 2 ├─1 /usr/lib/systemd/systemd --system --deserialize 23
 3 ├─user.slice
 4 │ └─user-0.slice
 5 │   └─session-255.scope
 6 │     ├─ 7970 systemd-cgls
 7 │     ├─ 7971 less
 8 │     ├─29914 sshd: root@pts/1    
 9 │     └─29918 -bash
10 └─system.slice
11   ├─firewalld.service
12   │ └─4430 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid
13   ├─tuned.service
14   │ └─12941 /usr/bin/python2 -Es /usr/sbin/tuned -l -P
15   ├─polkit.service

The control group 4.25 lists CPU, memory, input and output

 1 [root@localhost ~]# systemd-cgtop 
 2 Path                                                                                Tasks   %CPU   Memory  Input/s Output/s
 3 
 4 /                                                                                     174      -     1.4G        -        -
 5 /system.slice/NetworkManager.service                                                    1      -        -        -        -
 6 /system.slice/auditd.service                                                            1      -        -        -        -
 7 /system.slice/chronyd.service                                                           1      -        -        -        -
 8 /system.slice/crond.service                                                             1      -        -        -        -
 9 /system.slice/dbus.service                                                              1      -        -        -        -
10 /system.slice/firewalld.service                                                         1      -        -        -        -
11 /system.slice/irqbalance.service                                                        1      -        -        -        -
12 /system.slice/polkit.service                                                            1      -        -        -        -
13 /system.slice/postfix.service                                                           3      -        -        -        -
14 /system.slice/rsyslog.service                                                           1      -        -        -        -
15 /system.slice/sshd.service                                                              1      -        -        -        -
16 /system.slice/system-getty.slice/[email protected]                                     1      -        -        -        -
17 /system.slice/systemd-journald.service                                                  1      -        -        -        -

4.26 start rescue mode 

1 [root@localhost ~]# systemctl rescue

4.27 enter emergency mode 

1 [root@localhost ~]# systemctl emergency

4.28 Analysis of systemd startup process

1 [root@localhost ~]# systemd-analyze 
2 Startup finished in 418ms (kernel) + 1.421s (initrd) + 3.471s (userspace) = 5.311s
3 [root@localhost ~]# 

4.29 Analysis of time spent in each process at boot

 1 [root@localhost ~]# systemd-analyze blame
 2            354ms NetworkManager-wait-online.service
 3            294ms postfix.service
 4            280ms network.service
 5            267ms firewalld.service
 6            266ms dev-sda5.device
 7            185ms NetworkManager.service
 8            154ms tuned.service
 9            126ms auditd.service
10            102ms rhel-dmesg.service
11            101ms systemd-user-sessions.service
12             64ms sys-kernel-debug.mount
13             64ms dev-hugepages.mount
14             63ms systemd-remount-fs.service

4.30 Analysis of key chain at start

1 [root@localhost ~]# systemd-analyze critical-chain
2 The time after the unit is active or started is printed after the "@" character.
3 The time the unit takes to start is printed after the "+" character.
4 
5 multi-user.target @3.469s
6 └─NetworkManager.service @2.549s +185ms
7   └─network-pre.target @2.548s
8 [root@localhost ~]# 

 

Guess you like

Origin www.cnblogs.com/liuzgg/p/11693034.html