![如何在 RHEL7 / CentOS 7 中检查当前活动目标](https://linux22.com/image/1515590/%E5%A6%82%E4%BD%95%E5%9C%A8%20RHEL7%20%2F%20CentOS%207%20%E4%B8%AD%E6%A3%80%E6%9F%A5%E5%BD%93%E5%89%8D%E6%B4%BB%E5%8A%A8%E7%9B%AE%E6%A0%87.png)
在 RHEL 6 中我们可以运行runlevel
来检查系统的当前运行级别。
在 RHEL 7 中,我们有命令systemctl get-default
来检查默认目标,但是如何检查当前活动目标?
答案1
systemctl list-units --type target
以下是示例输出(它没有给出一行答案):
[root@ ~]# systemctl list-units --type target
UNIT LOAD ACTIVE SUB DESCRIPTION
basic.target loaded active active Basic System
cryptsetup.target loaded active active Encrypted Volumes
getty.target loaded active active Login Prompts
graphical.target loaded active active Graphical Interface
local-fs-pre.target loaded active active Local File Systems (Pre)
local-fs.target loaded active active Local File Systems
multi-user.target loaded active active Multi-User System
network-online.target loaded active active Network is Online
network.target loaded active active Network
nfs-client.target loaded active active NFS client services
nss-user-lookup.target loaded active active User and Group Name Lookups
paths.target loaded active active Paths
remote-fs-pre.target loaded active active Remote File Systems (Pre)
remote-fs.target loaded active active Remote File Systems
slices.target loaded active active Slices
sockets.target loaded active active Sockets
sound.target loaded active active Sound Card
swap.target loaded active active Swap
sysinit.target loaded active active System Initialization
timers.target loaded active active Timers
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.
20 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.
[root@ ~]# systemctl isolate multi-user.target
[root@ ~]# systemctl list-units --type target
UNIT LOAD ACTIVE SUB DESCRIPTION
basic.target loaded active active Basic System
cryptsetup.target loaded active active Encrypted Volumes
getty.target loaded active active Login Prompts
local-fs-pre.target loaded active active Local File Systems (Pre)
local-fs.target loaded active active Local File Systems
multi-user.target loaded active active Multi-User System
network-online.target loaded active active Network is Online
network.target loaded active active Network
nfs-client.target loaded active active NFS client services
paths.target loaded active active Paths
remote-fs-pre.target loaded active active Remote File Systems (Pre)
remote-fs.target loaded active active Remote File Systems
slices.target loaded active active Slices
sockets.target loaded active active Sockets
swap.target loaded active active Swap
sysinit.target loaded active active System Initialization
timers.target loaded active active Timers
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.
17 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.
[root@ ~]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
[root@ ~]#
我们从 graphic.target 开始,第一次执行命令时,我们可以看到 multi-user.target 和 graphic.target。这是因为 graphic.target 需要 multi-user.target。
接下来我们切换到 multi-user.target。如果你看到 multi-user.target 但没有看到 graphic.target,那么我们处于多用户目标中。
另外两个常见目标是 rescue.target 和 emergency.target。
- 如果您看到 rescue.target,则表明您位于救援目标中。
- 如果您看到 emergency.target,则您处于紧急目标中。