DC/OS JMX Access

微笑、不失礼 提交于 2019-12-12 15:39:58

问题


I have a dc/os cluster deployed to azure. I have deployed to the cluster a container with my java application. But I can't access it via jmx.

Let's take the example of deploying a standart tomcat image:

1) I opened a port 8081 according the next instruction: https://docs.microsoft.com/en-us/azure/container-service/container-service-enable-public-access#open-a-port-portal.

2) I deployed service using the next json:

{
  "id": "/tomcat",
  "instances": 1,
  "cpus": 1,
  "mem": 512,
  "container": {
    "type": "DOCKER",
    "docker": {
      "image": "tomcat:8.0",
      "network": "BRIDGE",
      "portMappings": [
        { "protocol": "tcp", "hostPort": 8080   , "containerPort": 8080 },
        { "protocol": "tcp", "hostPort": 8081   , "containerPort": 8081 }
      ]
    }
  },
  "requirePorts": true,
  "acceptedResourceRoles": [
    "slave_public"
  ],
  "env": {      
    "JAVA_OPTS": "-Dcom.sun.management.jmxremote -Djava.rmi.server.hostname=10.0.0.4 -Dcom.sun.management.jmxremote.port=8081 -Dcom.sun.management.jmxremote.rmi.port=8081 -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"
  },
  "healthChecks": [
    {
      "gracePeriodSeconds": 120,
      "intervalSeconds": 30,
      "maxConsecutiveFailures": 3,
      "path": "/",
      "portIndex": 0,
      "protocol": "HTTP",
      "timeoutSeconds": 5
    }
  ]
}

To connect I use Oracle Java Mission Control. I fill fields 'Host' and 'Port' as 'prefixagents.westeurope.cloudapp.azure.com' and '8081'. But I can't connect and I get a message: 'Unable to connect'.

But for all that I can succesfully connect to this port using telnet client:

telnet prefixagents.westeurope.cloudapp.azure.com 8081

Also I can connect to port 8080 and I can open tomcat web console at the following URL: http://agents.westeurope.cloudapp.azure.com:8080

I installed one more jmx command line client - http://wiki.cyclopsgroup.org/jmxterm/ and tried to connect to the service:

java -jar jmxterm-1.0-alpha-4-uber.jar  --url service:jmx:rmi:///jndi/rmi://<prefix>agents.westeurope.cloudapp.azure.com:8081/jmxrmi

I got the next exception: "java.rmi.ConnectException: Connection refused to host: 10.0.0.4". And 10.0.0.4 is hostname of my public agents node.

I connected to my dc/os cluster ( master node ) using https://docs.microsoft.com/en-us/azure/container-service/container-service-connect. I also installed there jmxterm and tried to connect to the service via jmx:

java -jar jmxterm.jar --url service:jmx:rmi:///jndi/rmi://10.0.0.4:8081/jmxrmi

And I connected succesfully.

Does anybody have any ideas why I can connect to the service via jmx from my master node but I can't from my local machine? Port 8081 is opened.


回答1:


I changed a value of property -Djava.rmi.server.hostname in JAVA_OPTS string: -Djava.rmi.server.hostname="public agent ip". And it works for me. Working configuration for a standart tomcat container in case that port 8081 is open:

{
  "id": "/tomcat",
  "instances": 1,
  "cpus": 1,
  "mem": 512,
  "container": {
    "type": "DOCKER",
    "docker": {
      "image": "tomcat:8.0",
      "network": "BRIDGE",
      "portMappings": [
        { "protocol": "tcp", "hostPort": 8080   , "containerPort": 8080 },
        { "protocol": "tcp", "hostPort": 8081   , "containerPort": 8081 }
      ]
    }
  },
  "requirePorts": true,
  "acceptedResourceRoles": [
    "slave_public"
  ],
  "env": {      
    "JAVA_OPTS": "-Dcom.sun.management.jmxremote -Djava.rmi.server.hostname=<public agent ip> -Dcom.sun.management.jmxremote.port=8081 -Dcom.sun.management.jmxremote.rmi.port=8081 -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"
  },
  "healthChecks": [
    {
      "gracePeriodSeconds": 120,
      "intervalSeconds": 30,
      "maxConsecutiveFailures": 3,
      "path": "/",
      "portIndex": 0,
      "protocol": "HTTP",
      "timeoutSeconds": 5
    }
  ]
}

And I can connect to tomcat via jmx using from local machine: host="public agent ip" and port=8081

public agent ip = "prefix"agents.westeurope.cloudapp.azure.com




回答2:


Does anybody have any ideas why I can connect to the service via jmx from my master node but I can't from my local machine? Port 8081 is opened.

You should connect jmx as the following command.

java -jar jmxterm.jar --url service:jmx:rmi:///jndi/rmi://<agent public IP>:8081/jmxrmi 

Update:

hostname should be public agent ip, then you could connect jmx from your local PC.



来源:https://stackoverflow.com/questions/44372719/dc-os-jmx-access

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!