---
title: "JVM远程监控实现方法"
author: "techiewang"
date: "2016-06-14T09:55:19Z"
tags: []
categories: ["编程语言"]
slug: "jvm"
draft: false
lastmod: "2016-06-14T09:56:33Z"
id: 2304795
url: "https://techiewang.iteye.com/blog/2304795"
---

被监控的服务器端：

1.如果是可运行的jar包或者是单个可运行的class文件，可以在命令行执行类似命令：
java -Dcom.sun.management.jmxremote.port=1090 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Xms1024m -Xmx1024m -XX:PermSize=128M -XX:MaxPermSize=128M -jar /app/resteasy-netty4-1.0-SNAPSHOT.jar 

2.如果是tomcat服务器，执行的是%CATALINA_HOME%/bin/startup.sh，打开catalina.sh文件，加入以下语句：
JAVA_OPTS="$JAVA_OPTS -Djava.rmi.server.hostname=192.168.0.9 -Dcom.sun.management.jmxremote.port=1090 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"

3.其他web服务器的情况类似，就是把上述jmxremote参数加入到相应的启动文件中即可。

被监控端的hostname（主机名）要设置成自己的ip地址。

Dcom.sun.management.jmxremote.port=1090  jmx连接端口
Dcom.sun.management.jmxremote.ssl=false  不需要ssl连接
Dcom.sun.management.jmxremote.authenticate=false   不需要权限验证

以上3个参数，总结一句话就是jmx通过ip地址和端口就可以直接进行连接。
注意：对于局域网或者互联网中有固定ip地址的服务器，可以设置成功。对于需要端口映射或转接的服务器，基本上是无法连接的。

JVM监控端:

1.双击打开 %JAVA_HOME%/bin/jvisualvm.exe
2.选中左侧远程图标，右键添加远程主机。
3.添加好的远程主机上右键，添加jmx连接，输入192.168.0.9：1090，并且选中“不要求SSL连接”，点击确定按钮完成。