Acesso através do jmx ao aplicativo java no contêiner do Docker no host remoto na rede local

1

Não consigo me conectar por meio do jmx (com VisualVM) ao aplicativo java no contêiner do Docker no host remoto na rede local.

Captura de tela do problema.

Caso 1: aplicativo Java no contêiner do Docker no cliente:

Conectar ao aplicativo (porta 6830) - funciona Conecte-se ao jmx (porta 6831) - funciona

java -Dhttp.port=9010 \
     -Dcom.sun.management.jmxremote.port=9011 \
     -Dcom.sun.management.jmxremote.ssl=false \
     -Dcom.sun.management.jmxremote.authenticate=false \
     -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9012 \
     -jar application.jar

docker run -d \
           -p 6830:9010 \
           -p 6831:9011 \
           --name container_name \
           base_image \
           setup.sh

Caso 2: Aplicativo Java sem contêiner do Docker no host remoto:

Conectar ao aplicativo (porta 6830) - funciona Conecte-se ao jmx (porta 6831) - funciona

java -Dhttp.port=6830 \
     -Dcom.sun.management.jmxremote.port=6831 \
     -Dcom.sun.management.jmxremote.ssl=false \
     -Dcom.sun.management.jmxremote.authenticate=false \
     -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=6832 \
     -jar application.jar

Caso 3: Applicação Java no contêiner do Docker no host remoto :

Conectar ao aplicativo (porta 6830) - funciona
Conecte-se ao jmx (porta 6831) - não está funcionando

java -Dhttp.port=9010 \
     -Dcom.sun.management.jmxremote.port=9011 \
     -Dcom.sun.management.jmxremote.ssl=false \
     -Dcom.sun.management.jmxremote.authenticate=false \
     -Dcom.sun.management.jmxremote.local.only=false \
     -Dcom.sun.management.jmxremote.rmi.port=9011 \
     -Djava.rmi.server.hostname="192.168.0.2" \
     -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9012 \
     -jar application.jar

docker run -d \
           -p 6830:9010 \
           -p 6831:9011 \
           --name container_name \
           base_image \
           setup.sh

Resultado netstat -tunelp | grep 6831 no servidor:

tcp6       0      0 :::6831                 :::*                    LISTEN      0          84051435    10094/docker-proxy

Resultado netstat -tunelp | grep 9011 no contêiner do Docker:

tcp6       0      0 :::9011                 :::*                    LISTEN      0          84052513    7/java

Informação adicional:

  • IP do servidor: 192.168.0.2
  • IP do cliente: 192.168.0.120
  • SO do servidor: Debian 8.5 x86_64
  • SO do cliente: Kubuntu 15.10 x86_64
  • Docker (servidor e cliente): 1.11.2
  • Java no Docker: 1.8.0_91-b14
  • OpenJDK no cliente: 1.7.0_101
  • VisualVM: 1.3.8

Atualização # 1

