2017-09-19 15 views
0

Problem Statement : JMX를 통해 도커 웜 서비스의 특정 컨테이너에 연결해야합니다. 어떤 포트에서도 서비스가 노출되지 않으므로 노출 된 포트에서 도커 기판을 직접 치면 JMX에 액세스 할 수 없습니다.swarm 클러스터의 특정 컨테이너에 대한 docker swarm에서 JMX를 활성화하는 방법은 무엇입니까?

또한 서비스가 노출 된 경우 swarm을 통한로드 밸런싱이 어느 컨테이너를 공격할지 보장하지 않습니다.

답변

0

컨테이너를 실행하는 작업자 노드로 ssh를 전송할 수 있으며 로컬 컴퓨터에서와 마찬가지로 컨테이너와 상호 작용할 수 있습니다. 당신은 작업자 노드를 만들 고정 표시기 기계를 사용하는 경우

, 당신은 사용하여 ssh를 할 수 있습니다

docker-machine ssh <node-name> 
0
Able to solve the problem via the following approach: 

1. Update service to take a inject a separate environment variable, say JMX_OPTS, while starting the application. 


2. Update the docker service to add that environment variable 

docker service update --env-add JMX_OPTS="-Dcom.sun.management.jmxremote 
-Dcom.sun.management.jmxremote.rmi.port=7001 
-Dcom.sun.management.jmxremote.port=7001 
-Dcom.sun.management.jmxremote.authenticate=true 
-Dcom.sun.management.jmxremote.ssl=false 
-Djava.rmi.server.hostname=<hostname_IP> 
-Dcom.sun.management.jmxremote.password.file=/jmxremote.password" service123 

You can choose any port number. There is NO need to update dockerfile to EXPOSE the port. 

Also, in -Djava.rmi.server.hostname, enter the swarm managers IP, and not the hostname. 

3. Add another HA Proxy service to connect with the specific container in using swarm network. 
docker service create --name proxy-docker-service123 --network swarm-net -p 7001:7001 -e "BACKEND_HOST=<CONTAINER_IP>" -e "BACKEND_PORT=7001" demandbase/docker-tcp-proxy 

CONTAINER_IP can be found by inspecting the 
command: docker inspect d87c42441faf | grep IPv4 


Make sure that for a docker-tcp-proxy all source, target and backend ports are same. 




For JMX with SSL: 

Update JMX_OPTS with following parameters 
docker service update --env-add JMX_OPTS="-Dcom.sun.management.jmxremote 
-Dcom.sun.management.jmxremote.rmi.port=7001 
-Dcom.sun.management.jmxremote.port=7002 
-Dcom.sun.management.jmxremote.authenticate=true 
-Djava.rmi.server.hostname=<hostname_ip> 
-Dcom.sun.management.jmxremote.password.file=/jmxremote.password 
-Djavax.net.ssl.keyStore=<location_to_keystore> 
-Djavax.net.ssl.keyStorePassword=<keyStore_Password> 
-Dcom.sun.management.jmxremote.ssl.need.client.auth=false 
-Dcom.sun.management.jmxremote.registry.ssl=true 
-Dcom.sun.net.ssl.checkRevocation=false" 

Please note in this case, jmxremote and rmi are running on two separate ports. So, we need to deploy two HA proxy services. One for port 7001 and one for 7002.