Linux運行級別
運行級別介紹
運行級別就是操作系統當前正在運行的功能級別,級別是從0到6。Centos7系統之前的版本是通過/etc/inittab文件來定義系統,而CentOS7用的是/lib/systemd/system/runlevel*
實際操作
[root@db01 ~]# cat /etc/redhat-release
CentOS release 6.7 (Final)
[root@db01 ~]# 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*
[root@db01 ~]# cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core)
[root@db01 ~]# 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:切換到指定的運行級別
[root@localhost ~]# systemctl get-default #獲取當前運行級別
[root@localhost ~]# systemctl set-default multi-user.target #設置默認運行級別為multi-user
[root@localhost ~]# systemctl isolate multi-user.target #在不重啟情況下,切換到multi-user
[root@localhost ~]# systemctl isolate graphical.target #在不重啟的情況下,切換到圖形界面
