设为首页 收藏本站
查看: 742|回复: 0

[经验分享] 【转】jconsole won't connect to remote JVM on linux

[复制链接]

尚未签到

发表于 2016-3-9 08:53:59 | 显示全部楼层 |阅读模式
  本文出处:http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6209663
  



Bug ID:

6209663

Votes

7

Synopsis

jconsole won't connect to remote JVM on Linux

Category

java:jconsole

Reported Against

Release Fixed

State

<!-- remove filtering state: show bug status/substatus
<font face="" color="#ff0000">Not a Defect</font>
-->11-Closed, Not a Defect, <!-- show area regardless of statusDetail
-->
bug

Priority:

3-Medium

Related Bugs

Submit Date

16-DEC-2004

Description

FULL PRODUCT VERSION :
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

Work Around

N/A

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

I see a very similar effect. I have one machine running Debian amd64 sarge that I am unable to connect to - I can connect locally using local connection. I can even connect "remotely" on the same machine by using 127.0.0.1 or it's IP address. I just cannot connect remotely from another machine - I get the same "Connection Failed". A netstat shows an ESTABLISHed connection to the correct port, the connection will not go TIME_WAIT until I click cancel on the connection window (even though it says Connection failed). I've tried both Debian i386/amd64 and solaris 10 beta 72 jconsoles (amd64 1.6.0 build) without success. A i386 machine with the exact same java -D args will allow connections. Its very very strange.
java version:
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) 64-Bit Server VM (build 1.5.0-b64, mixed mode)

/usr/lib/j2sdk1.5-sun/bin/java -server -Djava.awt.headless=true -Xmx896m -XX:+PrintGCDetails -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8400 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.endorsed.dirs=/usr/share/tomcat5/common/endorsed -classpath /usr/lib/j2sdk1.5-sun/lib/tools.jar:/usr/lib/j2sdk1.5-sun/jre//lib/jcert.jar:/usr/lib/j2sdk1.5-sun/jre//lib/jnet.jar:/usr/lib/j2sdk1.5-sun/jre//lib/jsse.jar:/usr/share/tomcat5/bin/bootstrap.jar:/usr/share/tomcat5/bin/commons-logging-api.jar -Dcatalina.base=/var/lib/tomcat5 -Dcatalina.home=/usr/share/tomcat5 -Djava.io.tmpdir=/var/lib/tomcat5/temp org.apache.catalina.startup.Bootstrap -config /etc/tomcat5/server0.xml start
  

Submitted On21-DEC-2004
bclbob

Futher investigation
Java code:
public class Sleep
{
public static void main( String[] args)
{
try
{
Thread.sleep(10000000);
}
catch (Exception e)
{
// eat
}
}
}

java cmd line:
java -Dcom.sun.management.jmxremote.port=8900 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false Sleep
still causes the same issue on the amd64 machine, but connects fine on i386.
amd64 java -version:
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) 64-Bit Server VM (build 1.5.0-b64, mixed mode)
i386 java -version:
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)

  

Submitted On29-DEC-2004
opty

Same problem here on Linux Mandrake 10.1 for x86-64 (Xeon EM64T here), when looking on jconsole localy the remote jconsole connection thread is at
java.net.SocketInputStream.socketRead0() for for few seconds before terminating, so the there have been a connection but something failed while communicating...
  

Submitted On06-JAN-2005
bclbob

Still an issue on Linux amd64 with SR1
java -version
java version "1.5.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_01-b08, mixed mode)

Can't connect remotely from Windows or Linux or Solaris 10 b72.
  

Submitted On14-JAN-2005
masterzen666

I confirm the problem:
client on debian/sarge i386
server on debian/sarge amd64 (EM64T)
Same VM running on client & server (except 64bit one for server):
java version "1.5.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_01-b08, mixed mode)
Analysis of a network trace seems to show that the remote part sends 127.0.0.1 as IP address.
Analysis of a network trace taken on 'lo' (on the client) shows that the jconsole tries to connect to a port that is not open on the client (because it is open on the server).
It might be related to the /etc/hosts file and the hostname to IP conversion...
I found the culprit and a workaround: my /etc/hosts was:
127.0.0.1 localhost localhost.localdomain server4
Changed that to
127.0.0.1 localhost localhost.localdomain
192.168.0.230 server4
fixed the problem....

  

