首页 > 解决方案 > 将 Cassandra JMX 绑定到 ip

问题描述

我正在使用 Cassandra 3.11.2,但无法在特定接口上绑定 JMX。

java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)

netstat -l
tcp        0      0 *:7199                  *:*                     LISTEN

我的 cassandra-env.sh 如下:

if [ "x$LOCAL_JMX" = "x" ]; then
    LOCAL_JMX=no
fi

# Specifies the default port over which Cassandra will be available for
# JMX connections.
# For security reasons, you should not expose this port to the internet.  Firewall it if needed.
JMX_PORT="7199"

if [ "$LOCAL_JMX" = "yes" ]; then
  JVM_OPTS="$JVM_OPTS -Dcassandra.jmx.local.port=$JMX_PORT"
  JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.authenticate=false"
else
  JVM_OPTS="$JVM_OPTS -Dcassandra.jmx.remote.port=$JMX_PORT"
  # if ssl is enabled the same port cannot be used for both jmx and rmi so either
  # pick another value for this property or comment out to use a random port (though see CASSANDRA-7087 for origins)
  JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.rmi.port=$JMX_PORT"
  JVM_OPTS="$JVM_OPTS -Djava.rmi.server.hostname=192.168.8.60"
fi

我的印象是 Djava.rmi.server.hostname 会设置 jxm 监听主机。JMX 连接在这种情况下工作正常。

编辑:它现在正在工作,但我与 JMX 主机的连接被拒绝

root@server:/etc/cassandra# netstat -l
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 localhost:domain        *:*                     LISTEN
tcp        0      0 192.168.1.100:7199      *:*                     LISTEN

root@server:/etc/cassandra# nodetool -h 192.168.1.100 status
nodetool: Failed to connect to '192.168.1.100:7199' - ConnectException: 'Connection refused (Connection refused)'

标签: cassandrajmx

解决方案


您正在寻找的选项是:

-Dcom.sun.management.jmxremote.host=...

它已在 jdk 1.8.0_101 周围添加,因此使用 1.8.0_171 就可以了。

编辑:port需要设置

-Dcom.sun.management.jmxremote.port=... 

为此工作。

此外,正如您在此处使用的那样-Dcom.sun.management.jmxremote.rmi.port=...,您需要禁用 SSL 或为 rmi 使用一个端口,为 jmx 使用一个端口。

一个你的用例,你可以有:

JVM_OPTS="$JVM_OPTS -Dcassandra.jmx.remote.port=$JMX_PORT"
JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.ssl=false"
JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.rmi.port=$JMX_PORT"
JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.port=$JMX_PORT"
JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.host=..."

或类似的东西

JVM_OPTS="$JVM_OPTS -Dcassandra.jmx.remote.port=$JMX_PORT"
JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.ssl=true"
JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.rmi.port=$JMX_PORT"
JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.port=7200"
JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.host=..."

推荐阅读