从kubernetes pod转发的JMX不同端口

时间:2018-10-24 12:26:07

标签: java kubernetes profiling jmx

我在将jmx从kubernetes pod转发到本地主机时遇到问题。 将端口转发到同一端口时,一切正常:

kubectl port-forward ... 9010:9010 OR
kubectl port-forward ... 9010

但是,当我尝试转发到其他本地端口时,

kubectl port-forward ... 9011:9010

jconsole或jms都无法连接。

这使我无法一次分析多个应用程序。

JMS错误:

com.oracle.jmc.rjmx.ConnectionException caused by java.rmi.NoSuchObjectException: no such object in table
    at com.oracle.jmc.rjmx.internal.RJMXConnection.connect(RJMXConnection.java:406)
    at com.oracle.jmc.rjmx.internal.ServerHandle.doConnect(ServerHandle.java:88)
    at com.oracle.jmc.rjmx.internal.ServerHandle.connect(ServerHandle.java:78)
    at com.oracle.jmc.console.ui.editor.internal.ConsoleEditor$ConnectJob.run(ConsoleEditor.java:73)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Caused by: java.rmi.NoSuchObjectException: no such object in table
    at java.rmi/sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:283)
    at java.rmi/sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:260)
    at java.rmi/sun.rmi.server.UnicastRef.invoke(UnicastRef.java:161)
    at java.management.rmi/javax.management.remote.rmi.RMIServerImpl_Stub.newClient(Unknown Source)
    at java.management.rmi/javax.management.remote.rmi.RMIConnector.getConnection(RMIConnector.java:2105)
    at java.management.rmi/javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:321)
    at com.oracle.jmc.rjmx.internal.RJMXConnection.connectJmxConnector(RJMXConnection.java:451)
    at com.oracle.jmc.rjmx.internal.RJMXConnection.establishConnection(RJMXConnection.java:427)
    at com.oracle.jmc.rjmx.internal.RJMXConnection.connect(RJMXConnection.java:399)
    ... 4 more

jconsole错误:

Connection to localhost:9011 did no succeed.

1 个答案:

答案 0 :(得分:2)

这是RMI问题。问题在于,传递给JMX客户端的RMI存根是为9010创建的,因此在尝试在9011进行连接时失败。有here概述了几个不错的解决方案。另一个选择是切换到JMXMP,它是纯套接字JMX协议,因此端口转发可以正常工作,而无需任何其他解决方法。