1、针对Centos6版本,打开配置文件/etc/inittab

[root@localhost ~]# vi /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)
# 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)
#
id:5:initdefault:

修改 id:5:initdefault:​id:3:initdefault:​,保存退出。

设置Linux(Centos6、Centos7)不启动图形界面(startx命令可启动图形界面)_sed


2、 针对Centos7版本

【说明】: 新版本的CentOS 系统里使用’targets’ 取代了运行级别的概念。系统有两种默认的’targets’: 多用户.target 对应之前版本的3 运行级别; 而图形.target 对应之前的5运行级别。

第1种:查看默认的target,执行:
​​​systemctl get-default​

第2种:开机以命令模式启动,执行:
​​​systemctl set-default multi-user.target​

第3种:开机以图形界面启动,执行:
​​​systemctl set-default graphical.target​

【具体方法】:直接在命令窗口执行以下命令打开命令行模式启动(如下图):

[root@localhost ~]# systemctl set-default multi-user.target

可参考如下图:

设置Linux(Centos6、Centos7)不启动图形界面(startx命令可启动图形界面)_sed_02


3、重启系统

[root@localhost ~]# reboot

4、从命令行启动图形界面

[root@localhost /]# startx