Registra tshark no cliente:

  1   0.000000 192.168.0.120 -> 192.168.0.2  TCP 74 52936→6831 [SYN] Seq=0 Win=29200 Len=0 MSS=1460 SACK_PERM=1 TSval=61129885 TSecr=0 WS=128
  2   0.000162  192.168.0.2 -> 192.168.0.120 TCP 74 6831→52936 [SYN, ACK] Seq=0 Ack=1 Win=28960 Len=0 MSS=1460 SACK_PERM=1 TSval=1212891632 TSecr=61129885 WS=128
  3   0.000196 192.168.0.120 -> 192.168.0.2  TCP 66 52936→6831 [ACK] Seq=1 Ack=1 Win=29312 Len=0 TSval=61129885 TSecr=1212891632
  4   0.000298 192.168.0.120 -> 192.168.0.2  TCP 73 52936→6831 [PSH, ACK] Seq=1 Ack=1 Win=29312 Len=7 TSval=61129886 TSecr=1212891632
  5   0.000391  192.168.0.2 -> 192.168.0.120 TCP 66 6831→52936 [ACK] Seq=1 Ack=8 Win=29056 Len=0 TSval=1212891632 TSecr=61129886
  6   0.000931  192.168.0.2 -> 192.168.0.120 TCP 86 6831→52936 [PSH, ACK] Seq=1 Ack=8 Win=29056 Len=20 TSval=1212891632 TSecr=61129886
  7   0.000941 192.168.0.120 -> 192.168.0.2  TCP 66 52936→6831 [ACK] Seq=8 Ack=21 Win=29312 Len=0 TSval=61129886 TSecr=1212891632
  8   0.000987 192.168.0.120 -> 192.168.0.2  TCP 81 52936→6831 [PSH, ACK] Seq=8 Ack=21 Win=29312 Len=15 TSval=61129886 TSecr=1212891632
  9   0.001024 192.168.0.120 -> 192.168.0.2  TCP 116 52936→6831 [PSH, ACK] Seq=23 Ack=21 Win=29312 Len=50 TSval=61129886 TSecr=1212891632
 10   0.001128  192.168.0.2 -> 192.168.0.120 TCP 66 6831→52936 [ACK] Seq=21 Ack=73 Win=29056 Len=0 TSval=1212891632 TSecr=61129886
 11   0.001544  192.168.0.2 -> 192.168.0.120 TCP 381 6831→52936 [PSH, ACK] Seq=21 Ack=73 Win=29056 Len=315 TSval=1212891632 TSecr=61129886
 12   0.006570 192.168.0.120 -> 192.168.0.2  TCP 81 52936→6831 [PSH, ACK] Seq=73 Ack=336 Win=30336 Len=15 TSval=61129887 TSecr=1212891632
 13   0.010023 192.168.0.120 -> 192.168.0.2  TCP 74 52940→6831 [SYN] Seq=0 Win=29200 Len=0 MSS=1460 SACK_PERM=1 TSval=61129888 TSecr=0 WS=128
 14   0.010176  192.168.0.2 -> 192.168.0.120 TCP 74 6831→52940 [SYN, ACK] Seq=0 Ack=1 Win=28960 Len=0 MSS=1460 SACK_PERM=1 TSval=1212891634 TSecr=61129888 WS=128
 15   0.010204 192.168.0.120 -> 192.168.0.2  TCP 66 52940→6831 [ACK] Seq=1 Ack=1 Win=29312 Len=0 TSval=61129888 TSecr=1212891634
 16   0.011325 192.168.0.120 -> 192.168.0.2  TCP 178 52940→6831 [PSH, ACK] Seq=1 Ack=1 Win=29312 Len=112 TSval=61129888 TSecr=1212891634
 17   0.011561  192.168.0.2 -> 192.168.0.120 TCP 66 6831→52940 [ACK] Seq=1 Ack=113 Win=29056 Len=0 TSval=1212891635 TSecr=61129888
 18   0.011572  192.168.0.2 -> 192.168.0.120 TCP 66 6831→52940 [FIN, ACK] Seq=1 Ack=113 Win=29056 Len=0 TSval=1212891635 TSecr=61129888
 19   0.011656 192.168.0.120 -> 192.168.0.2  TCP 73 52940→6831 [PSH, ACK] Seq=113 Ack=2 Win=29312 Len=7 TSval=61129888 TSecr=1212891635
 20   0.011700 192.168.0.120 -> 192.168.0.2  TCP 66 52940→6831 [FIN, ACK] Seq=120 Ack=2 Win=29312 Len=0 TSval=61129888 TSecr=1212891635
 21   0.011780  192.168.0.2 -> 192.168.0.120 TCP 60 6831→52940 [RST] Seq=2 Win=0 Len=0
 22   0.011791  192.168.0.2 -> 192.168.0.120 TCP 60 6831→52940 [RST] Seq=2 Win=0 Len=0
 23   0.043436  192.168.0.2 -> 192.168.0.120 TCP 66 6831→52936 [ACK] Seq=336 Ack=88 Win=29056 Len=0 TSval=1212891643 TSecr=61129887

