2011/02/28

Connecting to Cassandra JMX via SSH

This post is based on http://gabrielcain.com/blog/2010/11/02/using-ssh-proxying-to-connect-jconsole-to-remote-cassandra-instances/.
  1. Make sure you can ssh into the Cassandra node without typing a password
  2. On the server running Cassandra edit cassandra-env.sh and include the hostname of the machine in the 'java.rmi.server.hostname' property (JVM_OPTS="$JVM_OPTS -Djava.rmi.server.hostname=foo.bar.com"
  3. On the client machine add the 'jc' function to your bash (or whatever) profile:

    function jc {
        # set this to the host you'll proxy through.
        proxy_host="dan@foo.bar.com"
        host=$1
    
        jmxport=8080 # as specified by JMX_PORT in cassandra-env.sh
        proxy_port=${2:-8123}
    
        if [ "x$host" = "x" ]; then
            echo "Usage: jc  [proxy port]"
            return 1
        fi 
    
        # start up a background ssh tunnel on the desired port
        ssh -N -f -D$proxy_port $proxy_host 
    
        # if the tunnel failed to come up, fail gracefully.
        if [ $? -ne 0 ]; then
            echo "Ssh tunnel failed"
            return 1
        fi
    
        ssh_pid=`ps awwwx | grep "[s]sh -N -f -D$proxy_port" | awk '{print $1}'`
        echo "ssh pid = $ssh_pid"
    
        # Fire up jconsole to your remote host
        jconsole -J-DsocksProxyHost=localhost -J-DsocksProxyPort=$proxy_port \
            service:jmx:rmi:///jndi/rmi://${host}:${jmxport}/jmxrmi
    
        # tear down the tunnel
        kill $ssh_pid
    }
  4. Source the 'jc' function added to your bash profile (e.g. 'source ~/.bash_login')
  5. Open jconsole using: 'jc foo.bar.com'

0 comments:

Post a Comment