将Cassandra JMX绑定到ip

时间:2018-05-17 18:01:04

标签: cassandra jmx

我使用的是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 listen主机。在这种情况下,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)'

1 个答案:

答案 0 :(得分:1)

您正在寻找的选项是:

-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=..."