服务器Ubuntu22.04 server 安装gnome GUI+VNC远程配置

发布于:2025-03-12 ⋅ 阅读:(9) ⋅ 点赞:(0)

服务器端配置


一、安装桌面环境:

1.更新软件源。
sudo apt update
2.安装桌面环境所需的软件包,包括系统面板、窗口管理器、文件浏览器、终端等桌面应用程序。
sudo apt install gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal ubuntu-desktop

二、配置VNC服务器:

3.安装 TightVNC 服务器
sudo apt install tightvncserver
4.通过 vncserver 命令启动 VNC 服务器实例,第一次运行时同时会完成初始化(设置 VNC 访问密码,创建初始配置文件)
vncserver
5.系统将提示输入并验证密码以远程访问您的机器
6.验证密码后,可以选择创建仅供查看的密码。使用仅查看密码登录的用户将无法使用鼠标或键盘控制 VNC 实例,没有演示需要的输入 n 即可,后续如有需要可以再设置。

三、配置 xstartup 配置文件

7.备份VNC的xstartup配置文件
cp ~/.vnc/xstartup ~/.vnc/xstartup.bak
8.修改VNC的xstartup配置文件
nano ~/.vnc/xstartup

复制以下内容到文件:

#!/bin/sh
export XKL_XMODMAP_DISABLE=1
export XDG_CURRENT_DESKTOP="GNOME-Flashback:GNOME"
export XDG_MENU_PREFIX="gnome-flashback-"
gnome-session --session=gnome-flashback-metacity --disable-acceleration-check
9.关闭VNC
vncserver -kill :1
10.重新启动 VNC
vncserver -geometry 1920x1080 :1 -localhost no

或不指定分辨率重启

vncserver :1

客户端配置


11.在其他电脑使用RealVNC Viewer连接

可参考:Windows下通过VNC Viewer访问Linux服务器_vncviewer 服务端-CSDN博客

其他问题


一、灰屏或黑屏问题

查看日志文件寻找问题[2]:

cat /home/xmu18-tc/.vnc/xmu18:1.log

出现内容如下:

08/03/25 08:06:04 Xvnc version TightVNC-1.3.10
08/03/25 08:06:04 Copyright (C) 2000-2009 TightVNC Group
08/03/25 08:06:04 Copyright (C) 1999 AT&T Laboratories Cambridge
08/03/25 08:06:04 All Rights Reserved.
08/03/25 08:06:04 See http://www.tightvnc.com/ for information on TightVNC
08/03/25 08:06:04 Desktop name 'X' (xmu18:1)
08/03/25 08:06:04 Protocol versions supported: 3.3, 3.7, 3.8, 3.7t, 3.8t
08/03/25 08:06:04 Listening for VNC connections on TCP port 5901
Font directory '/usr/share/fonts/X11/Type1/' not found - ignoring
Font directory '/usr/share/fonts/X11/75dpi/' not found - ignoring
Font directory '/usr/share/fonts/X11/100dpi/' not found - ignoring
Terminated

提示没有字体,安装即可[3,4]:

sudo apt-get update
sudo apt-get install -y xvfb    # 有时候会出现无法定位此包
sudo apt-get install xfonts-100dpi xfonts-75dpi xfonts-cyrillic xorg dbus-x11 xfonts-Type1

然后重新杀死VNC和开启VNC。

(/X11/Type1/' not found问题仍暂未找到解决方法...)

二、可能需要修改wayland问题

服务器上打开文件,取消wayland=false的注释[5]:

sudo nano /etc/gdm3/custom.conf

重启生效

sudo systemctl restart gdm3

(本人测试过,不修改此项因该也没什么问题;但是取消注释比不取消注释用起来流畅一些,可能是不同协议需要转换导致一些延迟..)


//参考连接:
[1] https://linuxstory.org/how-to-install-and-configure-vnc-on-ubuntu-22-04/
[2] https://cloud.tencent.com/developer/article/2387064
[3] https://blog.csdn.net/lygzscnt12/article/details/108375183
[4] https://github.com/GabrielBB/xvfb-action/issues/29
[5] https://blog.csdn.net/yanchenyu365/article/details/133038162