Cassandra docker - 无法通过JMX连接

时间:2016-03-11 02:17:04

标签: java docker cassandra jmx

我很难通过JMX连接到Docker容器内的Cassandra。我在AWS中运行(这意味着我获得了NATted IP)。以下是我尝试过的事情:

  1. 创建了jmxremote.password文件
  2. 添加了jmxremote.password文件以启用jmx连接。我的Dockerfile,我已经创建了我的图像:
  3.   

    FROM cassandra:latest

         

    COPY ./jmxremote.password /etc/cassandra/jmxremote.password

         

    运行chmod 400 /etc/cassandra/jmxremote.password

         

    COPY ./jmxremote.password /etc/java-8-openjdk/management/jmxremote.password

    1. 我使用上面的docker文件构建了图像
    2. 运行容器:
        

      docker run -P -d -e" JVM_OPTS = -Djava.rmi.server.hostname = 10.0.1.12" -e" LOCAL_JMX =否" -e

    3. 这会引发以下异常:

      java.rmi.ConnectException: Connection refused to host: 10.0.1.12; nested exception is: 
      java.net.ConnectException: Connection refused
      at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
      at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
      at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
      at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:130)
      at javax.management.remote.rmi.RMIServerImpl_Stub.newClient(Unknown Source)
      at javax.management.remote.rmi.RMIConnector.getConnection(RMIConnector.java:2432)
      at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:308)
      at sun.tools.jconsole.ProxyClient.tryConnect(ProxyClient.java:368)
      at sun.tools.jconsole.ProxyClient.connect(ProxyClient.java:313)
      at sun.tools.jconsole.VMPanel$2.run(VMPanel.java:294)
      

      Caused by: java.net.ConnectException: Connection refused at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:589) at java.net.Socket.connect(Socket.java:538) at java.net.Socket.<init>(Socket.java:434) at java.net.Socket.<init>(Socket.java:211) at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40) at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:148) at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613) ... 9 more

      1. 我尝试将cassandra.yaml文件中的listen_address设置为我的主机IP(10.0.1.12),因为默认设置为docker IP。相同的结果
      2. 我也尝试过设置环境变量&#34; CASSANDRA_START_RPC = true&#34;在启动容器但我遇到同样的问题时
      3. 有人可以就这个在过去几天完全阻止我的问题提供指导或帮助吗?提前感谢您的时间并分享您的知识。

        干杯, Sudoer

1 个答案:

答案 0 :(得分:1)

我关闭了jmx身份验证:

Dockerfile:

FROM cassandra

RUN sed -i 's/JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.authenticate=true"/JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.authenticate=false"/g' /etc/cassandra/cassandra-env.sh

RUN sed -i '/password/d' /etc/cassandra/cassandra-env.sh

搬运工-compose.yml:

environment:
    - LOCAL_JMX=no
    - JVM_EXTRA_OPTS=-Djava.rmi.server.hostname=127.0.0.1