如何将 JConsole 附加到远程 JVM?

How to attach JConsole to a remote JVM?

我有一个 Java 8 应用程序 运行ning 在远程 Linux 服务器上,需要将 JConsole 附加到它以进行调试。

我从我的本地机器设置了一个到远程机器的隧道:

 ssh -fN -L 9999:localhost:9999 myuser@1.11.11.111

在远程机器上我运行具有以下系统属性的应用程序:

java -Dcom.sun.management.jmxremote.port=9999 \
-Dcom.sun.management.jmxremote.authenticate=false \ 
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.local.only=false \
-cp foo.jar:config com.foo.bar.Main config/blah.properties

但是当我启动 JConsole 时,我得到安全连接失败。

如果我点击 "Insecure connection" 我得到

我该如何解决这个问题?

我设法让它工作,为 RMI 端口添加一个额外的系统属性:

java \
-Dcom.sun.management.jmxremote.port=9999 \
-Dcom.sun.management.jmxremote.rmi.port=9999 \
-Dcom.sun.management.jmxremote.authenticate=false \ 
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.local.only=false \
-cp foo.jar:config com.foo.bar.Main config/blah.properties