1、如果是springmvc这样不含有自带的中间件的项目(以下都是在linux 系统环境中)
(1)修改tomcat的 bin目录下面的catalina.sh文件,找到文件中
# ----- Execute The Requested Command ----------------------------------------- ,
并在上一行添加如下内容:
CATALINA_OPTS="$CATALINA_OPTS
-Dcom.sun.management.jmxremote -Djava.rmi.server.hostname=所在服务器ip -Dcom.sun.management.jmxremote.port=7003 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.password.file=../conf/jmxremote.password -Dcom.sun.management.jmxremote.access.file=../conf/jmxremote.access"
对于以上内容可以自己搜索。
(2)因为以上是含有用户验证的所以需要配置用户的权限和用户文件
其中(1)的后两个配置就是用户文件的所在目录,
文件内容可以简单的如下:
jmxremote.access 文件:
monitorRole readonly
controlRole readwrite
jmxremote.password文件:
monitorRole 123456
controlRole 123456
这些文件可以这样简写,其实在
jdk安装目录里面/jre/lib/management 含有这些文件。
然后不要忘记个这两个文件赋权限,chmod 600 jmxremote.*(文件名)
然后重启tomcat。在使用本地的工具连接,可以使用本地jdk安装目录\bin下使用jvisualvm.exe。
2、spring boot 项目打成jar 独立运行的项目
在项目启动的时候添加相应的配置,或者在自己的启动脚本中添加一下配置
-Dcom.sun.management.jmxremote -Djava.rmi.server.hostname=所在服务器ip -Dcom.sun.management.jmxremote.port=7003 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.password.file=../conf/jmxremote.password -Dcom.sun.management.jmxremote.access.file=../conf/jmxremote.access"
其他的使用与1、相似。
对于不能使用Visual GC插件,“不受Jvm支持”可以查看这里.