java.lang.InternalError: 无法连接到 X11 窗口服务器以进行 JVisualVM 分析会话
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24153416/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.lang.InternalError: Can't connect to X11 window server for JVisualVM profiling session
提问by IAmYourFaja
I have an Ubuntu server VM (myapp01
) and have a Java application deployed there. The app has been acting wonky and I would like to profile it with JVisualVM. To do this I need to install X-Windows on my Windows 7 host, and then get the Ubuntu VM to export its X11 connection to my host when I tell it to run JVisualVM on the VM.
我有一个 Ubuntu 服务器 VM ( myapp01
) 并在那里部署了一个 Java 应用程序。该应用程序一直表现不佳,我想用 JVisualVM 对其进行分析。为此,我需要在我的 Windows 7 主机上安装 X-Windows,然后当我告诉它在 VM 上运行 JVisualVM 时,让 Ubuntu VM 将其 X11 连接导出到我的主机。
So I started by downloading XMing here:
所以我从这里下载 XMing 开始:
http://sourceforge.net/projects/xming/files/Xming/6.9.0.31/Xming-6-9-0-31-setup.exe/download
I used all default/recommended installation options, including using a normal PuTTy session and allowing public & private network access. After installing XMing, I launched it and verified it was running on my Windows host. I then opened up Cygwin and SSHed into the Ubuntu server:
我使用了所有默认/推荐的安装选项,包括使用普通 PuTTy 会话并允许公共和专用网络访问。安装 XMing 后,我启动它并验证它在我的 Windows 主机上运行。然后我打开 Cygwin 并通过 SSH 连接到 Ubuntu 服务器:
$ ssh myuser@myapp01
myuser@myapp01's password:
Welcome to Ubuntu 12.04.4 LTS (GNU/Linux 3.5.0-23-generic x86_64)
* Documentation: https://help.ubuntu.com/
System information as of Tue Jun 10 21:26:15 EDT 2014
System load: 0.0 Processes: 82
Usage of /: 22.5% of 11.81GB Users logged in: 0
Memory usage: 30% IP address for eth0: 10.10.41.108
Swap usage: 0%
Graph this data and manage this system at:
https://landscape.canonical.com/
38 packages can be updated.
30 updates are security updates.
Last login: Tue Jun 10 15:03:35 2014 from 10.10.101.96
I then export the display to what appearsto be my host's IP:
然后我将显示导出到似乎是我主机的 IP:
myuser@myapp01:~$ export DISPLAY=10.10.101.96
I then attempt to run JVisualVM:
然后我尝试运行 JVisualVM:
myuser@myapp01:~$ cd $JAVA_HOME
myuser@myapp01:/usr/lib/jvm/java-7-oracle-amd64$ ls
bin COPYRIGHT db include jre lib LICENSE man README.html release src.zip THIRDPARTYLICENSEREADME-JAVAFX.txt THIRDPARTYLICENSEREADME.txt
myuser@myapp01:/usr/lib/jvm/java-7-oracle-amd64$ cd bin/
myuser@myapp01:/usr/lib/jvm/java-7-oracle-amd64/bin$ ./jvisualvm
Error: Can't connect to X11 window server using '10.10.101.96' as the value of the DISPLAY variable.
See the /home/myuser/.visualvm/7u14/var/log/messages.log for details.
myuser@myapp01:/usr/lib/jvm/java-7-oracle-amd64/bin$ vim /home/myuser/.visualvm/7u14/var/log/messages.log
Inside /home/myuser/.visualvm/7u14/var/log/messages.log
:
内部/home/myuser/.visualvm/7u14/var/log/messages.log
:
java.lang.InternalError: Can't connect to X11 window server using '10.10.101.96' as the value of the DISPLAY variable.
at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
at sun.awt.X11GraphicsEnvironment.access0(X11GraphicsEnvironment.java:65)
at sun.awt.X11GraphicsEnvironment.run(X11GraphicsEnvironment.java:110)
at java.security.AccessController.doPrivileged(Native Method)
at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:74)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at java.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:102)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:81)
at org.netbeans.core.startup.Main.start(Main.java:200)
at org.netbeans.core.startup.TopThreadGroup.run(TopThreadGroup.java:84)
at java.lang.Thread.run(Thread.java:745)
Ideas? I am VPNed in, could that be affecting anything? Do I have XMing misconfigured somehow? Is my export DISPLAY
command wrong?
想法?我加入了 VPN,这会影响什么吗?我是否以某种方式错误配置了 XMing?我的export DISPLAY
命令错了吗?
采纳答案by andrewdotn
For security purposes, X servers won't generally accept direct TCP connections from other hosts. Otherwise people could connect keyloggers to your X server, and your keystrokes would pass over the network unencrypted, allowing people to record passwords just by being on the same LAN.
出于安全考虑,X 服务器通常不会接受来自其他主机的直接 TCP 连接。否则,人们可以将键盘记录器连接到您的 X 服务器,并且您的击键将在未加密的网络上传递,允许人们仅在同一个 LAN 上记录密码。
But SSH provides a secure way to forward X11 traffic over your SSH session, using the -X
or -Y
options.
但是 SSH 提供了一种使用-X
或-Y
选项通过 SSH 会话转发 X11 流量的安全方式。
On your windows computer, make sure $DISPLAY
is set correctly by trying to open an xterm
from the command line. $DISPLAY
will probably be set to :0
which stands for localhost:0
. There are also additional tokens used to authenticate connections to the X server that are stored in ~/.Xauthority
that you can view with xauth list
.
在您的 Windows 计算机上,$DISPLAY
通过尝试xterm
从命令行打开确保设置正确。$DISPLAY
可能会被设置为:0
代表localhost:0
。还有其他令牌用于验证与 X 服务器的连接,这些令牌存储在~/.Xauthority
您可以使用xauth list
.
Now, run ssh -Y 10.10.101.96
. If you get a message like X11 forwarding request failed on channel 0
, then run ssh -v -Y 10.10.101.96
instead to get debugging messages. If the remote machine is a server, the reason will probably be that xauth
isn't installed. On CentOS, it's in the xorg-x11-xauth
RPM.
现在,运行ssh -Y 10.10.101.96
。如果您收到类似 的消息X11 forwarding request failed on channel 0
,请ssh -v -Y 10.10.101.96
改为运行以获取调试消息。如果远程机器是服务器,原因可能xauth
是没有安装。在 CentOS 上,它位于xorg-x11-xauth
RPM 中。
On the remote machine, if everything went well, then $DISPLAY
on the remote machine will now be set to a proxy display set up by SSH:
在远程机器上,如果一切顺利,那么$DISPLAY
远程机器上现在将设置为由 SSH 设置的代理显示:
$ echo $DISPLAY
localhost:10.0
At which point you can run a command like xterm
on the remote machine, and have the window pop up on your local display.
此时,您可以像xterm
在远程机器上一样运行命令,并在本地显示器上弹出窗口。
Although there's no X server running on the remote machine, you may still need to install a bunch of X11 libraries for Java to be able to talk to your local X server…
尽管远程机器上没有运行 X 服务器,但您可能仍然需要为 Java 安装一堆 X11 库才能与本地 X 服务器通信……
回答by Serge Ballesta
If a JDK is installed on the Windows host, there is no need for using the JVisualVM from the Unix host through XWindow and ssh. It is a perfectly correct solution, but it can be tricky if you are not used to ssh and XWindow DISPLAY, not speaking of cygwin or XMing install ...
如果在 Windows 主机上安装了 JDK,则无需从 Unix 主机通过 XWindow 和 ssh 使用 JVisualVM。这是一个完全正确的解决方案,但如果您不习惯 ssh 和 XWindow DISPLAY,那么它可能会很棘手,更不用说 cygwin 或 XMing 安装...
The simplest solution in this use case is :
此用例中最简单的解决方案是:
- run jstatd on the Linux host (preferently under same credentials of the app to debug)
- run jvisualvm on the Windows host and ask it to connect to the Linux host
- 在 Linux 主机上运行 jstatd(最好在应用程序的相同凭据下进行调试)
- 在 Windows 主机上运行 jvisualvm 并要求它连接到 Linux 主机
(see docs about jvisualvm and jstatd for further references)
(请参阅有关 jvisualvm 和 jstatd 的文档以获取更多参考)
回答by user3132194
I have solved a similar problem. In my case there was an incorrect IP-address specified in /etc/hosts
file for a hostname of server running sshd.
我已经解决了一个类似的问题。就我而言,在/etc/hosts
文件中为运行 sshd 的服务器的主机名指定了不正确的 IP 地址。
Fortunately java application gave me this more verbose output, while other applications just fails with Failed to open display
message.
幸运的是,java 应用程序给了我这个更详细的输出,而其他应用程序只是失败并Failed to open display
显示消息。