我正在为客户做一个项目,客户希望使用 noVNC 通过我的网站访问一些 Windows 应用程序,这让我想到了一个设置多用户服务器的想法。我已经在我的 CentOS 7 VPS 上安装了 TigerVNC 服务器,当一个用户连接时,它可以正常工作,但是当第二个用户连接时,他/她只会看到黑屏,因为第二个用户似乎无法启动 gnome。
例如,如果我运行它,vncservice@:1
一切正常,用户将毫无问题地登录,但vncservice@:2
启动时,它不会启动 gnome,并且用户将看到一个只有光标的黑屏。vncservice@:2
首次启动时,该用户将启动到 gnome,但vncservice@:1
看不到他们的桌面等。等等。
我的设置如下:
[User 1 and 2 ~/.vnc/xstartup]
#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
/etc/X11/xinit/xinitrc
# Assume either Gnome or KDE will be started by default when installed
# We want to kill the session automatically in this case when user logs out. In case you modify
# /etc/X11/xinit/Xclients or ~/.Xclients yourself to achieve a different result, then you should
# be responsible to modify below code to avoid that your session will be automatically killed
sleep 60
if [ -e /usr/bin/gnome-session -o -e /usr/bin/startkde ]; then
vncserver -kill $DISPLAY
killall -u $USER
fi
[/etc/X11/xinit/xinitrc]
#!/bin/sh
# Mandatorily source xinitrc-common, which is common code shared between the
# Xsession and xinitrc scripts which has been factored out to avoid duplication
. /etc/X11/xinit/xinitrc-common
# The user may have their own clients they want to run. If they don't,
# fall back to system defaults.
if [ -f $HOME/.Xclients ]; then
exec $CK_XINIT_SESSION $SSH_AGENT $HOME/.Xclients || \
exec $CK_XINIT_SESSION $SSH_AGENT $HOME/.Xclients
elif [ -f /etc/X11/xinit/Xclients ]; then
exec $CK_XINIT_SESSION $SSH_AGENT /etc/X11/xinit/Xclients || \
exec $CK_XINIT_SESSION $SSH_AGENT /etc/X11/xinit/Xclients
else
# Failsafe settings. Although we should never get here
# (we provide fallbacks in Xclients as well) it can't hurt.
[ -x /usr/bin/xsetroot ] && /usr/bin/xsetroot -solid '#222E45'
[ -x /usr/bin/xclock ] && /usr/bin/xclock -geometry 100x100-5+5 &
[ -x /usr/bin/xterm ] && xterm -geometry 80x50-50+150 &
[ -x /usr/bin/twm ] && /usr/bin/twm
fi
[vncserver@:1 和 vncserver@:2,替换为实际用户名]
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=forking
User=<USERNAME>
Group=<USERNAME>
ExecStartPre=-/usr/bin/vncserver -kill %i
ExecStart=/usr/bin/vncserver %i
PIDFile=/home/<USERNAME>/.vnc/%H%i.pid
ExecStop=-/usr/bin/vncserver -kill %i
[Install]
WantedBy=multi-user.target
[第二个用户 VNC 日志]
[root@.... ~]# systemctl status vncserver@:5
● vncserver@:5.service - Remote desktop service (VNC)
Loaded: loaded (/etc/systemd/system/vncserver@:5.service; disabled; vendor preset: disabled)
Active: active (running) since za 2021-07-24 19:04:54 CEST; 59s ago
Process: 25990 ExecStart=/usr/bin/vncserver %i (code=exited, status=0/SUCCESS)
Process: 25981 ExecStartPre=/usr/bin/vncserver -kill %i (code=exited, status=2)
Main PID: 25997 (Xvnc)
CGroup: /system.slice/system-vncserver.slice/vncserver@:5.service
├─25997 /usr/bin/Xvnc :5 -auth /home/AHtYezzDXegQScyu/.Xauthority -desktop <HOSTNAME>:5 (AHtYezzDXegQScyu) -fp catalogue:/etc/X11/fontpath.d -geometry 1024x768 -pn -rfbauth /home/AHtYezzDXegQScyu/.vnc/passwd -rfbport 5905 -rfbwait 30000
├─26006 /bin/sh /home/AHtYezzDXegQScyu/.vnc/xstartup
├─26018 dbus-launch --sh-syntax --exit-with-session
├─26019 /usr/bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session
├─26053 /usr/libexec/imsettings-daemon
├─26057 /usr/libexec/gvfsd
├─26062 /usr/libexec/gvfsd-fuse /home/AHtYezzDXegQScyu/.gvfs -f -o big_writes
├─26126 /usr/libexec/at-spi-bus-launcher
├─26131 /usr/bin/dbus-daemon --config-file=/usr/share/defaults/at-spi2/accessibility.conf --nofork --print-address 3
├─26135 /usr/libexec/at-spi2-registryd --use-gnome-session
├─26158 /usr/bin/gnome-keyring-daemon --start --components=ssh
├─26241 /usr/libexec/xdg-permission-store
├─26246 /usr/libexec/gnome-shell-calendar-server
├─26251 /usr/libexec/evolution-source-registry
├─26258 /usr/libexec/goa-daemon
├─26269 /usr/libexec/goa-identity-service
├─26275 /usr/libexec/mission-control-5
├─26286 /usr/libexec/gvfs-udisks2-volume-monitor
├─26293 /usr/libexec/gvfs-mtp-volume-monitor
├─26299 /usr/libexec/gvfs-goa-volume-monitor
├─26305 /usr/libexec/gvfs-gphoto2-volume-monitor
├─26310 /usr/bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session
├─26311 /usr/libexec/gvfs-afc-volume-monitor
├─26411 /usr/libexec/gsd-print-notifications
├─26413 /usr/libexec/gsd-rfkill
├─26418 /usr/libexec/gsd-screensaver-proxy
├─26454 sleep 60
└─26458 /usr/libexec/evolution-calendar-factory
jul 24 19:05:22 <HOSTNAME> gnome-session-binary[26007]: WARNING: Failed to start app: Unable to start application: Failed to fork (Resource temporarily unavailable)
jul 24 19:05:22 <HOSTNAME> gsd-print-notif[26411]: Could not execute system-config-printer-udev handler: Failed to fork (Resource temporarily unavailable)
jul 24 19:05:22 <HOSTNAME> gnome-session-binary[26007]: WARNING: Application 'org.gnome.SettingsDaemon.Power.desktop' killed by signal 5
jul 24 19:05:22 <HOSTNAME> gnome-session[26007]: gnome-session-binary[26007]: WARNING: Application 'org.gnome.SettingsDaemon.Power.desktop' killed by signal 5
jul 24 19:05:22 <HOSTNAME> gnome-session-binary[26007]: GLib-WARNING: GError set over the top of a previous GError or uninitialized memory.
This indicates a bug in someone's code. You must ensure an error is NULL before it's set.
The overwriting error message was: Unable to start application: Failed to fork (Resource temporarily unavailable)...
jul 24 19:05:22 <HOSTNAME> gnome-session[26007]: gnome-session-binary[26007]: GLib-WARNING: GError set over the top of a previous GError or uninitialized memory.
jul 24 19:05:22 <HOSTNAME> gnome-session[26007]: This indicates a bug in someone's code. You must ensure an error is NULL before it's set.
jul 24 19:05:22 <HOSTNAME> gnome-session[26007]: The overwriting error message was: Unable to start application: Failed to fork (Resource temporarily unavailable)
jul 24 19:05:22 <HOSTNAME> evolution-calen[26465]: creating thread 'gdbus': Error creating thread: Resource temporarily unavailable
jul 24 19:05:47 <HOSTNAME> gnome-shell-cal[26246]: Could not load source 'birthdays': Timeout was reached
[/etc/X11/xinit/Xclients]
#!/bin/bash
GSESSION="$(type -p gnome-session)"
STARTKDE="$(type -p startkde)"
# check to see if the user has a preferred desktop
PREFERRED=
if [ -f /etc/sysconfig/desktop ]; then
. /etc/sysconfig/desktop
if [ "$DESKTOP" = "GNOME" ]; then
PREFERRED="$GSESSION"
elif [ "$DESKTOP" = "KDE" ]; then
PREFERRED="$STARTKDE"
fi
fi
if [ -n "$PREFERRED" ]; then
exec "$PREFERRED"
fi
# now if we can reach here, either no desktop file was present,
# or the desktop requested is not installed.
if [ -n "$GSESSION" -a -f /usr/share/xsessions/gnome.desktop ]; then
# by default, we run GNOME.
exec "$GSESSION" --session=gnome
elif [ -n "$STARTKDE" ]; then
# if GNOME isn't installed, try KDE.
exec "$STARTKDE"
fi
# We should also support /etc/X11/xinit/Xclients.d scripts
XCLIENTS_D=/etc/X11/xinit/Xclients.d
if [ "$#" -eq 1 ] && [ -x "$XCLIENTS_D/Xclients.$1.sh" ]; then
exec -l $SHELL -c "$SSH_AGENT $XCLIENTS_D/Xclients.$1.sh"
fi
# Failsafe.
# these files are left sitting around by TheNextLevel.
rm -f $HOME/Xrootenv.0
# Argh! Nothing good is installed. Fall back to twm
{
# gosh, neither fvwm95 nor fvwm2 is available;
# fall back to failsafe settings
[ -x /usr/bin/xsetroot ] && /usr/bin/xsetroot -solid '#222E45'
if [ -x /usr/bin/xclock ] ; then
/usr/bin/xclock -geometry 100x100-5+5 &
fi
if [ -x /usr/bin/xterm ] ; then
/usr/bin/xterm -geometry 80x50-50+150 &
fi
if [ -x /usr/bin/firefox -a -f /usr/share/doc/HTML/index.html ]; then
/usr/bin/firefox /usr/share/doc/HTML/index.html &
fi
if [ -x /usr/bin/twm ] ; then
exec /usr/bin/twm
fi
}
愚蠢的是,在尝试启动第二个vncserver
大约 50 次后,它通常只工作一次,当我停止并再次启动该服务时,它不会再显示任何内容,除了鼠标光标。
剩余的可用内存充足(大约 5 GB),剩余的存储空间也充足(大约 100 GB)。当我编辑文件~/.vnc/xstartup
以仅包含文件管理器时,它每次都运行正常,尝试为多个用户运行会话似乎是问题所在。
感谢您阅读完这一切,我已经浪费了无数的时间尝试调试这个问题而没有任何(重大的)改进。
更新 1:
经过几个小时的修修补补,我还是没能让 gnome 正常工作。危急时刻需要采取紧急措施,所以我最终安装了 Xfce,并使用漂亮的主题和图标包使其更漂亮。安装后它就正常工作了。我从文件中删除了所有 gnome 引用xstartup
并添加了startxfce4
。