Linux运行级别

Posted LEO00

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux运行级别相关的知识,希望对你有一定的参考价值。

Linux运行级别

运行级别介绍

运行级别就是操作系统当前正在运行的功能级别,级别是从0到6。Centos7系统之前的版本是通过/etc/inittab文件来定义系统,而CentOS7用的是/lib/systemd/system/runlevel*

实际操作

[[email protected] ~]# cat /etc/redhat-release
CentOS release 6.7 (Final)

[[email protected] ~]# cat /etc/inittab
# inittab is only used by upstart for the default runlevel.
#
# ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# System initialization is started by /etc/init/rcS.conf
#
# Individual runlevels are started by /etc/init/rc.conf
#
# Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf
#
# Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf,
# with configuration in /etc/sysconfig/init.
#
# For information on how to write upstart event handlers, or how
# upstart works, see init(5), init(8), and initctl(8).
#
# Default runlevel. The runlevels used are:
# 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,否则不能正常启动
#

id:3:initdefault:    # 表示运行级别3,是默认的

CentOS 7 版本不再/etc/inittab使用该文件定义系统运行级别,相关运行级别设置无效;新版本的运行级别都定义在/lib/systemd/system/runlevel*

[[email protected] ~]# cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core)

[[email protected] ~]# ll /lib/systemd/system/runlevel*
lrwxrwxrwx. 1 root root 15 Dec 3 2017 /lib/systemd/system/runlevel0.target -> poweroff.target
lrwxrwxrwx. 1 root root 13 Dec 3 2017 /lib/systemd/system/runlevel1.target -> rescue.target
lrwxrwxrwx. 1 root root 17 Dec 3 2017 /lib/systemd/system/runlevel2.target -> multi-user.target
lrwxrwxrwx. 1 root root 17 Dec 3 2017 /lib/systemd/system/runlevel3.target -> multi-user.target
lrwxrwxrwx. 1 root root 17 Dec 3 2017 /lib/systemd/system/runlevel4.target -> multi-user.target
lrwxrwxrwx. 1 root root 16 Dec 3 2017 /lib/systemd/system/runlevel5.target -> graphical.target
lrwxrwxrwx. 1 root root 13 Dec 3 2017 /lib/systemd/system/runlevel6.target -> reboot.target

7版本和之前版本对应

init级别systemctl target
0 shutdown.target
1 emergency.target
2 rescure.target
3 multi-user.target
4
5 graphical.target
6

设置运行级别

命令格式:
systemctl [command] [unit.target]
参数详解:
- get-default:获取当前的target
- set-default:设置指定的target为默认的运行级别
- isolate:切换到指定的运行级别

[[email protected] ~]# systemctl get-default #获取当前运行级别
[[email protected] ~]# systemctl set-default multi-user.target #设置默认运行级别为multi-user
[[email protected] ~]# systemctl isolate multi-user.target #在不重启情况下,切换到multi-user
[[email protected] ~]# systemctl isolate graphical.target #在不重启的情况下,切换到图形界面











































以上是关于Linux运行级别的主要内容,如果未能解决你的问题,请参考以下文章

linux运行级别简介

linux系统的运行级别

Linux系统有7个运行级别

linux 系统的7个运行级别

Linux 运行级别

Linux:检查当前运行级别的五种方法