以Linux环境为例:
修改 JAVA_OPTS 参数,加入以下信息
JAVA_OPTS= $JAVA_OPTS
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=10000
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
然后在VisualVM里面右键添加JMX连接,输入IP和端口号10000(端口号可以自定义,但是必须保证没有被占用!!!)
-Dcom.sun.management.jmxremote :允许使用JMX远程管理
-Dcom.sun.management.jmxremote.port=10000 :JMX远程连接端口
-Dcom.sun.management.jmxremote.authenticate=false :不进行身份认证,任何用户都可以连接
-Dcom.sun.management.jmxremote.ssl=false :不使用ssl
如果连接的是公网,那么就要注意安全性了,接下来看看使用用户名和密码连接
将$JAVA_HOME/jre/lib/management 目录下的 jmxremote.access jmxremote.password.template 拷贝到一个目录下比如 $file下,将jmxremote.password.template 改名为jmxremote.password
jmxremote.password
#(123456、123456为密码)
monitorRole 123456
controlRole 123456
monitorRole readonly
controlRole readwrite \
create javax.management.monitor.*,javax.management.timer.* \
unregister
-Djava.rmi.server.hostname=ip
-Dcom.sun.management.jmxremote.port=10000
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=true
-Dcom.sun.management.jmxremote.password.file=$file/jmxremote.password
-Dcom.sun.management.jmxremote.access.file=$file/jmxremote.access'
如果提示权限相关的错误,给相关的文件授权即可。
通过jstatd 监控JVM
说明: 客户端与服务器的JVM大版本号必须一致或者兼容。
配置 jstatd.all.policy,其内容如下:
grant codebase "file:${java.home}/../lib/tools.jar" {
permission java.security.AllPermission;
};
在服务器上,通过如下命令启动jstatd
jstatd -J-Djava.security.policy=jstatd.all.policy -J-Djava.rmi.server.hostname=ip -p 12345 &
此处的-p 是指定端口号,自行找个没有被占用的端口即可。
然后通过 jvisualvm 或者 jconsole 连接远程服务器。
jstatd 不支持监控CPU。
本文介绍如何在Linux环境下通过配置JAVA_OPTS参数启用JMX远程管理,包括设置端口、禁用身份验证和SSL,以及如何在VisualVM中添加JMX连接。此外,还提供了使用用户名和密码进行安全连接的方法,以及通过jstatd监控JVM的步骤。
1万+

被折叠的 条评论
为什么被折叠?



