Systemd是用于Linux的古代初始化零碎:与风行的SysV初始化零碎和LSB初始化脚本兼容的零碎服务管理器。
在Linux零碎上,操作系统的以后操作状态称为运行级别;它定义了正在运行的零碎服务。在Centos6之前的零碎种应用SysV init,运行级别由数字标识。然而,在systemd中,运行级别称为targets。
在本文中,将解释如何应用systemd更改运行级别(targets)。在持续进行之前,简要介绍一下运行级别数字与targets之间的关系:
level 0与poweroff.target匹配,(runlevel0.target是指向poweroff.target的符号链接)。
level 1与rescue.target匹配,(runlevel1.target是指向rescue.target的符号链接)。
level 3由multi-user.target匹配,(runlevel3.target是指向multi-user.target的符号链接)。
level 5由graphic.target匹配,(runlevel5.target是指向graphic.target的符号链接)。
level 6由reboot.target匹配,(而runlevel6.target是指向reboot.target的符号链接)。
Emergency与emergency.target匹配。
如何在Systemd中查看以后targets(运行级别)
系统启动时,默认状况下,systemd激活default.target单元。它的次要工作是通过依赖关系来激活服务和其余单元。要查看默认指标,输出上面的命令:
[root@localhost ~]# systemctl get-default
multi-user.target
Centos8种如何更改运行级别Centos8种如何更改运行级别
如何在Systemd中设置默认的targets(运行级别)
要设置默认指标,请运行以下命令。
[root@localhost ~]# systemctl set-default graphical.target
Removed /etc/systemd/system/default.target.
Created symlink /etc/systemd/system/default.target → /usr/lib/systemd/system/graphical.target.
Centos8种如何更改运行级别Centos8种如何更改运行级别
在零碎运行中切换targets(运行级别)
在零碎运行时,能够切换targets(运行级别),这意味着只有服务以及在该target下定义的单元才会在零碎上运行。
要切换到运行级别5(graphical.target),请运行以下命令,前提是曾经装置了图形界面。
[root@localhost ~]# systemctl isolate runlevel5.target
或者
[root@localhost ~]# systemctl isolate graphical.target
执行完命令,会立即进入图形界面。
Centos8种如何更改运行级别Centos8种如何更改运行级别
Centos8种如何更改运行级别Centos8种如何更改运行级别
总结
在本文汇总展现了在Centos8零碎种,如何应用systemd更改运行级别(targets)。