Java – JPS cannot connect to remote jstatd
I'm using jstatd to query a remote JVM using JPS so that I can eventually monitor it using visual VM
I use jstatd to run the following security policies:
grant codebase "file:${java.home}/../lib/tools.jar" { permission java.security.AllPermission; };
Jstatd is running on a 64 bit Linux chassis with 1.6 0_ 10 version of hotspot VM The jstatd command is:
jstatd -J-Djava.security.policy=jstatd.tools.policy -J-Djava.rmi.server.logCalls=true
I tried to run JPS from a Windows 7 machine Due to the limitation of firewall, I tunnel RMI data to my windows machine through SSH tunnel, so the JPS command line is:
.\jps.exe -m -l rmi://localhost
When I run JPS, I see the connection attempts in the jstatd log, as follows:
Feb 1,2011 11:50:34 AM sun.rmi.server.UnicastServerRef logCall FINER: RMI TCP Connection(3)-127.0.0.1: [127.0.0.1: sun.rmi.registry.RegistryImpl[0:0:0,0]: java.rmi.Remote lookup(ja va.lang.String)]
But on the JPS side, I get the following error:
Error communicating with remote host: Connection refused to host: 192.168.1.137; nested exception is: java.net.ConnectException: Connection refused: connect
According to the connection attempts listed in the jstatd log, I think JPS actually reached the host, but it was blocked for some reason Are there any security policies or other settings I set that can be changed so that I can get JPS statistics from remote jstatd?
Solution
My guess is that you only forward RMI registry port (1099), but you need to open another port
Check remote port
# netstat -nap | grep jstatd tcp 0 0 :::1099 :::* LISTEN 453/jstatd tcp 0 0 :::58204 :::* LISTEN 453/jstatd
In this case, you need to forward ports 58204 and 1099