CentOS 作为服务器的操作系统是很常见的,但是因为需要稳定而没有很时髦的更新,所以很少做为桌面环境。在服务器上通常不需要安装桌面环境,最小化地安装 CentOS(也就是 minimal CentOS)就可以了。不过在最小化安装的 CentOS 中通过 YUM 来安装桌面环境也是非常方便的。
单位的那台服务器上就让我安装了最小化的 CentOS 操作系统。但是同事说操作不方便,所以我就试了试,顺便记录这个安装方法。使用 yum groupinstall 指令很容易就能安装上图形界面的桌面系统。
1. yum 的 group 指令
yum 可以以程序组的模式来安装成套的软件包。支持的软件包可以通过,
# yum grouplist
1
# yum grouplist
查询到。在 group 软件包中,
对于CentOS 6,Desktop、Desktop Platform、KDE Desktop、X Window System 是主要的桌面环境。
对于CentOS 7,有 KDE Plasma Workspaces 和 Gnome Desktop 两大桌面环境。
在 CentOS 7 上的返回结果如下,
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.usc.edu
* extras: mirror.lug.udel.edu
* updates:
Available environment groups:
Minimal Install
Compute Node
Infrastructure Server
File and Print Server
Basic Web Server
Virtualization Host
Server with GUI
GNOME Desktop
KDE Plasma Workspaces
Development and Creative Workstation
Installed groups:
Graphical Administration Tools
Legacy UNIX Compatibility
Security Tools
System Administration Tools
Available Groups:
Compatibility Libraries
Console Internet Tools
Development Tools
Scientific Support
Smart Card Support
System Management
Done
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Loadedplugins:fastestmirror,langpacks
Loadingmirrorspeedsfromcachedhostfile
*base:mirrors.usc.edu
*extras:mirror.lug.udel.edu
*updates:
Availableenvironmentgroups:
MinimalInstall
ComputeNode
InfrastructureServer
FileandPrintServer
BasicWebServer
VirtualizationHost
ServerwithGUI
GNOMEDesktop
KDEPlasmaWorkspaces
DevelopmentandCreativeWorkstation
Installedgroups:
GraphicalAdministrationTools
LegacyUNIXCompatibility
SecurityTools
SystemAdministrationTools
AvailableGroups:
CompatibilityLibraries
ConsoleInternetTools
DevelopmentTools
ScientificSupport
SmartCardSupport
SystemManagement
Done
软件包列表根据系统使用的语言来显示,支持简体中文文件名。所以安装前最好用上述指令查询一下看看。如果系统使用了简体中文,而安装指令使用英文,可能会导致查询不到软件包这样的错误。下面的安装指令用的都是英语。
2. 安装图形桌面环境
CENTOS 7
CentOS 7 上的桌面环境安装包组合进行了调整,比以前要简单了。主要有两大阵营,KDE 和 GNOME。
因为没时间测试,只是预估着下面的指令应该能完成任务,请注意!
要安装 KDE 桌面环境(使用的是 Plasma 作为默认的桌面管理器了,很漂亮,看这里),
# yum groupinstall "KDE Plasma Workspaces"
1
# yum groupinstall "KDE Plasma Workspaces"
要安装 GNOME 环境,
# yum groupinstall "GNOME Desktop"
1
# yum groupinstall "GNOME Desktop"
安装程序会自动解决安装包和组件的依赖关系。
CENTOS 6
要安装 KDE 桌面环境,执行指令,
# yum groupinstall "X Window System" "KDE Desktop" Desktop
1
# yum groupinstall "X Window System" "KDE Desktop" Desktop
即可,同时安装了 3 个软件包。注意,因为KDE Desktop和 X Window System 两个软件包名称中间都包含空格,需要用引号引起来才行。
要安装 Gnome 桌面环境,执行指令,
# yum groupinstall "X Window System" "Desktop Platform" Desktop
1
# yum groupinstall "X Window System" "Desktop Platform" Desktop
即可,也是同时安装了 3 个软件包,其中 X Window System 是必须的,不管是 Gnome 还是 KDE。
既然是桌面环境,可能还需要诸如字体、管理工具之类的,如,
# yum -y groupinstall "Graphical Administration Tools"
# yum -y groupinstall "Internet Browser"
# yum -y groupinstall "General Purpose Desktop"
# yum -y groupinstall "Office Suite and Productivity"
# yum -y groupinstall "Graphics Creation Tools"
1
2
3
4
5
# yum -y groupinstall "Graphical Administration Tools"
# yum -y groupinstall "Internet Browser"
# yum -y groupinstall "General Purpose Desktop"
# yum -y groupinstall "Office Suite and Productivity"
# yum -y groupinstall "Graphics Creation Tools"
3. 启用
从命令行直接启动图形桌面环境,
# startx
1
# startx
这样就会启动默认的 Gnome 或者 KDE 桌面环境。如果有人喜欢同时安装 GNOME 和 KDE,切换方法可以参考CentOS 文档。
如果希望启动时自动启动到图形桌面,需要修改启动配置。因为 CentOS 7 开始使用 systemd 管理器,其操作方式与之前版本有所不同。
CENTOS 7
CentOS 7 中直接使用 systemd 指令修改启动目的状态即可。
使用,
# systemctl get-default
1
# systemctl get-default
可以查询到当前所设定的状态。multi-user.target 相当于以前的 level 3,也就是命令行终端;而graphical.target 相当于以前的 level 5,也就是图形界面。
所以如果要设置默认启动到图形界面,则执行,
# systemctl set-defaultgraphical.target
1
# systemctl set-defaultgraphical.target
CENTOS 6 等
编辑/etc/inittab,将id:3:initdefault:改为id:5:initdefault:。(请注意这里的英文半角冒号。)参考这里。
直接用 sed 会很方便,
sed -i 's/id:3:initdefault:/id:5:initdefault:/' /etc/inittab
1
sed-i's/id:3:initdefault:/id:5:initdefault:/'/etc/inittab
启动图形界面后,如果希望从图形界面切换到命令行界面,可以用Ctrl + Alt + F6(实际上 F1 到 F6 都行,不过它们代表 Linux 中不同的控制台),或者反过来Ctrl + Alt + F7回到刚才的图形界面。
messagebus 默认关闭导致 Gnome 无法使用
问题现象:
在 CentOS 系统上按照正常流程安装 Gnome 桌面环境,重启后发现无法登录系统。表现为:输入账户、密码后,出现如下错误提示,而且相应的错误信息无法取消,无法做任何操作。
"You are currently trying to run as the root super user. The super user is a specialized account that is not designed to run a normal user session. Various programs will not function properly, and actions performed under this account can cause unrecoverable damage to the operating system."
1
"You are currently trying to run as the root super user. The super user is a specialized account that is not designed to run a normal user session. Various programs will not function properly, and actions performed under this account can cause unrecoverable damage to the operating system."
处理办法:
该问题可能是由于桌面环境所依赖的 messgebus 和 haldaemon 服务没有自动启动所致。为了提高系统性能和稳定性,ECS Linux 服务器官方公共镜像未自动启动上述服务。
由于产生该错误的时候,用户无法做任何操作,用户可以尝试通过如下方式解决该问题:
通过历史快照回滚系统。
重新安装桌面环境。
使用如下方式修改上述服务为自启动:
chkconfig --level 35 haldaemon on
chkconfig --level 35 messagebus on
1
2
chkconfig--level35haldaemonon
chkconfig--level35messagebuson
说明:保险起见,建议将启动级别修改为 Level 3 而非默认的 Lever 5,然后通过 startx 命令手工启动桌面环境,以测试桌面环境的可用性。这样,在出现问题时还可以切换到终端模式进行问题排查和处理。最后,在确保桌面环境启动无误后,再将启动级别修改为 Level 5。
小杰博客 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:linux安装图形化界面