远程JMX访问拒绝:Caused by: java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested

在使用Jmx获取ActiveMQ信息时,访问远程Linux开发机器上的Jmx,代码片段:

RemoteJMXBrokerFacade createConnector = new RemoteJMXBrokerFacade();
System.setProperty("webconsole.jmx.url","service:jmx:rmi://jndi/rmi://10.17.2.216:1099/jmxrmi");
System.setProperty("webconsole.jmx.user","admin");
System.setProperty("webconsole.jmx.password","activemq");
SystemPropertiesConfiguration configuration = new SystemPropertiesConfiguration();
createConnector.setConfiguration(configuration);
BrokerViewMBean brokerAdmin = createConnector.getBrokerAdmin();

报异常:
java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested
这个127.0.0.1非常奇怪,后来查清是远程JMX启动时参数错误导致。
解决方法:
在activemq启动脚本中编辑,找到 $ ACTIVEQM_SUNJMX_START,在后面加 -Djava.rmi.server.hostname=
例如我的是-Djava.rmi.server.hostname=10.17.2.216
重启ActiveMQ,可正常连接。

你可能感兴趣的:(远程JMX访问拒绝:Caused by: java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested)