简体   繁体   English

如何从外部访问 VM 上 docker 容器中的 JMX 接口?

[英]How to access JMX interface in docker container on VM from outside?

I am trying to remotely monitor a JVM running in docker.我正在尝试远程监控在 docker 中运行的 JVM。 The configuration looks like this:配置如下所示:

machine: runs a JVM (in my case, Hello-World springboot app) in docker on an ubuntu machine (VM);机器:在 ubuntu 机器(VM)上的 docker 中运行 JVM(在我的例子中是 Hello-World springboot 应用程序); the IP of this machine is 10.10.1.29;本机IP为10.10.1.29; docker container has IP 172.28.0.3; docker 容器的 IP 为 172.28.0.3; and to connect to VM by ssh I putted my creds并通过 ssh 连接到 VM 我把我的信任

I have DockerFile of myApp我有 myApp 的 DockerFile


// some docker commands 

EXPOSE 9010
CMD ["java", \
 "-Dcom.sun.management.jmxremote", \
 "-Dcom.sun.management.jmxremote.authenticate=false", \
 "-Dcom.sun.management.jmxremote.ssl=false", \
 "-Dcom.sun.management.jmxremote.port=9010", \
 "-Dcom.sun.management.jmxremote.rmi.port=9010", \
 "-Djava.rmi.server.hostname=10.10.1.29", \
 "-jar /app/myApp-1.0.0.jar"]

the container starts and everything is super by docker-compose容器启动,一切都由 docker-compose 完成

config docker-compose.yaml:配置 docker-compose.yaml:

// some yaml config
 
    ports:
      - "9010:9010" # JMX
    

I am running jconsole locally and tried to run this我在本地运行 jconsole 并尝试运行它

service:jmx:rmi:///jndi/rmi://10.10.1.29:9010/jmxrmi

but connection failed但连接失败

I tried different options but unfortunately unsuccessfully我尝试了不同的选择,但不幸的是没有成功

Does anyone have a solution to this?有人对此有解决方案吗? Maybe the configuration is incorrect?也许配置不正确?

You will have to look into several issues here:您将不得不在这里研究几个问题:

  • run the JVM with JMX enabled.在启用 JMX 的情况下运行 JVM。 Be aware of the port that is opened to access these values请注意为访问这些值而打开的端口
  • run the docker container such that the port to the outside of the container运行 docker 容器,以便将端口连接到容器外部
  • as the container is running inside some OS ensure there is no firewall preventing access to this port from outside the OS由于容器在某些操作系统内运行,请确保没有防火墙阻止从操作系统外部访问此端口
  • as the OS is running inside a VM ensure that VM is fowarding traffic to the correct port由于操作系统在 VM 内运行,请确保 VM 将流量转发到正确的端口
  • from outside the VM access the correct interface/port.从 VM 外部访问正确的接口/端口。 If this access is from outside the host OS, ensure the host OS does not implement a firewall and forwards the traffic correctly如果此访问来自主机操作系统外部,请确保主机操作系统未实施防火墙并正确转发流量

Failure on any of these points will simply not give you access.在任何这些点上的失败都不会让您访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM