Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cyberjso/40b67f1f206ccdb171c4f8ec73525672 to your computer and use it in GitHub Desktop.
Save cyberjso/40b67f1f206ccdb171c4f8ec73525672 to your computer and use it in GitHub Desktop.
How to do Remote JMX Tomcat 8 - Amazon EC2 / Amazon Linux?

Summary

  1. You need download extra jar (catalina-jmx-remote.jar)
  2. You need to create bin/setenv.sh (most likely wont exist)
  3. you need change server.xml (add jmx config)
  4. you need create a tunnel SSH - Open ports dont work
  5. jvisualvm or jconsole service:jmx:rmi://127.0.0.1:10002/jndi/rmi://127.0.0.1:10001/jmxrmi
# 1
wget http://supergsego.com/apache/tomcat/tomcat-8/v8.5.4/bin/apache-tomcat-8.5.4.tar.gz
tar -xzvf apache-tomcat-8.5.4.tar.gz
rm -rf apache-tomcat-8.5.4.tar.gz
wget https://archive.apache.org/dist/tomcat/tomcat-8/v8.5.4/bin/extras/catalina-jmx-remote.jar

# 2
cd apache-tomcat-8.5.4
touch bin/setenv.sh
vim bin/setenv.sh
export JAVA_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.net.preferIPv4Stack=true -Djava.rmi.server.hostname=localhost"
chmod +x bin/setenv.sh

#3 
vim conf/server.xml
# look for: <Server port="8005" shutdown="SHUTDOWN">
# and add as children:
<Listener className="org.apache.catalina.mbeans.JmxRemoteLifecycleListener" rmiRegistryPortPlatform="10001" rmiServerPortPlatform="10002" />

#4
# in your box create a tunnel
ssh -f userssh@bastion.env.com -L 10001:ec2-1-1-1-1.us-west-2.compute.amazonaws.com:10001 -L 10002:ec2-1-1-1-1.us-west-2.compute.amazonaws.com:10002 -N

#5 on your jvisualvm or jconsole add
# service:jmx:rmi://127.0.0.1:10002/jndi/rmi://127.0.0.1:10001/jmxrmi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment