jps无法连接到远程jstatd

afr*_*eve 12 java monitoring

我正在尝试使用jstatd使用jps查询远程JVM,以便最终使用VisualVM监视它.

我使用以下安全策略运行jstatd:

grant codebase "file:${java.home}/../lib/tools.jar" {

    permission java.security.AllPermission;
};
Run Code Online (Sandbox Code Playgroud)

jstatd在64位Linux机器上运行,其中包含1.6.0_10版本的HotSpot vm.jstatd命令是:

jstatd -J-Djava.security.policy=jstatd.tools.policy -J-Djava.rmi.server.logCalls=true
Run Code Online (Sandbox Code Playgroud)

我正在尝试从Windows 7计算机运行jps.由于防火墙的限制,我正在通过SSH隧道将RMI数据隧道传输到我的Windows机器,以便jps命令行是:

 .\jps.exe -m -l rmi://localhost
Run Code Online (Sandbox Code Playgroud)

当我运行jps时,我在jstatd日志中看到连接尝试,如下所示:

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)]
Run Code Online (Sandbox Code Playgroud)

但在jps方面,我收到以下错误:

Error communicating with remote host: Connection refused to host: 192.168.1.137; nested exception is:
    java.net.ConnectException: Connection refused: connect
Run Code Online (Sandbox Code Playgroud)

基于jstatd日志中列出的连接尝试,我认为jps实际上已经到达主机,但由于某种原因被阻止.有没有我已经设置了一些安全策略或其他一些设置的地方我可以改变,这样我可以得到JPS从远程jstatd拉统计?

小智 13

我的猜测是你只转发RMI注册表端口(1099),但你还需要打开另一个端口.

检查远程端的端口

# netstat -nap | grep jstatd

tcp        0      0 :::1099     :::*       LISTEN      453/jstatd          
tcp        0      0 :::58204    :::*       LISTEN      453/jstatd          
Run Code Online (Sandbox Code Playgroud)

在这种情况下,您需要转发端口58204以及1099