提问者:小点点

RMI JMX连接的Java代码有什么问题?


RMI JMX连接的Java代码有什么问题?我显然没有尝试连接到localhost但错误暗示我正在连接。在远程服务器上,我在端口1099上启用了JMX选项(没有身份验证)。

这是我的时髦脚本:

import javax.management.remote.*;    
JMXServiceURL u = 
 new JMXServiceURL("service:jmx:rmi://10.222.244.185:9999/jndi/rmi://10.222.244.185:1099/jmxrmi");    
JMXConnector c = JMXConnectorFactory.connect(u);

这是我得到的错误:

C:\Temp>groovy jmx.gv
Caught: java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Conn
ection refused to host: 10.222.244.185; nested exception is:
        java.net.ConnectException: Connection refused: connect]
java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection r
efused to host: 10.222.244.185; nested exception is:
        java.net.ConnectException: Connection refused: connect]
        at jmx.run(jmx.gv:5)
Caused by: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: 10.222.244.185; nested except
ion is:
        java.net.ConnectException: Connection refused: connect]
        at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:101)
        at com.sun.jndi.toolkit.url.GenericURLContext.lookup(GenericURLContext.java:185)
        ... 1 more
Caused by: java.rmi.ConnectException: Connection refused to host: 10.222.244.185; nested exception is:
        java.net.ConnectException: Connection refused: connect
        at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:97)
        ... 2 more
Caused by: java.net.ConnectException: Connection refused: connect
        ... 3 more

共3个答案

匿名用户

这是著名的java. rmi.server.hostname问题。通常由某些Linux发行版中 /etc/hosts错误配置引起。127.0.0.1应该映射到localhost,您的真实主机名应该映射到您的真实IP地址。有关其他解决方案,请参阅RMIFAQ中的A.1项。

编辑:现在您已经编辑了问题中的IP地址,您正在查找的JMX服务更有可能不在该IP地址上运行。

匿名用户

不知何故,您的代码试图连接到127.0.0.1而不是远程

Connection refused to host: 127.0.0.1; nested exception is:

我怀疑您正在执行的代码与您有问题的代码不同。确保正在执行您有问题的任何代码。

匿名用户

这更多的是配置问题,你必须明确提及如何访问存根。尝试通过JVM参数设置jmxRemote选项。以下选项可能会解决您的问题。我为自己的项目尝试了同样的方法。

-Dcom.sun.management.jmxremote 
-Dcom.sun.management.jmxremote.port=8091
-Dcom.sun.management.jmxremote.rmi.port=8091
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false