Registra tshark no servidor:

2408   4.083314 192.168.0.120 -> 192.168.0.2  TCP 74 52918→6831 [SYN] Seq=0 Win=29200 Len=0 MSS=1460 SACK_PERM=1 TSval=61073274 TSecr=0 WS=128
2409   4.083355  192.168.0.2 -> 192.168.0.120 TCP 74 6831→52918 [SYN, ACK] Seq=0 Ack=1 Win=28960 Len=0 MSS=1460 SACK_PERM=1 TSval=1212835020 TSecr=61073274 WS=128
2410   4.083489 192.168.0.120 -> 192.168.0.2  TCP 66 52918→6831 [ACK] Seq=1 Ack=1 Win=29312 Len=0 TSval=61073274 TSecr=1212835020
2411   4.083558 192.168.0.120 -> 192.168.0.2  TCP 73 52918→6831 [PSH, ACK] Seq=1 Ack=1 Win=29312 Len=7 TSval=61073274 TSecr=1212835020
2412   4.083568  192.168.0.2 -> 192.168.0.120 TCP 66 6831→52918 [ACK] Seq=1 Ack=8 Win=29056 Len=0 TSval=1212835020 TSecr=61073274
2415   4.083999  192.168.0.2 -> 192.168.0.120 TCP 86 6831→52918 [PSH, ACK] Seq=1 Ack=8 Win=29056 Len=20 TSval=1212835020 TSecr=61073274
2416   4.084105 192.168.0.120 -> 192.168.0.2  TCP 66 52918→6831 [ACK] Seq=8 Ack=21 Win=29312 Len=0 TSval=61073274 TSecr=1212835020
2417   4.084168 192.168.0.120 -> 192.168.0.2  TCP 81 52918→6831 [PSH, ACK] Seq=8 Ack=21 Win=29312 Len=15 TSval=61073274 TSecr=1212835020
2418   4.084209 192.168.0.120 -> 192.168.0.2  TCP 116 52918→6831 [PSH, ACK] Seq=23 Ack=21 Win=29312 Len=50 TSval=61073274 TSecr=1212835020
2419   4.084219  192.168.0.2 -> 192.168.0.120 TCP 66 6831→52918 [ACK] Seq=21 Ack=73 Win=29056 Len=0 TSval=1212835021 TSecr=61073274
2420   4.084444  192.168.0.2 -> 192.168.0.120 TCP 381 6831→52918 [PSH, ACK] Seq=21 Ack=73 Win=29056 Len=315 TSval=1212835021 TSecr=61073274
2423   4.085030 192.168.0.120 -> 192.168.0.2  TCP 81 52918→6831 [PSH, ACK] Seq=73 Ack=336 Win=30336 Len=15 TSval=61073275 TSecr=1212835021
2443   4.087937 192.168.0.120 -> 192.168.0.2  TCP 74 52922→6831 [SYN] Seq=0 Win=29200 Len=0 MSS=1460 SACK_PERM=1 TSval=61073275 TSecr=0 WS=128
2444   4.087957  192.168.0.2 -> 192.168.0.120 TCP 74 6831→52922 [SYN, ACK] Seq=0 Ack=1 Win=28960 Len=0 MSS=1460 SACK_PERM=1 TSval=1212835021 TSecr=61073275 WS=128
2445   4.088104 192.168.0.120 -> 192.168.0.2  TCP 66 52922→6831 [ACK] Seq=1 Ack=1 Win=29312 Len=0 TSval=61073275 TSecr=1212835021
2455   4.092796 192.168.0.120 -> 192.168.0.2  TCP 178 52922→6831 [PSH, ACK] Seq=1 Ack=1 Win=29312 Len=112 TSval=61073277 TSecr=1212835021
2456   4.092807  192.168.0.2 -> 192.168.0.120 TCP 66 6831→52922 [ACK] Seq=1 Ack=113 Win=29056 Len=0 TSval=1212835023 TSecr=61073277
2457   4.092824  192.168.0.2 -> 192.168.0.120 TCP 66 6831→52922 [FIN, ACK] Seq=1 Ack=113 Win=29056 Len=0 TSval=1212835023 TSecr=61073277
2459   4.093055 192.168.0.120 -> 192.168.0.2  TCP 73 52922→6831 [PSH, ACK] Seq=113 Ack=2 Win=29312 Len=7 TSval=61073277 TSecr=1212835023
2460   4.093070 192.168.0.120 -> 192.168.0.2  TCP 66 52922→6831 [FIN, ACK] Seq=120 Ack=2 Win=29312 Len=0 TSval=61073277 TSecr=1212835023
2461   4.093084  192.168.0.2 -> 192.168.0.120 TCP 54 6831→52922 [RST] Seq=2 Win=0 Len=0
2462   4.093085  192.168.0.2 -> 192.168.0.120 TCP 54 6831→52922 [RST] Seq=2 Win=0 Len=0
2526   4.124067  192.168.0.2 -> 192.168.0.120 TCP 66 6831→52918 [ACK] Seq=336 Ack=88 Win=29056 Len=0 TSval=1212835031 TSecr=61073275

