Linux系统的运行级别
查看Linux系统运行级别信息:
CentOS6系列:
1 [root@localhost ~]# cat /etc/inittab 2 # inittab is only used by upstart for the default runlevel. 3 # ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM. 4 # System initialization is started by /etc/init/rcS.conf 5 # Individual runlevels are started by /etc/init/rc.conf 6 # Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf 7 # Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf, 8 # with configuration in /etc/sysconfig/init. 9 # For information on how to write upstart event handlers, or how 10 # upstart works, see init(5), init(8), and initctl(8). 11 # Default runlevel. The runlevels used are: 12 # 0 - halt (Do NOT set initdefault to this)#系统停机状态,系统默认运行级别不能设为0,否则不能正常开机,运行init 0机器就会关机 13 # 1 - Single user mode #单用户工作状态,root权限,用于系统维护,禁止远程登陆,修改root密码 14 # 2 - Multiuser, without NFS (The same as 3, if you do not have networking) #多用户状态(没有NFS),没有网络 15 # 3 - Full multiuser mode #完全的多用户状态(有NFS),登陆后进入控制台命令行模式 16 # 4 - unused #系统未使用,保留 17 # 5 - X11 #X11控制台,登陆后进入图形GUI模式,图形化界面 18 # 6 - reboot (Do NOT set initdefault to this)#系统正常关闭并重启,默认运行级别不能设为6,否则不能正常启动(循环重启),运行init 6机器就会重启。 19 # 20 id:3:initdefault: #默认运行级别3,控制台命令行模式 21 [root@localhost ~]#
1 [root@localhost ~]# runlevel #查看当前运行级别,返回结果中,第一个数为之前运行级别,后一个数为当前运行级别 2 N 3
CentOS7系列:
1 [root@localhost ~]# cat /etc/inittab 2 # inittab is no longer used when using systemd. 3 # ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM. 4 # Ctrl-Alt-Delete is handled by /usr/lib/systemd/system/ctrl-alt-del.target 5 # systemd uses 'targets' instead of runlevels. By default, there are two main targets: 6 # 7 # multi-user.target: analogous to runlevel 3 #multi-user.target类似于runlevel 8 # graphical.target: analogous to runlevel 5 #graphical.target类似于runlevel5 9 # 10 # To view current default target, run: 11 # systemctl get-default #查看默认运行级别的方式 12 # 13 # To set a default target, run: 14 # systemctl set-default TARGET.target #设置默认运行级别的方式 15 # 16 [root@localhost ~]#
查看默认运行级别:
1 [root@localhost ~]# systemctl get-default 2 multi-user.target
修改运行级别(图形界面):
1 [root@localhost ~]# systemctl set-default graphical.target
1. 运行级别设置
1)语法:systemctl [command] [unit.target]
2)命令及参数:
command部分
get-default :获取当前的target;
set-default :将默认运行级别设置为指定的target;
isolate :切换至指定的运行级别。
unit.target部分:为上面给出的运行级别
2. 常用运行级别相关命令
1)systemctl
systemctl get-default:获取当前的运行级别;
systemctl set-default multi-user.target:将默认运行级别设置为mulit-user;
systemctl isolate multi-user.target:不重启系统的情况下,将运行级别切换至mulit-user;
systemctl isolate graphical.target:不重启系统的情况下,将运行级别切换至图形模式。
2) 其他
runlvel:返回结果中,第一个数为之前运行级别,后一个数为当前运行级别;
init 5:将当前运行级别切换至5(图形模式)。