JMX远程连接失败

10月 9, 2016 |

今天使用JMX远程连接kafka时,执行netstat -ntupl发现jmx 端口启动了,而且selinux关闭了,防火墙了关闭了,就是连接不上,一番google,发现是没有配置-Djava.rmi.server.hostname=ip address的缘故,why-do-i-need-to-define-java-rmi-server-hostname 解释了为什么需要配置这个属性,
摘录如下:

When you execute an RMI lookup server generates a stub and _hardcodes_ it's own address in it. Stub is then transfered to the client and address generated by the server used for method remoting. The address hardcoded in the stub has nothing to do with an address you used for a lookup. The algorithm used by the server to find it's own address is not very smart and fails to produce a meaningful result in all but trivial network configurations (very often it produces "localhost" so your rmi clients end up sending requests to themselves). That's why, most of the times, it's needed to override the algorithm by setting java.rmi.server.hostname.

大致的意思是,我们启动jconsole指定的ip:port只是用于RMI lookup,返回的Stub 中才有我们执行JMX远程方法操作的地址,但是默认算法有问题,经常讲这个地址解析为localhost,所以我们远程连接时通过java.rmi.server.hostname指定正确的服务器地址。

Posted in: WEB开发

Comments are closed.