Submitted On19-JAN-2005
bclbob

Thanks masterzen666 - that worked for me! great work
  

Submitted On21-JAN-2005
marcoesch

I dont think it is related to name resolution. I am experiencing  the same problem. On the server I can see the socket going in to LISTEN mode on the specified port. When the client tries to connect I can see it going into ESTABLISHED with ip address from the client running jconsole  ... but still get connection fialed on the client.
tcp        0      0 *:9930                  *:*                     LISTEN
tcp        0      0 ::ffff:10.107.0.15:9930 ::ffff:10.107.0.25:1641 ESTABLISHED

  

Submitted On04-FEB-2005
opty

The above evaluation trick for /etc/hosts works with a straight connection, but it won
  

Submitted On14-FEB-2005
bjerkz

The "trick" with /etc/hosts solves it for me, too.
Thanks!

  

Submitted On03-MAR-2005
opty

/etc/hosts doesn
  

Submitted On03-MAR-2005
opty

/etc/hosts does not resolve when using NAT or SSH tunneling
  

Submitted On03-MAR-2005
Caffeine0001

If you are behind a NAT or firewall and having problems, see the second reply of http://forum.java.sun.com/thread.jspa?threadID=289869&messageID=1242288 and http://java.sun.com/j2se/1.4/docs/guide/rmi/faq.html#nethostname.  Please also add this to the JConsole FAQ.
  

Submitted On15-FEB-2007


I am running Ubuntu Edgy and I definitely see this problem.  I don't know whose fault it is, but it's definitely a bug.  I have a pretty comprehensive writeup including a workaround here:
http://trac.marketcetera.org/trac.fcgi/wiki/Marketcetera/UbuntuJMX
  

Submitted On19-FEB-2007
HolgerK

If have the same problem even with proper hostname setup.
JDK 1.5.0.11, Linux/i386, two machines.
I can connect to the remote port via "telnet server port", but jconsole reports "connection failed" when started on client (oder server).
BTW: jmxremote documentation is inconsistant:
1.) gui screwup: I found no place how users and roles relate. all documentation seems to use these terms als synonyms. the remote dialog in jconsole should read "rolename", not "username" in this case.
2.) typo: the commed in jmxremote.password reads monitorRole and measureRole.
  

Submitted On29-MAR-2007
SheepShepherd

For my RedHat AS3  the trick with /etc/hosts was not enough until I changed my host name with "hostname -v <name_of_my_machine>"  command (root privileges are required).
  

Submitted On26-JUL-2007
mipito

I'm having the same problem on a linux box and the 'hostname' fix doesn't help. Issuing 'hostname -i" gives me the true ip.
I fire up the process to be monitored on the server, ssl & authentication disabled. On the client (a pc) i fire up jconsole and the connection is established as displayed by netstat, but for some reason it ends up in "connection failed".
What is jconsole trying to do at this point? I can connect fine to that port using telnet.
  

Submitted On27-JUL-2007
mipito

Ok, the problem i was running into (see my previous comment) and is now resolved is that the jvm you're trying to connect to actually exposes *two* ports, the one specified via -Dcom.sun.management.jmxremote.port, and some other one. The 2nd one is random, but jconsole wants to connect to it, so if you have a firewall, and you've only opened up the above port, you're hosed. I don't know if it's possible to specify both ports on the cmd line, which is what you'd want to do if you have to poke holes in your firewall.
I believe there is a way to write code to get around this problem, but that's a pain, in particular when one is not in control of that code.
  

Submitted On22-AUG-2008
r_d

adding -Djava.rmi.server.hostname=<host ip> should help resolve this problem.
  


PLEASE NOTE: JDK6 is formerly known as Project Mustang

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-188315-1-1.html 上篇帖子: 深度介绍Linux内核是如何工作的 下篇帖子: Linux对I/O端口资源的管理(ZZ)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表