Jconsole 无法连接运行于远程 Linux 主机上的 JVM

转载于:http://rhythm-zju.blog.163.com/blog/static/31004200801502012968/

最近开始在手头的项目里应用 JMX 进行 Java 应用服务器的远程监控管理。然而在使用 jconsole 进行调试的时候遇到了标题所述的问题: jconsole 无法连接运行于远程 Linux 主机上的 JVM , 通过 Google 找到这篇博客:

http://shallon.javaeye.com/blog/129750

从而找到 Sun Bug Database 中的 6209663 号记录,位于:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6209663

在阅读之前很开心地看到该 Bug 的状态为:

Closed, not a bug

好兆头。Bug 明细摘录如下(为便于阅读做了少量格式编辑):

java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode)

JDK 1.5.0
JDK 1.6.0-EA

ADDITIONAL OS VERSION INFORMATION :
-----------------------------------

Fedora Core 3 2.6.9-667
Debian testing 2.6.8-1
Debian unstable 2.6.9-1
SUSE ENTERPRISE LINUX 9
Windows XP SP 1


A DESCRIPTION OF THE PROBLEM :
------------------------------

jconsole won't connect to a remote Linux JVM - "connection failed". Tested on
different Linux distributions and versions, and on different JVMs.

I can connect just fine locally on all Linux platforms, using either Local or
Remote tab in jconsole.

I can also connect remotely from Linux to JVM on Windows XP, using the same
command line and SampleTest.

Connecting from Linux to Linux or from Windows to Linux does NOT work, however.

I'm not running firewalls or filters on any of these systems. Network is
working, cause I'm using ssh/scp/ftp to login and copy files etc. ping between
these systems work. I can also connect using telnet remote-ip 8999 from the
jconsole box to the remote JVM and see that it actually responds (pressing
Enter three times closes the connection).

I'm having the same problem for authenticated (still no ssl) connection. This
also means that authenticated works *locally*, just not remotely.

On the "server" side, I'm using the JMX SampleTest program.

(Haven't found anything in the installation notes or release notes indicating
this should not work on Linux. Also, haven't found anything in Bug Parade, on
java.net/java.sun.com forums or Google.)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
------------------------------------------

On the "server" side:

    java /
        -Dcom.sun.management.jmxremote.port=8999 /
        -Dcom.sun.management.jmxremote.authenticate=false /
        -Dcom.sun.management.jmxremote.ssl=false SampleTest /

(used -Dcom.sun.management.jmxremote only to test Local-only connection.)

On the client side:

    jconsole remote-ip:8999

EXPECTED VERSUS ACTUAL BEHAVIOR :
---------------------------------

EXPECTED - Connect!
ACTUAL - jconsole reports "Connection failed".

ERROR MESSAGES/STACK TRACES THAT OCCUR :
----------------------------------------

jconsole reports "Connection failed".

REPRODUCIBILITY :
-----------------

This bug can be reproduced often.

xxxxx@xxxxx 2004-12-16 19:25:03 GMT

果然,在该 Bug 的 Evaluation 中找到了答案:

I'm able to connect from Windows to Linux and also from Linux to Linux.

The application is running on RedHat A.S. 2.1. JDK 5.0 jconsole running on
Windows 2000 and RedHat Enterprise Linux 3.0 Update 1 both work!

I suspect this is related to the hostname resolution. Suggest the submitter to
try entering IP address instead of hostname to verify if it works or not.

xxxxx@xxxxx 2004-12-16 20:01:44 GMT


Some Linux distributions setup /etc/hosts so that the hostname resolves to the
loopback address rather than the host address. If you use "hostname -i" and it
reports 127.0.0.1 then you may have problems with RMI and jconsole. Editing
/etc/hosts so that the hostname resolves to the host address will fix the
issue.

xxxxx@xxxxx 2005-2-03 17:20:00 GMT

The submitter has verified that it's a Linux /etc/hosts problem as described
above in the evalution. This will be closed as "not a defect". We will
document this problem in the JConsole FAQ in the next documentation update
under:

   http://java.sun.com/j2se/1.5.0/docs/guide/management/jconsole.html

xxxxx@xxxxx 2005-03-02 19:03:00 GMT

果不其然,经检查,我所使用的这台 32 位 Debian Linux 主机的 /etc/hosts 的第一行为:

127.0.0.1 domain-name host-name

将 127.0.0.1 改为主机真实 IP 后,一切正常。

老外报 Bug 真是认真呀:问题描述、重现步骤、错误表现、可重现频度,全都一一详细列举。

猜你喜欢

转载自blog.csdn.net/qq_36838191/article/details/86510222