这段用于 RMI JMX 连接的 Java 代码有什么问题?我显然没有尝试连接到本地主机,但错误暗示我是。在远程服务器上,我在端口 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
最佳答案
这就是著名的 java.rmi.server.hostname 问题。通常是由某些 Linux 发行版中的/etc/hosts 配置错误引起的。 127.0.0.1 应该映射到本地主机,你的真实主机名应该映射到你的真实 IP 地址。请参阅 RMI FAQ 中的 A.1 项以获取另一种解决方案。
编辑:既然您已经编辑了问题中的 IP 地址,您正在查找的 JMX 服务更有可能根本没有在该 IP 地址上运行。
关于java - 这段用于 RMI JMX 连接的 Java 代码有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13279082/