尚硅谷韩顺平(推荐):https://www.bilibili.com/video/BV1dW411M7xL?from=search&seid=8072051292168114337
大佬榜:https://blog.csdn.net/capecape/article/details/78528761
指定运行级别
| 运行级别说明: |
| 0:关机 |
| 1:单用户【找回丢失密码】 |
| 2:多用户状态没有网路服务 |
| 3:多用户状态有网路服务(使用最多) |
| 4:系统未使用保留给用户 |
| 5:图形界面 |
| 6:系统重启 |
| |
| 常用运行级别是3和5,要修改默认的运行级别可修改文件: |
| /etc/inittab 的 id:5:initdefault: 这一行中的数字 |
| 命令:init[0123456] |
在centos7下运行vim /etc/inittab结果如下:

| 注释内容大意是说, |
| |
| # multi-user.target类似于runlevel 3; |
| # graphical.target类似于runlevel5 |
| |
| #查看默认运行级别的方式为 |
| systemctl get-default |
| |
| #设置默认运行级别的方式 |
| systemctl set-default TARGET.target |
运行级别对应表:
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] |
| |
| 参数详解: |
| command: |
| get-default :取得当前的target |
| set-default :设置指定的target为默认的运行级别 |
| isolate :切换到指定的运行级别 |
systemctl |
命令 说明 |
systemctl get-default |
获得当前的运行级别 |
systemctl set-default multi-user.target |
设置默认的运行级别为mulit-user |
systemctl isolate multi-user.target |
在不重启的情况下,切换到运行级别mulit-user下 |
systemctl isolate graphical.target |
在不重启的情况下,切换到图形界面下 |
注:该表前两行是设置默认运行级别,后两行是设置当前运行级别。
切换到指定运行级别
| centos7 不再使用/etc/inittab文件进行默认的启动级别配置,而使用比sysvinit的运行级更为自由的target替代。 |
| |
| 第3运行级用:multi-user.target替代。 |
| 第5运行级用:graphical.target替代。 |
| |
| 设置默认第三启动级别: |
| [root@xuegod63 ~]# systemctl set-default multi-user.target |
| 设置默认第五启动级别: |
| [root@xuegod63 ~]# systemctl set-default graphical.target |
| |
| 查看当前默认的启动级别: |
| systemctl get-default |
| |
| 查看当前运行的级别: |
| runlevel |
| |

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步