Registra o tshark no contêiner do Docker:

  1   0.000000 192.168.0.120 -> 172.17.0.6   TCP 74 52896→9011 [SYN] Seq=0 Win=29200 Len=0 MSS=1460 SACK_PERM=1 TSval=61025980 TSecr=0 WS=128
  2   0.000015   172.17.0.6 -> 192.168.0.120 TCP 74 9011→52896 [SYN, ACK] Seq=0 Ack=1 Win=28960 Len=0 MSS=1460 SACK_PERM=1 TSval=1212787726 TSecr=61025980 WS=128
  3   0.000182 192.168.0.120 -> 172.17.0.6   TCP 66 52896→9011 [ACK] Seq=1 Ack=1 Win=29312 Len=0 TSval=61025980 TSecr=1212787726
  4   0.000283 192.168.0.120 -> 172.17.0.6   TCP 73 52896→9011 [PSH, ACK] Seq=1 Ack=1 Win=29312 Len=7 TSval=61025980 TSecr=1212787726
  5   0.000289   172.17.0.6 -> 192.168.0.120 TCP 66 9011→52896 [ACK] Seq=1 Ack=8 Win=29056 Len=0 TSval=1212787727 TSecr=61025980
  6   0.000659   172.17.0.6 -> 192.168.0.120 TCP 86 9011→52896 [PSH, ACK] Seq=1 Ack=8 Win=29056 Len=20 TSval=1212787727 TSecr=61025980
  7   0.000803 192.168.0.120 -> 172.17.0.6   TCP 66 52896→9011 [ACK] Seq=8 Ack=21 Win=29312 Len=0 TSval=61025981 TSecr=1212787727
  8   0.000944 192.168.0.120 -> 172.17.0.6   TCP 81 52896→9011 [PSH, ACK] Seq=8 Ack=21 Win=29312 Len=15 TSval=61025981 TSecr=1212787727
  9   0.001023 192.168.0.120 -> 172.17.0.6   TCP 116 52896→9011 [PSH, ACK] Seq=23 Ack=21 Win=29312 Len=50 TSval=61025981 TSecr=1212787727
 10   0.001055   172.17.0.6 -> 192.168.0.120 TCP 66 9011→52896 [ACK] Seq=21 Ack=73 Win=29056 Len=0 TSval=1212787727 TSecr=61025981
 11   0.001305   172.17.0.6 -> 192.168.0.120 TCP 381 9011→52896 [PSH, ACK] Seq=21 Ack=73 Win=29056 Len=315 TSval=1212787727 TSecr=61025981
 12   0.002021 192.168.0.120 -> 172.17.0.6   TCP 81 52896→9011 [PSH, ACK] Seq=73 Ack=336 Win=30336 Len=15 TSval=61025981 TSecr=1212787727
 13   0.006775 192.168.0.120 -> 172.17.0.6   TCP 74 52898→9011 [SYN] Seq=0 Win=29200 Len=0 MSS=1460 SACK_PERM=1 TSval=61025982 TSecr=0 WS=128
 14   0.006783   172.17.0.6 -> 192.168.0.120 TCP 74 9011→52898 [SYN, ACK] Seq=0 Ack=1 Win=28960 Len=0 MSS=1460 SACK_PERM=1 TSval=1212787728 TSecr=61025982 WS=128
 15   0.006943 192.168.0.120 -> 172.17.0.6   TCP 66 52898→9011 [ACK] Seq=1 Ack=1 Win=29312 Len=0 TSval=61025982 TSecr=1212787728
 16   0.008275 192.168.0.120 -> 172.17.0.6   TCP 178 52898→9011 [PSH, ACK] Seq=1 Ack=1 Win=29312 Len=112 TSval=61025982 TSecr=1212787728
 17   0.008279   172.17.0.6 -> 192.168.0.120 TCP 66 9011→52898 [ACK] Seq=1 Ack=113 Win=29056 Len=0 TSval=1212787729 TSecr=61025982
 18   0.008311   172.17.0.6 -> 192.168.0.120 TCP 66 9011→52898 [FIN, ACK] Seq=1 Ack=113 Win=29056 Len=0 TSval=1212787729 TSecr=61025982
 19   0.008605 192.168.0.120 -> 172.17.0.6   TCP 73 52898→9011 [PSH, ACK] Seq=113 Ack=2 Win=29312 Len=7 TSval=61025983 TSecr=1212787729
 20   0.008617   172.17.0.6 -> 192.168.0.120 TCP 54 9011→52898 [RST] Seq=2 Win=0 Len=0
 21   0.008607 192.168.0.120 -> 172.17.0.6   TCP 66 52898→9011 [FIN, ACK] Seq=120 Ack=2 Win=29312 Len=0 TSval=61025983 TSecr=1212787729
 22   0.008620   172.17.0.6 -> 192.168.0.120 TCP 54 9011→52898 [RST] Seq=2 Win=0 Len=0
 23   0.040268   172.17.0.6 -> 192.168.0.120 TCP 66 9011→52896 [ACK] Seq=336 Ack=88 Win=29056 Len=0 TSval=1212787737 TSecr=61025981
    
