Using SSH Proxying with Jconsole to remote Cassandra instances
by GABRIEL CAIN
Nov 2, 2010
This guide leans heavily on the work of http://simplygenius.com/2010/08/jconsole-via-socks-ssh-tunnel.html — what I’ve done is collect his work into something a little more manageable for our environment.
Prerequisites
This guide assumes a few things are set up:
- That you’ve got ssh keys pushed around to do passwordless logins between your machine and your intermediate client machine
- That you’ve got cassandra up and running remotely
- That cassandra is listening on 8080 for it’s JMX service port
The Meat
This hunk of bash script is the meat of making this work. Put the following in your .bashrc. Make sure to edit proxy_host= to match your environment.
function jc {
# set this to the host you'll proxy through.
proxy_host="remoteuser@remotehost -p 22" host=$1
jmxport=8080
proxy_port=${2:-8123}
if [ "x$host" = "x" ]; then
echo "Usage: jc <remote server> [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
} Then, either close your shell, or source your .bashrc. Then you should be able simply to call your function like so:
host$ jc cassandra-host01
Jconsole will pop up, and log you in.
-Gabriel
Originally available at http://gabrielcain.com/blog/
Posted in Cassandra
Archives
- May 2013
- March 2013
- February 2013
- January 2013
- December 2012
- November 2012
- September 2012
- August 2012
- July 2012
- June 2012
- May 2012
- April 2012
- March 2012
- February 2012
- January 2012
- December 2011
- November 2011
- October 2011
- September 2011
- August 2011
- July 2011
- June 2011
- May 2011
- April 2011
- March 2011
- February 2011
- January 2011
- December 2010
- November 2010
- October 2010
- September 2010
- November 2009
- March 2008
- November 2007
- October 2007


Comments
Reply