Installing the Graphical Window System (X.org-X11) and the Default Desktop Environment on CentOS 6

本文介绍如何在CentOS 6最小安装的基础上安装图形界面系统(X.org-X11)及桌面环境(GNOME或KDE),包括所需安装的软件包组及其配置方法。

Posted 09-06-2011 at 01:12 PM by gearge 

Updated 11-26-2011 at 02:29 PM by  gearge
Tags  centos 6gnomeinstallkdeminimal

Installing the Graphical Window System (X.org-X11) and the Default Desktop Environment on CentOS 6

Performing the default "Minimal" install of CentOS 6 does not install the graphical subsystem (the X.org server) and the desktop environment (e.g. GNOME or KDE). Such OS install is nice for building an optimal system from scratch, setting up a headless server (no monitor, keyboard and mouse) and other purposes; but for one reason or another, you may still require a graphical user interface (GUI). This tutorial will show you how to install and start the graphical window system and the desktop environment of your choice.

To achieve the task, you will need to install the following package groups (groups of packages combined for a common purpose): "X Window System", "Desktop", "Fonts" and "General Purpose Desktop" (last two are optional). This will install about 500 additional packages on your system (~250MB download, or you may use the available OS installation DVD to retrieve packages).

Code:
yum -y groupinstall "X Window System" "Desktop" "Fonts" "General Purpose Desktop"
(Please enter this as is - package group names as well as package names are case sensitive).

Previous versions of RHEL and its derivatives provided a package group called "GNOME Desktop Environment", that was sufficient for a general purpose GNOME desktop. Currently, package group "Desktop" installs all critical components of GNOME, including gdm (the GNOME Display Manager), plus a few additional packages; enough to provide a minimalist GNOME desktop with mouse support, a graphical file manager, copy/paste functionality and the luxurious GNOME Terminal emulator - maybe just what you need. Thus, installing the "General Purpose Desktop" package group is optional, but will help you mimic the system you would probably get if you where to include the default graphical desktop during OS install. Alternatively, you can chose a single package group "KDE Desktop", for a general purpose KDE Software Compilation.

It is generally recommended to install the "Fonts" package group to improve usability of the GUI, no matter what desktop environment you choose to install.

You may view the complete list of available package groups by issuing:

Code:
yum grouplist
You may review the contents of each package group by entering:

Code:
yum groupinfo "Name of the Package Group"
To boot directly into GUI, you will need to manually change the runlevel of the system from 3 (full multiuser environment with networking) to 5 (the same as mode 3 + X11), by changing the line "id:3:initdefault:" to "id:5:initdefault:" in /etc/inittab file. Or you can manually start X.org from console, by entering "startx" (without quotes).

