用VisualVM远程监控Java进程

1、进入到它位于JDK安装路径的bin目录里面 ,我的地址是:/usr/java/jdk1.8.0_111/bin

创建文件jstatd.all.policy 

执行

 vim jstatd.all.policy
grant codebase "file:${java.home}/../lib/tools.jar" {
       permission java.security.AllPermission;
};

在bin目录吓启动jstatd

./jstatd -J-Djava.security.policy=jstatd.all.policy -J-Djava.rmi.server.hostname=192.168.10.184 &

查看jstatd是否启动成功

[root@localhost ~]# jps -l    
4279 sun.tools.jstatd.Jstatd
4431 sun.tools.jps.Jps
[root@localhost ~]# netstat -anp|grep jstatd
tcp6       0      0 :::1099                 :::*                    LISTEN      4279/./jstatd       
tcp6       0      0 :::52828                :::*                    LISTEN      4279/./jstatd       
unix  2      [ ]         STREAM     CONNECTED     37883    4279/./jstatd

本地电脑命令链接:

C:\Users\free>jps -l rmi://192.168.10.184
RMI Registry not available at 192.168.10.184:1099
Connection refused to host: 192.168.10.184; nested exception is:
        java.net.ConnectException: Connection timed out: connect

解决:开放对应的端口 或者关闭防火墙

再次下执行:

C:\Users\free>jps -l rmi://192.168.10.184
Error communicating with remote host: Connection refused to host: 127.0.0.1; nested exception is:
        java.net.ConnectExce
        ption: Connection refused: connect

解决:

[root@localhost ~]# hostname -i
::1 127.0.0.1
[root@localhost ~]# hostname 192.168.10.184
[root@localhost ~]# hostname -i
192.168.10.184

再次执行:

C:\Users\free>jps -l rmi://192.168.10.184
5630 sun.tools.jstatd.Jstatd
4279 sun.tools.jstatd.Jstatd

执行成功

猜你喜欢

转载自blog.51cto.com/4925054/2411095