连接到 VNC 服务器失败:连接被拒绝;VNC 服务器已关闭连接且 X 服务器已在显示器上运行:1

连接到 VNC 服务器失败:连接被拒绝;VNC 服务器已关闭连接且 X 服务器已在显示器上运行:1

我按照本教程在远程机器上设置了 VNC 服务器以及 xfce4:https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-vnc-on-ubuntu-20-04

简而言之,在服务器上:

$ apt update && apt install xfce4 xfce4-goodies tightvncserver

之后我启动了一个 VNC 实例,如下所示(我已经在提示时设置了密码):

$ tightvncserver -localhost -geometry 1600x1280


New 'X' desktop is server.domain.org:1

Starting applications specified in /home/userroot/.vnc/xstartup
Log file is /home/userroot/.vnc/server.domain.org:1.log

这是xstartup文件内容~/.vnc

#!/bin/sh
set -xv

xrdb $HOME/.Xresources
#xsetroot -solid grey
#x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &
# Fix to make GNOME work
#export XKL_XMODMAP_DISABLE=1
#/etc/X11/Xsession
/usr/bin/startxfce4 &

xstartup我还尝试在此文件中添加以下两行:

unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS

如此处所述:https://ubuntuforums.org/showthread.php?t=2442905&s=1a71305ce4f7a8e7360357cf0dbc074c&p=13955725#post13955725
但这并没有改变什么。

以下是日志文件的内容:server.domain.org:1.logVNC 实例启动后:

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

xrdb $HOME/.Xresources
+ xrdb /home/userroot/.Xresources
xrdb: No such file or directory
xrdb: can't open file '/home/userroot/.Xresources'
#xsetroot -solid grey
#x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &
# Fix to make GNOME work
#export XKL_XMODMAP_DISABLE=1
#/etc/X11/Xsession
/usr/bin/startxfce4 &

+ /usr/bin/startxfce4
/usr/bin/startxfce4: X server already running on display :1
Xlib:  extension "RANDR" missing on display ":1".
gpg-agent[23223]: WARNING: "--write-env-file" is an obsolete option - it has no effect
gpg-agent: a gpg-agent is already running - not starting a new one

(xfce4-session:23216): xfce4-session-WARNING **: 13:33:14.479: gpg-agent returned no PID in the variables
(xfce4-session:23216): xfce4-session-WARNING **: 13:33:14.480: xfsm_manager_load_session: Something wrong with /home/userroot/.cache/sessions/xfce4-session-server.domain.org:1, Does it exist? Permissions issue?
Xlib:  extension "RANDR" missing on display ":1.0".
(xfwm4:23226): xfwm4-WARNING **: 13:33:14.499: The display does not support the XRender extension.
(xfwm4:23226): xfwm4-WARNING **: 13:33:14.499: The display does not support the XRandr extension.
(xfwm4:23226): xfwm4-WARNING **: 13:33:14.499: The display does not support the XComposite extension.
(xfwm4:23226): xfwm4-WARNING **: 13:33:14.499: The display does not support the XDamage extension.
(xfwm4:23226): xfwm4-WARNING **: 13:33:14.499: The display does not support the XFixes extension.
(xfwm4:23226): xfwm4-WARNING **: 13:33:14.499: Compositing manager disabled.

Xlib:  extension "RANDR" missing on display ":1.0".
Xlib:  extension "RANDR" missing on display ":1.0".
Xlib:  extension "RANDR" missing on display ":1.0".
Xlib:  extension "RANDR" missing on display ":1.0".
xfwm4-Message: 13:33:14.537: Unsupported keyboard modifier '<Super>Tab'

