我需要使用SSH在虚拟机上远程运行Google Chrome。我不想要xforwarding——我想利用vm上可用的GPU。当我尝试运行google-chrome
时,我得到以下错误:
[19615:19615:0219/152933.751028:ERROR:browser_main_loop.cc(1512)] Unable to open X display.
我尝试将DISPLAY env值设置为各种值:
export DISPLAY=localhost:0.0
export DISPLAY=127.0.0.1:0.0
export DISPLAY=:0.0
我还尝试用不同的值替换上面例子中的0.0。
我在/etc/ssh/sshd_config中有ForwardX11 no
我试着设置这样的目标:
systemctl isolate multi-user.target
当我尝试运行sudo lshw -C display
时,我得到以下输出:
*-display
description: VGA compatible controller
product: Hyper-V virtual VGA
vendor: Microsoft Corporation
physical id: 8
bus info: pci@0000:00:08.0
version: 00
width: 32 bits
clock: 33MHz
capabilities: vga_controller bus_master rom
configuration: driver=hyperv_fb latency=0
resources: irq:11 memory:f8000000-fbffffff
*-display UNCLAIMED
description: VGA compatible controller
product: GM204GL [Tesla M60]
vendor: NVIDIA Corporation
physical id: 1
version: a1
width: 64 bits
clock: 33MHz
capabilities: pm msi pciexpress vga_controller bus_master cap_list
configuration: latency=0
resources: iomemory:f0-ef iomemory:f0-ef memory:41000000-41ffffff memory:fe0000000-fefffffff memory:ff0000000-ff1ffffff
我尝试通过以下方式更新我的gpu驱动程序:
wget https://www.nvidia.com/content/DriverDownload-March2009/confirmation.php?url=/tesla/375.66/nvidia-diag-driver-local-repo-rhel7-375.66-1.x86_64.rpm
yum -y install nvidia-diag-driver-local-repo-rhel7-375.66-1.x86_64.rpm
但在那之后,我仍然可以在我的NVIDIA gpu旁边看到UNCLIMED
。阿比的想法?
您可以尝试使用Xvfb。它不需要额外的硬件。
如果您还没有安装Xvfb,请安装它,并执行以下步骤
sudo apt-get install -y xvfb
生成依赖项"无头";铬/硒工作:
sudo apt-get -y install xorg xvfb gtk2-engines-pixbuf
sudo apt-get -y install dbus-x11 xfonts-base xfonts-100dpi xfonts-75dpi xfonts-cyrillic xfonts-scalable
可选但漂亮:用于捕获Xvfb显示的屏幕截图:
sudo apt-get -y install imagemagick x11-apps
确保Xvfb在每次启动box/vm时启动:
Xvfb -ac :99 -screen 0 1280x1024x16 &
export DISPLAY=:99
运行Google Chrome
google-chrome
好的,伙计们。我在发疯两个小时后发现了自己的问题。我的盒子配置正确。您不能做的是ssh从一个盒子到另一个盒子,再到这个盒子,并期望X11转发能很好地发挥作用。在不破坏整个网络的情况下,我发现如果我从MAIN框切换到这个框(没有两个或三个ssh’ing(,chrome就会作为使用CLI的普通用户出现。因此,正是来自多个盒子的多个外壳让显示器显示它被设置为"什么都没有"!手动设置显示器只会使问题复杂化。有一次我从主外盒直接向这个盒子开火,我的显示器被设置为10:0,这是我配置中的第一个例子。不要犯这个错误,你会浪费宝贵的时间。
FWIW,我在使用SSH登录Docker compose堆栈中的Selenium chrome节点时遇到了这种情况。如果我用sudo -u seluser google-chrome
调用它作为root
,Chrome就会启动,但如果我以seluser
登录,则不会启动。结果发现,root
将DISPLAY
设置为:99:0
,而seluser
根本没有设置。如果我显式地设置它(从seluser
shell或从docker compose exec
命令行(,它就会工作。
$ docker-compose exec -u seluser
selenium-chrome # or whatever your service is called
/bin/bash
seluser@c02cda62b751:/$ export DISPLAY=:99:0
seluser@c02cda62b751:/$ google-chrome http://app.test:3000/home
或
$ docker-compose exec -u seluser -e DISPLAY=:99:0
selenium-chrome
google-chrome http://app.test:3000/home
但是,:99.0
是未记录的,所以如果这不起作用,您可以尝试使用检查root
的DISPLAY
值
docker-compose exec -u root selenium-chrome bash -c 'echo "${DISPLAY}"'
我在使用WSL和Ubuntu时遇到了同样的问题。我已取消安装/重置ubuntu。之后,我执行了以下命令
wsl --set-default-version 2
然后我又安装了Ubuntu,我没有遇到--no-sandbox
问题或任何问题。
希望这对某人有用。