调试JConsole连接失败
我有一个 Web 应用程序部署到远程树脂服务器,并且它打开了 JMX。
我可以远程登录到远程服务器,即
franz@see:/tmp$ telnet <remote-ip> 5555
Trying <remote-ip>...
Connected to <remote-ip>.
Escape character is '^]'.
��sr5javax.management.remote.message.HandshakeBeginMessage�,���6profilestLjava/lang/String;Lversionq~xppt1.0^]
telnet> q
Connection closed.
但我无法使用我的 JConsole 连接到它
$JAVA_HOME/bin/java -cp $JAVA_HOME/lib/jconsole.jar:$JAVA_HOME/lib/tools.jar:pm-common/lib/jmxremote_optional-1_0_1_3.jar sun.tools.jconsole.JConsole service:jmx:jmxmp://<remote-ip>:5555
我已经尝试使用以下 java 版本,但我在两个实例上都收到“连接失败”。
## where JAVA_HOME=/opt/java/64/jdk1.5.0_22
java version "1.5.0_22"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_22-b03)
Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_22-b03, mixed mode)
## where JAVA_HOME=/opt/java/64/jdk1.6.0_17
java version "1.6.0_17"
Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
Java HotSpot(TM) 64-Bit Server VM (build 14.3-b01, mixed mode)
你们知道如何调试这个(即找出问题所在)吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
通过 cygwin 启动 Java 进程时,我遇到了同样的问题。 JConsole 无法连接。通过 win7-cmd 启动它一切正常。
I encountered the same Problem when starting the Java-Process through cygwin. JConsole cannot connect. Started it through win7-cmd everything works as expected.
我不知道这是否有帮助,但也许您应该使用 JDK bin 目录中的 jconsole 二进制文件,而不是使用未记录的(并且可能会更改)sun.* 类来启动控制台
I don't know if this is helpful, but perhaps you should use the the jconsole binary in the JDK bin directory rather than using the undocumented (and subject to change) sun.* classes to start up the console
如果您的应用程序在 JDK 1.6 上运行,那么您应该能够连接它。如果它使用1.6之前的JDK,则通过指定以下JVM参数
-Dcom.sun.management.jmxremote来运行它
If your application is running on JDK 1.6 then you should be able to connect it. If it is using JDK prior to 1.6 then run it with specifying the following JVM argument
-Dcom.sun.management.jmxremote
我遇到了类似的问题,远程计算机位于防火墙后面,并且防火墙阻止了
-Dcom.sun.management.jmxremote.port
和 RMI46924
定义的端口。在允许我连接到这些端口后,我连接成功。I was having similar issue that remote machine was behind firewall and firewall was blocking ports defined by
-Dcom.sun.management.jmxremote.port
and RMI46924
. After allowing me to cnnect to these port I connected succesfully.如果您要访问防火墙后面的计算机,则需要打开 JMX 和 RMI 端口。
在这种情况下,强制 RMI 的值比依赖自动分配要好得多
就我而言,我试图访问 Tomcat,所以我必须执行以下操作:
然后
If you are accessing a machine behind a firewall, you need to open both JMX and RMI ports.
In this context, you are much better off forcing the value for RMI than relying on the auto assigned
In my case, I was trying to access Tomcat so I had to do the following:
and then
对我来说,我使用的是本地进程连接,并且遇到了与 OP 相同的问题。我的误解是,“如果是本地连接就不能被拒绝,对吗?”未必。
另一位用户 JeneralJames 在对萨马斯答案的评论中提到了与我完全相同的症状。
解决该问题的方法是断开与 VPN 的连接(或者在连接到 VPN 时启用 LAN 访问 - 我的 VPN 设置的非默认配置)。
我按照 rogerdpack 的建议运行
jconsole -debug
发现了这个问题,它向我显示了一个我在连接尝试中没有预料到的 IP(尽管是到本地进程的连接)。当时我的VPN设置完全禁止本地网络上的连接,因此java正在查找本地IP,获取值,但由于VPN配置不允许该IP连接,因此“本地连接”被拒绝。显然,即使对于本地连接,jconsole(或任何其他使用 JMX 应用程序的 MBean)默认情况下也会使用这个不正确的 IP。我希望这可以帮助其他人,我花了 3 天仔细阅读多个 stackoverflow 线程和 java 文档,直到发现 -debug 选项才无济于事。
For me, I was using a local process connection and had the same issue as OP. The misconception I had was, "Connection can't be refused if it local, right?" Not necessarily.
Another user, JeneralJames, mentioned the exact same symptoms I had in a comment on samarth's answer.
What resolved it was disconnecting from VPN (or alternatively enabling LAN access while connected to VPN - a non-default configuration for my VPN settings).
I discovered the issue by running
jconsole -debug
as suggested by rogerdpack, and it showed me an IP I was not expecting in the connection attempt (despite being a connection to a local process). My VPN settings at the time disallowed connections on the local network entirely, so java was looking up the local IP, getting the value, but that IP is not allowed to connect due to the VPN configuration, so the "local connection" was rejected.Apparently jconsole (or any other MBeans using JMX app for that matter) will use this incorrect IP by default even for local connections. I hope this helps someone else out, I have spent 3 days perusing multiple stackoverflow threads and java documentation to no avail until discovering that -debug option.
确保您正在使用以下 java 属性集运行应用程序
立即尝试连接。
如果你想调试这个,你可以使用以下命令运行jconsole
以下是logging.properties文件的内容
一旦你运行
jconsole
,将弹出一个单独的窗口显示日志。Make sure you are running your application with following java properties set
Try to connect now.
If you want to debug this ,you can run the jconsole with following command
Below is the content of logging.properties file
Once you run
jconsole
a separate window will pop up displaying logs.如果您运行 jconsole -debug ,它会为您提供有关故障的更多诊断信息。看
Daniel Fuchs 博客文章“连接问题疑难解答”在 JConsole 中”。
我这样做了,它显示我正在使用 32 位 jconsole,目标进程是使用不同的(64 位)jvm 启动的,所以显然这是不允许的,因此失败了。
if you run
jconsole -debug
it gives you more diagnostic info on the failure. Seethe Daniel Fuchs blog entry "Troubleshooting connection problems in JConsole".
I did this and it showed me I was using 32 bit jconsole the target process was started with a different (64 bit) jvm, so apparently this isn't allowed and it was thus failing.
这最终使它对我有用:提供这个额外的选项:
-Djava.rmi.server.hostname=
因此,所有 vm 参数都用于从远程计算机打开 jconsole ,远程机器上的jvm必须启动,
整个过程列于这里
This finally made it work for me : Giving this extra option:
-Djava.rmi.server.hostname=<ip addres where jvm is running
So all the vm arguments used to open jconsole from a remote machine, the jvm on the remote machine must be started with
The entire process is listed here