(xfwm4:23226): xfwm4-WARNING **: 13:33:14.538: Cannot find visual format on screen 0
Xlib:  extension "RANDR" missing on display ":1.0".
(xfsettingsd:23231): xfsettingsd-CRITICAL **: 13:33:14.555: No RANDR extension found in display :1.0. Display settings won't be applied.
Xlib:  extension "XInputExtension" missing on display ":1.0".
(xfsettingsd:23231): xfsettingsd-CRITICAL **: 13:33:14.555: XI is not present.
(xfsettingsd:23231): xfsettingsd-CRITICAL **: 13:33:14.555: Failed to initialize the Xkb extension.
(xfsettingsd:23231): xfsettingsd-CRITICAL **: 13:33:14.556: Failed to initialize the Accessibility extension.
(Thunar:23233): Gtk-WARNING **: 13:33:14.557: Unable to locate theme engine in module_path: "pixmap",
  (plenty of time the previous line)
(xfwm4:23226): Gtk-WARNING **: 13:33:14.560: Unable to locate theme engine in module_path: "pixmap",
(xfdesktop:23235): Gtk-WARNING **: 13:33:14.561: Unable to locate theme engine in module_path: "pixmap",
(xfwm4:23226): Gtk-WARNING **: 13:33:14.561: Unable to locate theme engine in module_path: "pixmap",
(xfwm4:23226): Gtk-WARNING **: 13:33:14.561: Unable to locate theme engine in module_path: "pixmap",
(xfdesktop:23235): Gtk-WARNING **: 13:33:14.561: Unable to locate theme engine in module_path: "pixmap",
(xfdesktop:23235): Gtk-WARNING **: 13:33:14.561: Unable to locate theme engine in module_path: "pixmap",
(xfwm4:23226): Gtk-WARNING **: 13:33:14.562: Unable to locate theme engine in module_path: "pixmap",
(xfwm4:23226): Gtk-WARNING **: 13:33:14.562: Unable to locate theme engine in module_path: "pixmap",
(xfdesktop:23235): Gtk-WARNING **: 13:33:14.562: Unable to locate theme engine in module_path: "pixmap",
(xfdesktop:23235): Gtk-WARNING **: 13:33:14.562: Unable to locate theme engine in module_path: "pixmap",
(xfce4-session:23216): Gtk-WARNING **: 13:33:14.564: Unable to locate theme engine in module_path: "pixmap",
  (plenty of time the previous line)
vmware-user: could not open /proc/fs/vmblock/dev
(xfsettingsd:23231): Gtk-WARNING **: 13:33:14.571: Unable to locate theme engine in module_path: "pixmap",
  (plenty of time the previous line)

Xlib:  extension "RANDR" missing on display ":1.0".
(migrate:23252): Gtk-WARNING **: 13:33:14.625: Unable to locate theme engine in module_path: "pixmap",
  (plenty of time the previous line)
xfwm4-Message: 13:33:14.628: Unsupported keyboard modifier '<Super>Tab'

** (xfdesktop:23235): WARNING **: 13:33:14.796: Failed to set the background '/usr/share/backgrounds/xfce/xfce-teal.jpg': GDBus.Error:org.freedesktop.DBus.Error.InvalidArgs: No such interface 'org.freedesktop.DisplayManager.AccountsService'
Xlib:  extension "RANDR" missing on display ":1.0".
Xlib:  extension "VMWARE_CTRL" missing on display ":1.0".
Xlib:  extension "RANDR" missing on display ":1.0".

(请注意,我用占位符删除了重复的行)

在客户端(服务器的防火墙(ufw)上端口 22 自然是打开的)我打开一个 SSH 隧道:

$ ssh -f -N -L 5901:localhost:5901 -l userroot server.domain.org

然后我尝试连接,但遇到此错误(此次尝试后服务器日志中不再有新行):

$ xtightvncviewer localhost:5901

channel 2: open failed: connect failed: Connection refused
xtightvncviewer: VNC server closed connection

服务器和客户端均基于Ubuntu 18.04.5 LTS (GNU/Linux 5.4.0-77-generic x86_64)

如何修复?我在设置服务器时是否遗漏了什么?

相关内容