(1).首先需要了解Linux的七個運行級別
0 系統停機魔石,系統默認運行級別不能設置為0,否則不能正常啟動 1 單用戶模式,root權限,用於系統維護,禁止遠程登錄,就像Windows下的安全模式登錄 2 多用戶模式,沒有NFS和網絡支持 3 完整的多用戶文本模式,有NFS和網絡,登錄后進入控制台命令行模式 4 系統未使用,保留一般不用,在一些特殊情況下可以用它來做一些事情。例如在筆記本電腦的電池用盡時,可以切換到這個模式來做一些設置 5 圖形化模式,登錄后進入圖形GUI模式,X Windows系 6 重啟模式,默認運行級別不能設置為6,否則不能正常啟動。運行init 6機器就會重啟。
這七個啟動級別最簡單的使用方法:
init [0~6]
作用是切換系統運行級別
[xf@xuexi ~]$ init 0 //關機 [xf@xuexi ~]$ init 3 //進入字符界面 [xf@xuexi ~]$ init 5 //進入圖形界面
(2)如何設置默認的運行級別呢
CentOS7不再使用/etc/inittab文件進行默認的啟動級別配置,而使用比sysvinit的運行級別更為自由的target替代。
第3運行級用multi-user.target替代
第5運行級用graphical.target替代
設置默認第3運行級別
[xf@xuexi ~]$ 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.
設置默認第5運行級別
[xf@xuexi ~]$ systemctl set-default graphical.target Removed symlink /etc/systemd/system/default.target. Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/graphical.target.
這是直接從5運行級別啟動
[xf@xuexi ~]$ runlevel N 5
這是從3運行級別切到5運行級別
[xf@xuexi ~]$ runlevel 3 5
查看當前默認的啟動級別
[xf@xuexi ~]$ systemctl get-default graphical.target
