Linux系统有7个运行级别(runlevel)

运行级别0:系统停机状态,系统默认运行级别不能设为0,否则不能正常启动 运行级别1:单用户工作状态,root权限,用于系统维护,禁止远程登陆 运行级别2:多用户状态(没有NFS) 运行级别3:完全的多用户状态(有NFS),登陆后进入控制台命令行模式 运行级别4:系统未使用,保留 运行级别5:X11控制台,登陆后进入图形GUI模式 运行级别6:系统正常关闭并重启,默认运行级别不能设为6,否则不能正常启动

Cent 6

运行级别的原理: 1.在目录/etc/rc.d/init.d下有许多服务器脚本程序,一般称为服务(service) 2.在/etc/rc.d目录下有7个名为rcN.d的目录,对应系统的7个运行级别 3.rcN.d目录下都是一些符号链接文件,这些链接文件都指向init.d目录下的service脚本文件,命名规则为K+nn+服务名或S+nn+服务名,其中nn为两位数字。 4.系统会根据指定的运行级别进入对应的rcN.d目录,并按照文件名顺序检索目录下的链接文件 对于以K开头的文件,系统将终止对应的服务 对于以S开头的文件,系统将启动对应的服务 5.查看运行级别用:runlevel 6.进入其它运行级别用:init N 7.关机 init 0 ,halt,shutdown 重启 init 6,reboot, shutdown -r

Cent7

运行级别原理,从Cent7开始,Linux 开始使用以systemd为初始进程取代init. 1.在/etc/systemd为 systemd主目录包括配置文件及默认启动级别 2.在/etc/systemd/system 中,包括了默认启动级别的连接文件 default.target,如果需要更改默认启动级别,将default.target指向 /lib/systemd/system/ 目录下的默认文件 3.在/etc/systemd/system中,也包括了每种runlevel的默认启动服务的保存目录,如果要在某个runlevel默认启动服务,则需要将这些服务指向到这个目录. 4.查看运行级别 runlevel 5.进入其它运行级别 init N

启动运行等级5,即图形模式 systemctl isolate runlevel5.target systemctl isolate graphical.target

启动运行等级3,即多用户模式(命令行)

systemctl isolate runlevel3.target systemctl isolate multiuser.target

 实际中遇到的问题
 cent7装了 server GUI   通过 yum remove gnome*  删除之后
			 误删除 /usr/lib/systemd/system/runlevel 文件 导致进不去系统
			 进入rescue 模式 ,  原系统默认挂载到 /mnt/sysimage/下 
			 光盘系统 是默认的/目录,
				 从/usr/lib/systemd/system/ 下复制 相对应的文件 或所有文件
			                   到/mnt/sysimage/usr/lib/systemd/system/下
												 然后在  /mnt/sysimage/etc/systemd/system 下修改default.target 链接文件的指向,然后重启计算机,解决故障

区别清楚runlevel 和 图形化界面 runlevel 是运行等级 图形化界面x window 是一个应该程序

6.关机 init 0 ,halt,shutdown 重启 init 6,reboot, shutdown -r 7.systemd 采用全新的 systemctl 管理工具统一管理, 开启服务 systemctl start service 关闭服务 systemctl stop service 开机启动 systemctl enable service , 将/etc/systemd/system 对应级别中加入服务软链接 禁止启动 systemctl disable service 移除/etc/systemd/system 对应级别中加入服务软链接 查看状态 systemclt list-units systemctl list-unit-files