我正在尝试远程监控在docker中运行的JVM。配置如下所示:
机器1:在ubuntu机器上的docker中运行JVM(以我为例,运行kafka);本机的IP为10.0.1.201; 在docker中运行的应用程序位于172.17.0.85。
机器2:运行JMX监视
请注意,当我从机器2运行JMX监视时,它会失败,并显示以下错误(注意:当我运行jconsole,jvisualvm,jmxtrans和node-jmx / npm:jmx时,会发生相同的错误):
对于每个JMX监视工具,失败时的堆栈跟踪如下所示:
java.rmi.ConnectException: Connection refused to host: 172.17.0.85; nested exception is java.net.ConnectException: Operation timed out at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619) (followed by a large stack trace)
现在有趣的部分是,当我在运行docker的同一台机器(上方的机器1)上运行相同的工具(jconsole,jvisualvm,jmxtrans和node- jmx / npm:jmx)时,JMX监控正常运行。
我认为这表明我的JMX端口处于活动状态并且可以正常工作,但是当我从计算机2远程执行JMX监视时,它看起来像JMX工具无法识别内部docker IP(172.17.0.85)
以下是JMX监视起作用的机器1上的相关(我认为)网络配置元素(请注意docker ip,172.17.42.1):
docker0 Link encap:Ethernet HWaddr ... inet addr:172.17.42.1 Bcast:0.0.0.0 Mask:255.255.0.0 inet6 addr:... Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:6787941 errors:0 dropped:0 overruns:0 frame:0 TX packets:4875190 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:1907319636 (1.9 GB) TX bytes:639691630 (639.6 MB) wlan0 Link encap:Ethernet HWaddr ... inet addr:10.0.1.201 Bcast:10.0.1.255 Mask:255.255.255.0 inet6 addr:... Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:4054252 errors:0 dropped:66 overruns:0 frame:0 TX packets:2447230 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:2421399498 (2.4 GB) TX bytes:1672522315 (1.6 GB)
这是远程机器(机器2)上的相关网络配置元素,我从中得到了JMX错误:
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384 options=3<RXCSUM,TXCSUM> inet6 ::1 prefixlen 128 inet 127.0.0.1 netmask 0xff000000 inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 nd6 options=1<PERFORMNUD> en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500 ether .... inet6 ....%en1 prefixlen 64 scopeid 0x5 inet 10.0.1.203 netmask 0xffffff00 broadcast 10.0.1.255 nd6 options=1<PERFORMNUD> media: autoselect status: active
为了完整起见,以下解决方案有效。应当使用已建立的特定参数来运行JVM,以启用远程docker JMX监视,如下所示:
-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=<PORT> -Dcom.sun.management.jmxremote.rmi.port=<PORT> -Djava.rmi.server.hostname=<IP> where: <IP> is the IP address of the host that where you executed 'docker run' <PORT> is the port that must be published from docker where the JVM's JMX port is configured (docker run --publish 7203:7203, for example where PORT is 7203). Both `port` and `rmi.port` can be the same.
完成此操作后,您应该能够从本地或远程计算机执行JMX监视(jmxtrans,node-jmx,jconsole等)。
感谢@ Chris-Heald使此修复变得非常快速和简单!