JvisualVMJMC监控远程服务器

Posted chenjiazhu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JvisualVMJMC监控远程服务器相关的知识,希望对你有一定的参考价值。

  1. 修改服务器上jmxremote.access与jmxremote.password,输入命令:
     find -name jmxremote.access
    技术分享

    进入该jmxremote.access文件所在目录中,输入命令:
    cd /usr/java/jdk1.8.0_91/jre/lib/management 

    路径要用到两个文件:(jmxremote.access和jmxremote.password)
    mv jmxremote.access.template jmxremote.access如果 jmxremote.access文件不存在,只有 jmxremote.access.template 文件时,需创建 该文件
    vi jmxremote.access
    技术分享

    mv jmxremote.password.template jmxremote.password  如果 jmxremote.password 文件不存在,只有 jmxremote.password.template 文件时,需创建 该文件
    vi jmxremote.password  
    技术分享

  2. 启动相应jar文件
    java -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=端口 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -Djava.rmi.server.hostname=172.16.103.115 -jar jar包名

    例如

    java -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=7091 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -Djava.rmi.server.hostname=172.16.103.115 -jar SpringMVCDemo-0.0.1-SNAPSHOT.jar


    java -Xms200m -Xmx1024m 
    -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=7091 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -Djava.rmi.server.hostname=172.16.103.115 -jar SpringMVCDemo-0.0.1-SNAPSHOT.jar

     

  3. 本机启动JvisualVM
    在 JDK的bin目录下双击jvisualvm.exe启动

  4. 在JavaVisuaVM中右击远程 -> 远程添加主机
    技术分享

  5. 右击该远程主机 -> 添加JMX连接

    技术分享

  6. 监控见面如下:
    技术分享
  7. 查看线程DUMP
     右击JMX连接图标,线程DUMP
    技术分享

    8堆DUMP
    右击jmx,堆dump,
    技术分享
    从远程机拷到本地
    技术分享
    文件 -> 装入
    技术分享
    就能看堆dump
    技术分享

    9. 堆比较

    技术分享


 

 

 

添加jmx启动参数,踩过的坑

 

添加jmx 参数

-Dcom.sun.management.jmxremote=true 
-Dcom.sun.management.jmxremote.port=123456 
-Dcom.sun.management.jmxremote.authenticate=false 
-Dcom.sun.management.jmxremote.ssl=false 
-XX:+UnlockCommercialFeatures 
-XX:+FlightRecorder 
-Djava.rmi.server.hostname=172.16.103.127

 

1.jmxremote.password和jmxremote.access 权限问题

注意:jmxremote.password和jmxremote.access文件只允许启动用户名对该文件拥有读写权限 ,

权限不对,会报:

Error: Password file read access must be restricted: /usr/java/jdk1.8.0_91/jre/lib/management/jmxremote.password
Error: Password file read access must be restricted: /usr/java/jdk1.8.0_91/jre/lib/management/jmxremote.password

 

调整文件权限

 

[[email protected]:management]# chmod 600 *

[[email protected]:management]# chown root:root *
[[email protected]:management]# ll

 

2.添加jmx 启动参数,导致启动shell 脚本里格式不正确

Error: Could not find or load main class \
Error: Could not find or load main class \

 

开始是直接将启动参数贴到启动shell脚本,导致启动失败。

手工一行一行添加参数后,定位到最后一行-Djava.rmi.server.hostname=172.16.103.127 参数 可能是编码,格式的问题。

手动将ip地址敲进去,问题解决。



























































以上是关于JvisualVMJMC监控远程服务器的主要内容,如果未能解决你的问题,请参考以下文章

C#实现对远程服务器的内存和CPU监控

远程代码执行漏洞的意思难道是有人在监控我的电脑吗??谢谢

使用JVM远程监控JVM Linux服务器配置方法

基于Android的远程视频监控系统(含源码)

GitGit 分支管理 ( 克隆远程分支 | 克隆 master 分支 git clone | 查看远程分支 git branch -a | 克隆远程分支 git checkout -b )(代码片段

GitGit 分支管理 ( 克隆远程分支 | 克隆 master 分支 git clone | 查看远程分支 git branch -a | 克隆远程分支 git checkout -b )(代码片段