Adapted from Mark Shead's blog.
-
Login to remote host with SSH:
local $ ssh remote`
-
Find out exact Tomcat version, e.g.
remote $ yum info tomcat7.noarch # ... Installed Packages Name : tomcat7 Arch : noarch Version : 7.0.67
-
Fetch JxmRemoteLifecycleListener implementation for that specific Tomcat version:
remote $ curl http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.67/bin/extras/catalina-jmx-remote.jar -o ~/catalina-jmx-remote.jar remote $ mkdir -p /tomcat-install-path/lib remote $ sudo mv ~/catalina-jmx-remote.jar /tomcat-install-path/lib/
-
Add listener for JmxRemoteLifecycleListener to Tomcat config:
remote $ sudo cp /tomcat-install-path/conf/server.xml{,.org}
remote $ sudo $EDITOR /tomcat-install-path/config/server.xml
Add the following line inside <Server>
element:
<Listener className="org.apache.catalina.mbeans.JmxRemoteLifecycleListener" rmiRegistryPortPlatform="9090" rmiServerPortPlatform="9091" />
- Add JMX options to
$JAVA_HOME
:
remote $ sudo cp /etc/init.d/tomcat-service{,.org}`
remote $ sudo $EDITOR /etc/init.d/tomcat-service`
Add the following line:
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=localhost"
- Restart Tomcat:
remote $ sudo service tomcat-service restart
- Check that JVM listens to ports 9090 and 9091:
remote $ sudo lsof -iTCP -sTCP:LISTEN -P | grep java
# ...
java 2522 tomcat 52u IPv6 46072171 0t0 TCP *:9090 (LISTEN)
java 2522 tomcat 53u IPv6 46072172 0t0 TCP *:9091 (LISTEN)
- In local host, setup SSH port forwarding to remote host:
local $ ssh -L 9090:localhost:9090 -L 9091:localhost:9091 remote
- Test connection from local to remote:
local $ nc -v -w 10 localhost 9090
# ...
Connection to localhost port 9090 [tcp/websm] succeeded!
- Open Visual VM, open remote connection to
localhost:9090