【问题标题】:How to connect to JMX server running inside WSL2如何连接到在 WSL2 中运行的 JMX 服务器
【发布时间】:2021-02-16 10:33:53
【问题描述】:

我正在使用启用 JMX 服务器远程连接的以下参数运行我的 Java 应用程序:

-Dcom.sun.management.jmxremote=true
-Dcom.sun.management.jmxremote.port=9998
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false

我可以通过 VisualVM 成功连接到该 JMX 服务器,方法是将新的 JMX 连接添加到地址:<HOSTNAME>:9998

但是当我在 Windows Subsystem for Linux 2 (WSL2) 中运行该应用程序时,Visual VM 无法连接到localhost:9998: connection failed

据我所知,应用程序在 WSL2 中侦听的每个端口也在主机(Windows 本身)中打开,我可以使用Win+R -> cmd -> telnet localhost 9998(连接成功)来检查。 另外,我在 WSL2 中运行一个 nginx 实例,我可以使用 localhost 连接到我的主机 (Windows) 上的任何浏览器。

【问题讨论】:

    标签: java windows-subsystem-for-linux jmx visualvm wsl-2


    【解决方案1】:

    我无法使用上述任何建议让 Windows jconsole 连接到在 WSL2 中运行的 JVM,但是现在可以使用 Windows 11 的 Linux GUI 支持在 WSL2 中运行 Linux jconsole。完美运行。

    【讨论】:

      【解决方案2】:

      这似乎是 Java 的普遍问题。

      https://github.com/microsoft/WSL/discussions/6253

      对我有用的解决方法是使用 JMX 服务器在 WSL2 中侦听“0.0.0.0”而不是“127.0.0.1”。

      【讨论】:

      • 你的意思是使用-D=com.sun.management.jmxremote.host=0.0.0.0?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-02
      • 2020-07-15
      • 2022-08-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多