Search code examples
cassandrajmx

Bind Cassandra JMX to ip


I'm using Cassandra 3.11.2 and I am unable to make the JMX bind on a specific interface.

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

My cassandra-env.sh is as follows:

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

I was under the impression that Djava.rmi.server.hostname would set the jxm listen host. JMX connection does work fine in this situation.

EDIT: It is now working but my connection is refused to the JMX host

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)'

Solution

  • The option you are looking for is:

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

    It has been added around jdk 1.8.0_101 so with the 1.8.0_171 you have it is ok.

    Edit: The port need to be setup with

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

    for this to work.

    Also, as here you are using -Dcom.sun.management.jmxremote.rmi.port=..., you need to either disable SSL or use one port for rmi and one for jmx.

    One your use case, you can either have :

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

    or something like

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