通常情况下,centos6和其他Linux的版本都可以通过修改/etc/inittab文件来设置启动模式。启动模式一般如下几种,在服务器模式下,最常用的就是模式3。
# Default runlevel. The runlevels used are: # 0 - halt (Do NOT set initdefault to this) # 1 - Single user mode # 2 - Multiuser, without NFS (The same as 3, if you do not have networking) # 3 - Full multiuser mode # 4 - unused # 5 - X11 # 6 - reboot (Do NOT set initdefault to this)
但是CentOS7之后(含Centos Stream),上述方法已经被弃用了,打开/etc/inittab文件,会显示如下内容:
# inittab is no longer used. # ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM. # Ctrl-Alt-Delete is handled by /usr/lib/systemd/system/ctrl-alt-del.target # systemd uses 'targets' instead of runlevels. By default, there are two main targets: # multi-user.target: analogous to runlevel 3 # graphical.target: analogous to runlevel 5 # To view current default target, run: # systemctl get-default # To set a default target, run: # systemctl set-default TARGET.target
按照上述内容,要查询当前启动级别,需要使用systemctl get-default查询,设置启动级别,需要使用systemctl set-default TARGET.target来设置。例如要设置多用户命令含模式启动,就需要使用systemctl set-default.multi-user.target来设置。