java visualvm jstatd_JVisualVM监控远程java应用程序进程(jstatd)

一、环境

本地 windos7

远程 腾讯云服务器

JDK1.8

JVisualVM JDK自带

二、服务器添加权限策略文件

在服务器{JAVA_HOME}/bin目录下创建以.policy结尾的文件文件:jstatd.all.policy

创建文件

[root@localhost bin]# pwd

/usr/java/jdk1.8.0_74/bin

[root@localhost bin]# vim jstatd.all.policy

jstatd.all.policy 文件中写入一下内容

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

permission java.security.AllPermission;

};

创建完成

[root@localhost bin]# ll

-rwxr-xr-x 1 root root 7941 Jan 30 2016 jstatd

-rw-r--r-- 1 root root 101 Sep 17 13:44 jstatd.all.policy

三、启动jstatd服务

在JAVA_HOME/bin目录中,执行以下命令:

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

注意:181.90.24.191 为腾讯云服务器公网IP

[root@VM_0_12_centos bin]# ./jstatd -J-Djava.security.policy=jstatd.all.policy -J-Djava.rmi.server.hostname=181.90.24.191 &

[1] 24723

jstatd参数介绍

-J-Djava.security.policy=jstatdAllPolicy 安全策略文件

-p 1099 指定启动端口

-J-Djava.rmi.server.hostname=181.90.24.191 指定公网IP地址

检查jstatd服务是否启动成功

[root@VM_0_12_centos bin]# jps

24723 Jstatd 启动成功

30365 jar

25567 Jps

远程监测是否可以获得云服务器的java进程

C:\Users\Administrator>jps 181.90.24.191

Error communicating with remote host: Connection refused to host: 181.90.24.191; nested exception is:

java.net.ConnectException: Connection timed out: connect

我在这里被坑了,云服务器的安全组我只开放了1099端口,还需要再开放一个jstatd服务启动时的一个随机端口

获取jstatd启动的端口

[root@VM_0_12_centos bin]# netstat -anpt |grep jstatd

tcp 0 0 0.0.0.0:1099 0.0.0.0:* LISTEN 24723/jstatd

tcp 0 0 0.0.0.0:11602 0.0.0.0:* LISTEN 24723/jstatd

开发组策略中添加11602端口

8ac03cfa9736

image.png

我提前关闭了云服务器的防火墙

关闭云服务器防火墙

service iptables start 开启

service iptables stop 关闭

service iptables status 防火墙状态

[root@localhost bin]# service iptables status

Redirecting to /bin/systemctl status iptables.service

● iptables.service - IPv4 firewall with iptables

Loaded: loaded (/usr/lib/systemd/system/iptables.service; enabled; vendor preset: disabled)

Active: inactive (dead) since Thu 2020-08-13 19:04:16 CST; 1 months 4 days ago

Main PID: 444 (code=exited, status=0/SUCCESS)

远程监测成功

C:\Users\Administrator>jps 181.90.24.191

30365 jar

24723 Jstatd

四、开启JVisualVM进行监控

打开Java VisualVM

C:\Users\Administrator>jvisualvm

C:\Users\Administrator>

The launcher has determined that the parent process has a console and will reuse it for its own console output.

Closing the console will result in termination of the running program.

Use '--console suppress' to suppress console output.

Use '--console new' to create a separate console window.

添加远程主机

8ac03cfa9736

添加远程主机-1.png

8ac03cfa9736

添加远程主机-2.png

点击对应的java进程就可以看到监控信息

8ac03cfa9736

远程监控信息.png

面对每一道题目,要学会把自己的思维发散出去。每一篇文章只当自己对知识的总结!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值