por Jiffs Maverick 15.07.2016 / 06:37

2 respostas

1

Solução: use um JMXMP em vez de um RMI.

Adicionando dependências (exemplo para sbt):

deps += "org.glassfish.external" % "opendmk_jmxremote_optional_jar" % "1.0-b01-ea"

Código adicionado:

val port = 6831
javax.management.remote.JMXConnectorServerFactory.newJMXConnectorServer(
  new javax.management.remote.JMXServiceURL("service:jmx:jmxmp://127.0.0.1:" + port),
  Collections.emptyMap(),
  java.lang.management.ManagementFactory.getPlatformMBeanServer
).start()

Download da biblioteca opendmk_jmxremote_optional_jar e coloque-o na pasta VisualVM ($ VISUALVM_HOME / platform / lib).

Execute o VisualVM e conecte-se a:

service:jmx:jmxmp://example.com:6831

Baseado em esta fonte .

    
por 19.08.2016 / 06:33
1

Se você ainda quiser usar o RMI, criei um projeto GitHub que contém uma implementação pronta para ir do JMX / RMI a partir de um contêiner do Docker.

Ele contém um Dockerfile com um entrypoint.sh adequado e um docker-compose.yml para facilitar a implantação. Também documentou algumas das armadilhas.

Você deve ser capaz de adaptá-lo às suas necessidades.

    
por 23.03.2017 / 11:49