linux运行级别
1、运行级别
运行级别 定义了在 Linux 系统的目前状态(或运行级别)下能够完成哪些任务。每个 Linux 系统支持三种基本的运行级别,以及完成正常操作所需的一个或多个运行级别。一共有七种运行级别,如下。常用的运行级别有3和5,单用户模式常用于忘记密码重新设置root密码。
0 - halt (Do NOT set initdefault to this) # 运行级别0:系统停机状态,系统默认运行级别不能设为0,否则不能正常启动
1 - Single user mode # 运行级别1:单用户工作状态,root权限,用于系统维护,禁止远程登陆
2 - Multiuser, without NFS (The same as 3, if you do not have networking) #运行级别2:多用户状态(没有NFS)
3 - Full multiuser mode #运行级别3:完全的多用户状态(有NFS),登陆后进入控制台命令行模式
4 - unused #运行级别4:系统未使用,保留
5 - X11 #运行级别5:X11控制台,登陆后进入图形GUI模式
6 - reboot (Do NOT set initdefault to this) #运行级别6:系统正常关闭并重启,默认运行级别不能设为6,否则不能正常启动
2、查看运行级别
runlevel、systemctl命令用于查看当前系统的运行级别
[[email protected]_0_11_centos ~]# runlevel
N 3
[[email protected]_0_11_centos ~]#
运行级别定义在/lib/systemd/system下
[[email protected]_0_11_centos ~]# ll /lib/systemd/system/runlevel*
lrwxrwxrwx 1 root root 15 Dec 8 08:31 /lib/systemd/system/runlevel0.target -> poweroff.target
lrwxrwxrwx 1 root root 13 Dec 8 08:31 /lib/systemd/system/runlevel1.target -> rescue.target
lrwxrwxrwx 1 root root 17 Dec 8 08:31 /lib/systemd/system/runlevel2.target -> multi-user.target
lrwxrwxrwx 1 root root 17 Dec 8 08:31 /lib/systemd/system/runlevel3.target -> multi-user.target
lrwxrwxrwx 1 root root 17 Dec 8 08:31 /lib/systemd/system/runlevel4.target -> multi-user.target
lrwxrwxrwx 1 root root 16 Dec 8 08:31 /lib/systemd/system/runlevel5.target -> graphical.target
lrwxrwxrwx 1 root root 13 Dec 8 08:31 /lib/systemd/system/runlevel6.target -> reboot.target
3、原理
rcN.d目录下都是一些软符号链接,指向/etc/init.d/下的服务脚本,系统启动时,会根据指定的运行级别进入对应的rcN.d目录,并按照文件名顺序检索目录下的链接文件:对于以K开头的文件,系统将终止对应的服务; 对于以S开头的文件,系统将启动对应的服务。
[[email protected]_0_11_centos rc.d]# cd rc0.d/
[[email protected]_0_11_centos rc0.d]# ll
total 0
lrwxrwxrwx. 1 root root 20 Mar 6 2019 K50netconsole -> ../init.d/netconsole
lrwxrwxrwx. 1 root root 17 Mar 6 2019 K90network -> ../init.d/network
[[email protected]_0_11_centos rc0.d]#
4、设置运行级别
[[email protected]_0_11_centos rc0.d]# systemctl set-default multi-user.target
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/multi-user.target.
[[email protected]_0_11_centos rc0.d]#
[[email protected]_0_11_centos rc0.d]# init 3
[[email protected]_0_11_centos rc0.d]#
# inittab is no longer used when using systemd.
#
# ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# Ctrl-Alt-Delete is handled by /usr/lib/systemd/system/ctrl-alt-del.target
#
# systemd uses 'targets' instead of runlevels. By default, there are two main targets:
#
# multi-user.target: analogous to runlevel 3
# graphical.target: analogous to runlevel 5
#
# To view current default target, run:
# systemctl get-default
#
# To set a default target, run:
# systemctl set-default TARGET.target
id:3:initdefault
~
上一篇: CSS弹性盒模型flex在布局中的应用
下一篇: js循环的总结