Upon installation and subsequent reboot, you will be presented with the "Setup Agent" interface (even if you choose to stay in runlevel 3, you will see the text user interface of this tool - hence, the options provided will be different from the graphical variant). This is due to package "firstboot" being automatically installed by the "X Window System" package group and can be a handy way to setup a freshly installed system. All steps in "Setup Agent" are optional, so you can just skim through them, skipping any. Though, creating a new normal user on a freshly installed system is done best through this graphical tool, as it helps automatically create the new user and associate it with groups (such as the "video" group) appropriate for everyday use in a GUI environment . So, for the purpose of this tutorial, I would advice not skipping the user creation step.
[root@yfw ~]# cd /tmp Xvfb-1.20.11-2.el8.x86_64.rpmvault.centos.org/8.5.2111/AppStream/x86_64/os/Packages/xorg-x11-server-X --2025-10-30 08:25:51-- https://vault.centos.org/8.5.2111/AppStream/x86_64/os/Packages/xorg-x11-server-Xvfb-1.20.11-2.el8.x86_64.rpm Resolving vault.centos.org (vault.centos.org)... 54.230.175.20, 54.230.175.55, 54.230.175.75, ... Connecting to vault.centos.org (vault.centos.org)|54.230.175.20|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 891844 (871K) [application/x-rpm] Saving to: 'xorg-x11-server-Xvfb-1.20.11-2.el8.x86_64.rpm' xorg-x11-server-Xvfb-1.2 100%[==================================>] 870.94K 3.50MB/s in 0.2s 2025-10-30 08:25:51 (3.50 MB/s) - 'xorg-x11-server-Xvfb-1.20.11-2.el8.x86_64.rpm' saved [891844/891844] [root@yfw tmp]# ls -l xorg-x11-server-Xvfb-1.20.11-2.el8.x86_64.rpm -rw-r--r-- 1 root root 891844 Jun 11 2021 xorg-x11-server-Xvfb-1.20.11-2.el8.x86_64.rpm [root@yfw tmp]# # 应该看到文件存在且大小约 871KB [root@yfw tmp]# rpm -ivh --force --nodeps xorg-x11-server-Xvfb-1.20.11-2.el8.x86_64.rpm Verifying... ################################# [100%] Preparing... ################################# [100%] Updating / installing... 1:xorg-x11-server-Xvfb-1.20.11-2.el################################# [100%] error: unpacking of archive failed on file /usr/bin/Xvfb;6902b0ba: cpio: open failed - Resource temporarily unavailable error: xorg-x11-server-Xvfb-1.20.11-2.el8.x86_64: install failed [root@yfw tmp]#
最新发布
10-31
我们已经排除了磁盘空间不足和文件系统只读的问题,但现在连 **手动 `rpm` 安装也失败**,报错: ``` error: unpacking of archive failed on file /usr/bin/Xvfb; cpio: open failed - Resource temporarily unavailable ``` 这个错误非常关键: > ❌ `cpio: open failed - Resource temporarily unavailable` > 🟡 不是权限问题、不是磁盘满、也不是网络问题 > 🔴 极有可能是:**系统级资源限制(ulimit)、inode 耗尽、或内核/虚拟机层面对写操作的封锁** --- ## ✅ 诊断步骤 1:检查 inode 使用情况 即使磁盘还有空间,也可能 **inodes 被耗尽**,导致无法创建新文件。 ```bash df -i ``` 输出示例: ``` Filesystem Inodes IUsed IFree IUse% Mounted on /dev/vda1 39321600 8543210 30778390 22% / ``` ✅ 正常:`IFree` > 0,`IUse%` < 90% 🔴 危险:如果 `IUse%` 接近 100%,说明小文件太多(如日志碎片、session 文件等) 👉 如果 `IUse%` 很高,请运行: ```bash # 查找哪些目录占用了大量 inode for dir in /*; do echo "$dir:"; find "$dir" | wc -l; done 2>/dev/null | sort -nrk2 | head -10 ``` --- ## ✅ 诊断步骤 2:检查当前用户的资源限制(ulimit) ```bash ulimit -a ``` 重点关注: | 参数 | 建议值 | |------|--------| | `open files (-n)` | ≥ 1024 | | `processes (-u)` | ≥ 512 | | `file size (-f)` | unlimited | ⚠️ 如果 `open files` 太小(比如 256),可能导致 `cpio` 解包失败。 修复方法(临时): ```bash ulimit -n 65536 ulimit -u 4096 ``` 然后再试安装: ```bash rpm -ivh --force --nodeps xorg-x11-server-Xvfb-1.20.11-2.el8.x86_64.rpm ``` --- ## ✅ 诊断步骤 3:尝试直接复制二进制文件(绕过 RPM) 既然 `/usr/bin/Xvfb` 写不进去,我们可以: 1. 先解压 RPM 包 2. 提取 `Xvfb` 可执行文件 3. 放到用户目录下运行(如 `/home/openfire/bin/Xvfb`) ### 🔧 步骤 A:安装 `rpm2cpio` 工具来提取 RPM 内容 ```bash yum install cpio -y ``` > ✅ 这个应该能成功,因为 `cpio` 是轻量工具 然后提取 RPM 中的内容: ```bash cd /tmp mkdir xvfb-extract cd xvfb-extract # 将 RPM 转为 cpio 流,并解压 rpm2cpio ../xorg-x11-server-Xvfb-1.20.11-2.el8.x86_64.rpm | cpio -idmv ``` ✅ 成功后你会看到: ``` ./usr/bin/Xvfb ./usr/libexec/xorg-wrap ... ``` --- ### 🔧 步骤 B:将 `Xvfb` 复制到可写路径 ```bash # 创建 openfire 用户的 bin 目录 su - openfire -c 'mkdir -p ~/bin' # 从 root 复制文件过去 cp ./usr/bin/Xvfb /home/openfire/bin/ chown openfire:openfire /home/openfire/bin/Xvfb chmod +x /home/openfire/bin/Xvfb ``` --- ### 🔧 步骤 C:以 openfire 用户测试运行 Xvfb ```bash su - openfire -s /bin/bash export PATH=$HOME/bin:$PATH which Xvfb # 应该输出 /home/openfire/bin/Xvfb Xvfb :99 -screen 0 1024x768x24 -nolisten tcp & export DISPLAY=:99 echo $DISPLAY ``` ✅ 如果没有报错,说明虚拟显示已启动! --- ### 🔧 步骤 D:启动 Spark ```bash cd /opt/openfire/enterprise/spark/Spark ./Spark ``` 🎯 此时你应该看到: - Java 启动正常 - AWT 不再报错 `Can't connect to X11` - Spark 在后台运行(GUI 渲染在内存中) --- ## ✅ 最终解决方案总结 | 问题 | 解决方式 | |------|----------| | `yum/rpm` 无法安装 Xvfb | 因系统限制无法写入 `/usr/bin` | | ✔️ 绕过方案 | 手动提取 RPM 中的 `Xvfb` 二进制文件 | | ✔️ 部署位置 | 放入 `/home/openfire/bin/Xvfb` | | ✔️ 权限处理 | 所有者设为 `openfire`,加执行权限 | | ✔️ 启动方式 | `Xvfb :99 &` + `export DISPLAY=:99` | --- ## 💡 补充建议:长期解决办法 1. **联系系统管理员或云平台支持**:确认是否有安全策略(如 AppArmor、SELinux、容器限制)阻止写入 `/usr/bin` 2. **使用容器化部署 Spark**(推荐): ```dockerfile FROM centos:8 RUN yum install -y xorg-x11-server-Xvfb java-11-openjdk openfire-spark-client CMD ["sh", "-c", "Xvfb :99 & export DISPLAY=:99 && /opt/spark/Spark"] ``` 这样完全避开主机权限问题。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值