我有一个部署到远程树脂服务器的Web应用程序,它已打开JMX。
我可以telnet到远程服务器,即
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)
你们有没有想过如何调试这个(即找出错误的地方)?
答案 0 :(得分:32)
确保使用以下java属性集
运行应用程序-Dcom.sun.management.jmxremote.port=9005
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
立即尝试连接。 如果要调试它,可以使用以下命令运行jconsole
jconsole -J-Djava.util.logging.config.file=path_to_logging.properties_for_jconsole
以下是logging.properties文件的内容
Logging.properties
handlers = java.util.logging.ConsoleHandler
.level = INFO
java.util.logging.ConsoleHandler.level = FINEST
java.util.logging.ConsoleHandler.formatter = \
java.util.logging.SimpleFormatter
// Use FINER or FINEST for javax.management.remote.level - FINEST is
// very verbose...
javax.management.level = FINEST
javax.management.remote.level = FINER
运行jconsole
后,会弹出一个单独的窗口显示日志。
答案 1 :(得分:19)
如果您运行jconsole -debug
,它会为您提供有关失败的更多诊断信息。看到
the Daniel Fuchs blog entry "Troubleshooting connection problems in JConsole"
我这样做了,它显示我使用32位jconsole,目标进程是用不同的(64位)jvm启动的,所以显然这是不允许的,因此失败了。
答案 2 :(得分:9)
这最终使它对我有用:给予这个额外选项:-Djava.rmi.server.hostname=<ip addres where jvm is running
因此,所有用于从远程计算机打开jconsole的vm参数,必须以
启动远程计算机上的jvm -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=<port> -Dcom.sun.management.jmxremote -com.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=<ip address>
列出整个过程here
答案 3 :(得分:3)
通过cygwin启动Java-Process时遇到了同样的问题。 JConsole无法连接。通过win7-cmd启动它一切都按预期工作。
答案 4 :(得分:1)
我不知道这是否有用,但也许您应该使用JDK bin目录中的jconsole二进制文件,而不是使用未记录的(并且可以更改)sun。*类来启动控制台
答案 5 :(得分:1)
如果您的应用程序在JDK 1.6上运行,那么您应该能够连接它。如果它使用1.6之前的 JDK ,则使用指定以下JVM参数运行它
<强> -Dcom.sun.management.jmxremote 强>
答案 6 :(得分:1)
我遇到了类似的问题,即远程计算机位于防火墙之后,防火墙阻止了-Dcom.sun.management.jmxremote.port
和RMI 46924
定义的端口。允许我连接到这些端口后,我成功连接。
答案 7 :(得分:0)
如果要访问位于防火墙后面的计算机,则需要同时打开JMX和RMI端口。
在这种情况下,与依靠自动分配相比,强加RMI值要好得多
就我而言,我试图访问Tomcat,因此必须执行以下操作:
#!/bin/sh
CATALINA_OPTS="$CATALINA_OPTS -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses=true -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8008 -Dcom.sun.management.jmxremote.rmi.port=8007 -Dcom.sun.
management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"
然后
firewall-cmd --zone=public --add-port=8008/tcp --permanent
firewall-cmd --zone=public --add-port=8007/tcp --permanent
firewall-cmd --reload