这个用于RMI JMX连接的Java代码有什么问题?我显然没有尝试连接到localhost,但错误暗示我是。在远程服务器上,我在端口1099上启用了JMX选项(无身份验证)。
这是我的groovy脚本:
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
答案 0 :(得分:1)
这是着名的java.rmi.server.hostname问题。通常由某些Linux发行版中的/ etc / hosts配置错误引起。 127.0.0.1应映射到localhost,您的真实主机名应映射到您的真实IP地址。有关其他解决方案,请参阅RMI常见问题解答中的A.1项。
编辑:既然您已经在问题中编辑了IP地址,那么您查找的JMX服务很可能不会在该IP地址上运行。
答案 1 :(得分:0)
您的代码试图连接到127.0.0.1
而不是远程
Connection refused to host: 127.0.0.1; nested exception is:
我怀疑您执行的代码与您遇到的代码不同。确保有问题的代码正在被执行。