學習 Linux 上的現代服務管理系統 (Systemd)
systemd 是 Linux 作業系統的框架和服務管理器。在啟動時作為第一個程序(作為 PID 1)執行時,它充當 init 系統,從而啟動和維護使用者空間服務。本文介紹了“學習 Linux 上的現代服務管理系統 (Systemd)”。
要獲取有關 systemd 的更多資訊,請使用以下命令,如下所示:
$ systemd -h
示例輸出應如下所示:
Starts up and maintains the system or user services. -h --help Show this help --test Determine startup sequence, dump it and exit --no-pager Do not pipe output into a pager --dump-configuration-items Dump understood unit configuration items --unit=UNIT Set default unit --system Run a system instance, even if PID != 1 --user Run a user instance --dump-core[=BOOL] Dump core on crash --crash-vt=NR Change to specified VT on crash --crash-reboot[=BOOL] Reboot on crash --crash-shell[=BOOL] Run shell on crash .......................................................................................
版本資訊
要獲取有關 systemd 的版本資訊,請使用以下命令,如下所示:
$ systemd --version
示例輸出應如下所示:
systemd 229 +PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ -LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN
確定啟動順序
要確定啟動順序,請使用以下命令,如下所示:
$ systemd --test
示例輸出應如下所示:
State Change Timestamp: Mon 2017-01-30 11:15:37 IST Inactive Exit Timestamp: Mon 2017-01-30 11:15:37 IST Active Enter Timestamp: Mon 2017-01-30 11:15:37 IST Active Exit Timestamp: n/a Inactive Enter Timestamp: n/a GC Check Good: yes Need Daemon Reload: no Transient: no Slice: n/a CGroup: n/a CGroup realized: no CGroup mask: 0x0 CGroup members mask: 0x0 Name: sys-devices-platform-serial8250-tty-ttyS26.device Following Set Member: dev-ttyS26.device Job Timeout: 1min 30s ..............................................................................
理解單元配置
要獲取轉儲並瞭解單元配置項,請使用以下命令:
$ systemd --dump-configuration-items
示例輸出應如下所示:
[Scope] Slice=SLICE CPUAccounting=BOOLEAN CPUShares=SHARES StartupCPUShares=SHARES CPUQuota=OTHER MemoryAccounting=BOOLEAN MemoryLimit=LIMIT DeviceAllow=DEVICE DevicePolicy=POLICY BlockIOAccounting=BOOLEAN BlockIOWeight=WEIGHT StartupBlockIOWeight=WEIGHT BlockIODeviceWeight=DEVICEWEIGHT BlockIOReadBandwidth=BANDWIDTH .....................................................................................
分析 Systemd 啟動過程
要分析 systemd 啟動過程,請使用以下命令:
$ systemd-analyze
示例輸出應如下所示:
Startup finished in 8.740s (firmware) + 4.483s (loader) + 3.616s (kernel) + 4min 21.244s (userspace) = 4min 38.084s
啟動過程列表
要獲取啟動過程及其時間的列表,請使用以下命令,如下所示:
$ systemd-analyze blame
示例輸出應如下所示:
3min 59.399s apt-daily.service 16.585s NetworkManager-wait-online.service 11.182s grub-common.service 9.532s apport.service 9.224s irqbalance.service 8.986s networking.service 8.916s snapd.refresh.service 8.859s speech-dispatcher.service 7.709s dev-sda2.device 7.641s gpu-manager.service 7.641s rsyslog.service 7.078s avahi-daemon.service 6.178s lightdm.service ..............................................................................
控制組內容
要顯示控制組內容,請使用以下命令,如下所示:
$ systemd-cgls
示例輸出應如下所示:
Control group /: -.slice ├─init.scope │ └─1 /lib/systemd/systemd --system --deserialize 19 ├─system.slice │ ├─avahi-daemon.service │ │ ├─733 avahi-daemon: running [linux-Inspiron-3542.local │ │ └─806 avahi-daemon: chroot helpe │ ├─thermald.service │ │ └─845 /usr/sbin/thermald --no-daemon --dbus-enable │ ├─dbus.service │ │ ├─ 759 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activ │ │ └─2637 /usr/lib/x86_64-linux-gnu/fwupd/fwupd │ ├─ModemManager.service │ │ └─871 /usr/sbin/ModemManager │ ├─cron.service │ │ └─850 /usr/sbin/cron -f │ ├─apache2.service │ │ ├─ 4441 /usr/sbin/apache2 -k start
頂級控制組
要根據其資源使用情況顯示頂級控制組,請使用以下命令,如下所示:
$sudo systemd-cgtop
示例輸出應如下所示:
Control Group Tasks %CPU Memory Input/s Output/s / - 20.0 6.3G - - /init.scope 1 - - - - /system.slice 125 - - - - /user.slice 695 - - - - /user.slice/user-1000.slice 654 - - - - /user.slice/user-126.slice 41 - - - -
Systemctl
Systemctl 可用於檢查和管理“systemd”系統和服務管理器的狀態。
要獲取有關 systemctl 的更多資訊,請使用以下命令,如下所示:
$ systemctl --help
示例輸出應如下所示:
Query or send control commands to the systemd manager. -h --help Show this help --version Show package version --system Connect to system manager --user Connect to user service manager -H --host=[USER@]HOST Operate on remote host -M --machine=CONTAINER Operate on local container -t --type=TYPE List units of a particular type --state=STATE List units with particular LOAD or SUB or ACTIVE state -p --property=NAME Show only properties by this name -a --all Show all loaded units/properties, including dead/empty ones. To list all units installed on the system, use the 'list-unit-files' command instead. -l --full Don't ellipsize unit names on output ...........................................................................
版本資訊
要獲取 systemctl 的版本,請使用以下命令:
$ systemctl --version
示例輸出應如下所示:
systemd 229 +PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ -LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN
所有服務的列表
要獲取所有正在執行的服務的列表,請使用以下命令,如下所示:
$ systemctl
示例輸出應如下所示:
UNIT LOAD ACTIVE SUB DESCRIPTION proc-sys-fs-binfmt_misc.automount loaded active running Arbitrary Executable File Formats F sys-devices-pci0000:00-0000:00:02.0-drm-card0-card0\x2deDP\x2d1-intel_backlight.device loaded sys-devices-pci0000:00-0000:00:03.0-sound-card0.device loaded active plugged Haswell-ULT HD sys-devices-pci0000:00-0000:00:1b.0-sound-card1.device loaded active plugged 8 Series HD Aud sys-devices-pci0000:00-0000:00:1c.2-0000:06:00.0-net-wlp6s0.device loaded active plugged QCA sys-devices-pci0000:00-0000:00:1c.3-0000:07:00.0-net-enp7s0.device loaded active plugged RTL sys-devices-pci0000:00-0000:00:1d.0-usb1-1\x2d1-1\x2d1.6-1\x2d1.6:1.0-bluetooth-hci0.device lo sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda-sda1.device loade sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda-sda2.device loade sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda-sda3.device loade sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda.device loaded act sys-devices-pci0000:00-0000:00:1f.2-ata2-host1-target1:0:0-1:0:0:0-block-sr0.device loaded act sys-devices-platform-dell\x2dlaptop-leds-dell::kbd_backlight.device loaded active plugged /s sys-devices-platform-serial8250-tty-ttyS0.device loaded active plugged /sys/devices/platform sys-devices-platform-serial8250-tty-ttyS1.device loaded active plugged /sys/devices/platform sys-devices-platform-serial8250-tty-ttyS10.device loaded active plugged /sys/devices/platfor sys-devices-platform-serial8250-tty-ttyS11.device loaded active plugged /sys/devices/platfor sys-devices-platform-serial8250-tty-ttyS12.device loaded active plugged /sys/devices/platfor sys-devices-platform-serial8250-tty-ttyS13.device loaded active plugged /sys/devices/platfor
啟動服務
要使用 systemctl 啟動服務,請使用以下命令,如下所示:
$ sudo systemctl start application.service
使用 systemctl 啟動服務的示例如下所示:
$ sudo systemctl start bluetooth.service
服務的狀況
要獲取 bluetooth.service 的狀態,如下所示:
$ systemctl status bluetooth
示例輸出應如下所示:
bluetooth.service - Bluetooth service Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2017-01-27 09:32:45 IST; 3 days ago Docs: man:bluetoothd(8) Main PID: 954 (bluetoothd) Status: "Running" CGroup: /system.slice/bluetooth.service └─954 /usr/lib/bluetooth/bluetoothd Jan 30 10:10:22 linux-Inspiron-3542 bluetoothd[954]: gatt-time-server: Input/output error (5) Jan 30 10:10:22 linux-Inspiron-3542 bluetoothd[954]: Not enough free handles to register service Jan 30 10:10:22 linux-Inspiron-3542 bluetoothd[954]: Not enough free handles to register service Jan 30 10:10:22 linux-Inspiron-3542 bluetoothd[954]: Sap driver initialization failed. Jan 30 10:10:22 linux-Inspiron-3542 bluetoothd[954]: sap-server: Operation not permitted (1) Jan 30 10:10:22 linux-Inspiron-3542 bluetoothd[954]: Endpoint registered: sender=:1.68 path=/Med Jan 30 10:10:22 linux-Inspiron-3542 bluetoothd[954]: Endpoint registered: sender=:1.68 path=/Med Jan 30 11:20:54 linux-Inspiron-3542 systemd[1]: Started Bluetooth service. Jan 30 11:21:07 linux-Inspiron-3542 systemd[1]: Started Bluetooth service. Jan 30 11:41:00 linux-Inspiron-3542 systemd[1]: Started Bluetooth service.
停止服務
要停止服務,請使用以下命令,如下所示:
$ sudo systemctl stop bluetooth.service
要驗證上述命令,請使用以下命令,如下所示:
$ systemctl status bluetooth
示例輸出應如下所示:
bluetooth.service - Bluetooth service Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled) Active: inactive (dead) since Mon 2017-01-30 11:45:35 IST; 4s ago Docs: man:bluetoothd(8) Main PID: 954 (code=exited, status=0/SUCCESS) Status: "Quitting" ..................................................................................
重新啟動服務
要重新啟動服務,請使用以下命令,如下所示:
$ sudo systemctl restart bluetooth.service
啟用服務
要啟用在啟動時啟動的服務,請使用以下命令,如下所示:
$ sudo systemctl enable bluetooth.service
停用服務
要停用在啟動時啟動的服務,請使用以下命令,如下所示:
$ sudo systemctl disable bluetooth.service
要驗證服務是否已啟用,請使用以下命令,如下所示:
$ sudo systemctl is-enabled bluetooth.service; echo $?
示例輸出應如下所示:
enabled 0
遮蔽服務
要遮蔽服務,請使用以下命令,如下所示:
$ sudo systemctl mask bluetooth.service
取消遮蔽服務
要取消遮蔽服務,請使用以下命令,如下所示:
$ sudo systemctl unmask bluetooth.service
殺死服務
要殺死服務,請使用以下命令,如下所示:
$ sudo systemctl kill bluetooth.service
配置詳細資訊
要獲取服務的配置詳細資訊,請使用以下命令,如下所示:
$ sudo systemctl show bluetooth
示例輸出應如下所示:
Restart=no NotifyAccess=none RestartUSec=100ms TimeoutStartUSec=1min 30s TimeoutStopUSec=1min 30s RuntimeMaxUSec=infinity WatchdogUSec=0 WatchdogTimestampMonotonic=0 ............................................................
分析服務的關鍵鏈
要分析服務的關鍵鏈,請使用以下命令,如下所示:
$ sudo systemd-analyze critical-chain bluetooth.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. bluetooth.service +886ms
依賴項列表
要獲取依賴項列表,請使用以下命令,如下所示:
$ sudo systemctl list-dependencies bluetooth.service
特定型別的單元列表
要獲取特定型別的單元列表,請使用以下命令,如下所示:
systemctl -t mount
示例輸出應如下所示:
UNIT LOAD ACTIVE SUB DESCRIPTION -.mount loaded active mounted / boot-efi.mount loaded active mounted /boot/efi dev-hugepages.mount loaded active mounted Huge Pages File System dev-mqueue.mount loaded active mounted POSIX Message Queue File System proc-sys-fs-binfmt_misc.mount loaded active mounted Arbitrary Executable File Formats File Syste run-user-1000-gvfs.mount loaded active mounted /run/user/1000/gvfs run-user-1000.mount loaded active mounted /run/user/1000 run-user-126.mount loaded active mounted /run/user/126 sys-fs-fuse-connections.mount loaded active mounted FUSE Control File System sys-kernel-debug.mount loaded active mounted Debug File System ....................................................................
所有已載入的單元
要顯示所有已載入的單元/屬性,包括已失效/空的單元,請使用以下命令,如下所示:
$ systemctl -a
示例輸出應如下所示:
UNIT LOAD ACTIVE SUB DESCRIPTION proc-sys-fs-binfmt_misc.automount loaded active running Arbitrary Executable File Forma ● org.freedesktop.network1.busname not-found inactive dead org.freedesktop.network1.busnam dev-cdrom.device loaded active plugged HL-DT-ST_DVD+_-RW_GU90N dev-cdrw.device loaded active plugged HL-DT-ST_DVD+_-RW_GU90N dev-disk-by\x2did-ata\x2dHL\x2dDT\x2dST_DVD\x2b_\x2dRW_GU90N_M7FE9H30316.device loaded acti dev-disk-by\x2did-ata\x2dTOSHIBA_MQ01ABD100_X4P6SQD0S.device loaded active plugged TOSH dev-disk-by\x2did-ata\x2dTOSHIBA_MQ01ABD100_X4P6SQD0S\x2dpart1.device loaded active plugg dev-disk-by\x2did-ata\x2dTOSHIBA_MQ01ABD100_X4P6SQD0S\x2dpart2.device loaded active plugg dev-disk-by\x2did-ata\x2dTOSHIBA_MQ01ABD100_X4P6SQD0S\x2dpart3.device loaded active plugg dev-disk-by\x2did-wwn\x2d0x50000395d5887d4c.device loaded active plugged TOSHIBA_MQ01AB dev-disk-by\x2did-wwn\x2d0x50000395d5887d4c\x2dpart1.device loaded active plugged TOSHI dev-disk-by\x2did-wwn\x2d0x50000395d5887d4c\x2dpart2.device loaded active plugged TOSHI dev-disk-by\x2did-wwn\x2d0x50000395d5887d4c\x2dpart3.device loaded active plugged TOSHI dev-disk-by\x2did-wwn\x2d0x5001480000000000.device loaded active plugged HL-DT-ST_DV ..............................................................................................
單元檔案列表
要獲取單元檔案列表,請使用以下命令,如下所示:
$ systemctl list-unit-files
示例輸出應如下所示:
UNIT FILE STATE proc-sys-fs-binfmt_misc.automount static dev-hugepages.mount static dev-mqueue.mount static proc-sys-fs-binfmt_misc.mount static sys-fs-fuse-connections.mount static sys-kernel-config.mount static sys-kernel-debug.mount static acpid.path enabled cups.path enabled systemd-ask-password-console.path static systemd-ask-password-plymouth.path static systemd-ask-password-wall.path static systemd-networkd-resolvconf-update.path static accounts-daemon.service enabled acpid.service disabled alsa-restore.service static alsa-state.service static alsa-utils.service masked anacron-resume.service enabled anacron.service enabled .................................................
指定單元檔案列表
要獲取指定單元檔案列表,請使用以下命令,如下所示:
$ sudo systemctl list-unit-files --type=moun
示例輸出應如下所示:
UNIT FILE STATE dev-hugepages.mount static dev-mqueue.mount static proc-sys-fs-binfmt_misc.mount static sys-fs-fuse-connections.mount static sys-kernel-config.mount static sys-kernel-debug.mount static 6 unit files listed. ......................................................
主機和本地容器的單元列表
要顯示主機和本地容器的單元列表,請使用以下命令,如下所示:
$ sudo systemctl -r
示例輸出應如下所示:
UNIT LOAD ACTIVE SUB DESCRIPTION proc-sys-fs-binfmt_misc.automount loaded active running Arbitrary Executable File Formats F sys-devices-pci0000:00-0000:00:02.0-drm-card0-card0\x2deDP\x2d1-intel_backlight.device loaded sys-devices-pci0000:00-0000:00:03.0-sound-card0.device loaded active plugged Haswell-ULT HD sys-devices-pci0000:00-0000:00:1b.0-sound-card1.device loaded active plugged 8 Series HD Aud sys-devices-pci0000:00-0000:00:1c.2-0000:06:00.0-net-wlp6s0.device loaded active plugged QCA sys-devices-pci0000:00-0000:00:1c.3-0000:07:00.0-net-enp7s0.device loaded active plugged RTL sys-devices-pci0000:00-0000:00:1d.0-usb1-1\x2d1-1\x2d1.6-1\x2d1.6:1.0-bluetooth-hci0.device lo sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda-sda1.device loade sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda-sda2.device loade sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda-sda3.device loade sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda.device loaded act sys-devices-pci0000:00-0000:00:1f.2-ata2-host1-target1:0:0-1:0:0:0-block-sr0.device loaded act sys-devices-platform-dell\x2dlaptop-leds-dell::kbd_backlight.device loaded active plugged ............................................................................................
排隊作業
要指定在排隊新作業時如何處理已排隊的作業,請使用以下命令,如下所示:
$ systemctl --job-mode=active
示例輸出應如下所示:
UNIT LOAD ACTIVE SUB DESCRIPTION proc-sys-fs-binfmt_misc.automount loaded active running Arbitrary Executable File Formats F sys-devices-pci0000:00-0000:00:02.0-drm-card0-card0\x2deDP\x2d1-intel_backlight.device loaded sys-devices-pci0000:00-0000:00:03.0-sound-card0.device loaded active plugged Haswell-ULT HD sys-devices-pci0000:00-0000:00:1b.0-sound-card1.device loaded active plugged 8 Series HD Aud sys-devices-pci0000:00-0000:00:1c.2-0000:06:00.0-net-wlp6s0.device loaded active plugged QCA sys-devices-pci0000:00-0000:00:1c.3-0000:07:00.0-net-enp7s0.device loaded active plugged RTL sys-devices-pci0000:00-0000:00:1d.0-usb1-1\x2d1-1\x2d1.6-1\x2d1.6:1.0-bluetooth-hci0.device lo sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda-sda1.device loade sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda-sda2.device loade sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda-sda3.device loade sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda.device loaded act sys-devices-pci0000:00-0000:00:1f.2-ata2-host1-target1:0:0-1:0:0:0-block-sr0.device loaded act sys-devices-platform-dell\x2dlaptop-leds-dell::kbd_backlight.device loaded active plugged /s sys-devices-platform-serial8250-tty-ttyS0.device loaded active plugged /sys/devices/platform sys-devices-platform-serial8250-tty-ttyS1.device loaded active plugged /sys/devices/platform sys-devices-platform-serial8250-tty-ttyS10.device loaded active plugged /sys/devices/platfor sys-devices-platform-serial8250-tty-ttyS11.device loaded active plugged /sys/devices/platfor sys-devices-platform-serial8250-tty-ttyS12.device loaded active plugged /sys/devices/platfor sys-devices-platform-serial8250-tty-ttyS13.device loaded active plugged /sys/devices/platfor sys-devices-platform-serial8250-tty-ttyS14.device loaded active plugged /sys/devices/plat ..............................................................................................
套接字型別
要獲取所有套接字型別,請使用以下命令,如下所示:
$ systemctl --show-types
示例輸出應如下所示:
UNIT LOAD ACTIVE SUB DESCRIPTION proc-sys-fs-binfmt_misc.automount loaded active running Arbitrary Executable File Formats F sys-devices-pci0000:00-0000:00:02.0-drm-card0-card0\x2deDP\x2d1-intel_backlight.device loaded sys-devices-pci0000:00-0000:00:03.0-sound-card0.device loaded active plugged Haswell-ULT HD sys-devices-pci0000:00-0000:00:1b.0-sound-card1.device loaded active plugged 8 Series HD Aud sys-devices-pci0000:00-0000:00:1c.2-0000:06:00.0-net-wlp6s0.device loaded active plugged QCA sys-devices-pci0000:00-0000:00:1c.3-0000:07:00.0-net-enp7s0.device loaded active plugged RTL sys-devices-pci0000:00-0000:00:1d.0-usb1-1\x2d1-1\x2d1.6-1\x2d1.6:1.0-bluetooth-hci0.device lo sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda-sda1.device loade sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda-sda2.device loade sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda-sda3.device loade sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda.device loaded act sys-devices-pci0000:00-0000:00:1f.2-ata2-host1-target1:0:0-1:0:0:0-block-sr0.device loaded act sys-devices-platform-dell\x2dlaptop-leds-dell::kbd_backlight.device loaded active plugged /s sys-devices-platform-serial8250-tty-ttyS0.device loaded active plugged /sys/devices/platform sys-devices-platform-serial8250-tty-ttyS1.device loaded active plugged /sys/devices/platf ........................................................................................
忽略抑制器
在關閉或休眠時忽略抑制器。請使用以下命令,如下所示:
$ systemctl -i
示例輸出應如下所示:
UNIT LOAD ACTIVE SUB DESCRIPTION proc-sys-fs-binfmt_misc.automount loaded active running Arbitrary Executable File Formats F sys-devices-pci0000:00-0000:00:02.0-drm-card0-card0\x2deDP\x2d1-intel_backlight.device loaded sys-devices-pci0000:00-0000:00:03.0-sound-card0.device loaded active plugged Haswell-ULT HD sys-devices-pci0000:00-0000:00:1b.0-sound-card1.device loaded active plugged 8 Series HD Aud sys-devices-pci0000:00-0000:00:1c.2-0000:06:00.0-net-wlp6s0.device loaded active plugged QCA sys-devices-pci0000:00-0000:00:1c.3-0000:07:00.0-net-enp7s0.device loaded active plugged RTL sys-devices-pci0000:00-0000:00:1d.0-usb1-1\x2d1-1\x2d1.6-1\x2d1.6:1.0-bluetooth-hci0.device lo sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda-sda1.device loade sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda-sda2.device loade sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda-sda3.device loade sys-devices-pci0000:00-0000:00:1f.2-ata1-host0-target0:0:0-0:0:0:0-block-sda.device loaded act sys-devices-pci0000:00-0000:00:1f.2-ata2-host1-target1:0:0-1:0:0:0-block-sr0.device loaded act sys-devices-platform-dell\x2dlaptop-leds-dell::kbd_backlight.device loaded active plugged /s sys-devices-platform-serial8250-tty-ttyS0.device loaded active plugged /sys/devices/platform sys-devices-platform-serial8250-tty-ttyS1.device loaded active plugged /sys/devices/platform sys-devices-platform-serial8250-tty-ttyS10.device loaded active plugged /sys/devices/platfor sys-devices-platform-serial8250-tty-ttyS11.device loaded active plugged /sys/devices/platfor sys-devices-platform-serial8250-tty-ttyS12.device loaded active plugged /sys/devices/platfor sys-devices-platform-serial8250-tty-ttyS13.device loaded active plugged /sys/devices/plat ............................................................................................
套接字資訊列表
要獲取套接字資訊列表,請使用以下命令,如下所示
$sudo systemctl list-unit-files --type=socket
示例輸出應如下所示:
UNIT FILE STATE acpid.socket enabled apport-forward.socket enabled avahi-daemon.socket enabled cups.socket enabled dbus.socket static saned.socket disabled snapd.socket enabled syslog.socket static systemd-bus-proxyd.socket static systemd-fsckd.socket static systemd-initctl.socket static ........................................................................
啟用套接字
要啟用套接字,請使用以下命令,如下所示:
$ sudo systemctl start saned.socket
在上述命令中,saned.socket 是單元檔案。
停止套接字
要停止套接字,請使用以下命令,如下所示:
$ sudo systemctl stop saned.socket
重新啟動套接字
要重新啟動套接字,請使用以下命令,如下所示:
$ sudo systemctl restart saned.socket
重新載入套接字
要重新載入套接字,請使用以下命令,如下所示:
$ sudo systemctl reload saned.socket
啟用套接字
要啟用套接字,請使用以下命令,如下所示:
$ sudo systemctl enable saned.socket
停用套接字
要停用套接字,請使用以下命令,如下所示:
$ sudo systemctl disable saned.socket
遮蔽套接字
要遮蔽套接字,請使用以下命令,如下所示:
$ sudo systemctl mask saned.socket
取消遮蔽套接字
要取消遮蔽套接字,請使用以下命令,如下所示:
$ sudo systemctl unmask saned.socket
套接字狀態
要獲取套接字的狀態,請使用以下命令,如下所示:
$ sudo systemctl status saned.socket
示例輸出應如下所示:
saned.socket - saned incoming socket Loaded: loaded (/lib/systemd/system/saned.socket; disabled; vendor preset: enabled) Active: active (listening) since Mon 2017-01-30 12:30:05 IST; 2min 59s ago Listen: [::]:6566 (Stream) Accepted: 0; Connected: 0 Jan 30 12:30:05 linux-Inspiron-3542 systemd[1]: Listening on saned incoming socket.
重新啟動系統
要重新啟動系統,請使用以下命令,如下所示:
$sudo systemctl reboot
掛起系統
要掛起系統,請使用以下命令,如下所示:
$sudo systemctl suspend
休眠系統
要休眠系統,請使用以下命令,如下所示:
$sudo systemctl hibernate
關閉系統
要關閉系統,請使用以下命令,如下所示:
$ sudo systemctl poweroff
關機
要關機,請使用以下命令,如下所示:
$sudo systemctl halt
在本文中,我們學習了有關“學習 Linux 上的現代服務管理系統 (Systemd)”的內容,我們將推出更多基於 Linux 的技巧和提示。請繼續關注!
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP