Centos8种如何更改运行级别

导读 Systemd是用于Linux的现代初始化系统:与流行的SysV初始化系统和LSB初始化脚本兼容的系统服务管理器。

Linux系统上,操作系统的当前操作状态称为运行级别;它定义了正在运行的系统服务。在Centos6之前的系统种使用SysV init,运行级别由数字标识。但是,在systemd中,运行级别称为targets。

在本文中,将解释如何使用systemd更改运行级别(targets)。在继续进行之前,简要介绍一下运行级别数字与targets之间的关系:

  • level 0poweroff.target匹配,(runlevel0.target是指向poweroff.target的符号链接)。
  • level 1rescue.target匹配,(runlevel1.target是指向rescue.target的符号链接)。
  • level 3multi-user.target匹配,(runlevel3.target是指向multi-user.target的符号链接)。
  • level 5graphic.target匹配,(runlevel5.target是指向graphic.target的符号链接)。
  • level 6reboot.target匹配,(而runlevel6.target是指向reboot.target的符号链接)。
  • Emergencyemergency.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)。Linux就该这么学

猜你喜欢

转载自blog.csdn.net/Linuxprobe18/article/details/111941862