文章目录
jvisualvm
是JDK自带的一款JVM监控程序
一个可以被监控的java进程启动脚本
- 允许匿名监控的启动脚本
#!/bin/sh
nohup java -Djava.rmi.server.hostname=118.31.117.131 \
-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.port=22222 -Xms2048m -Xmx2048m \
-jar ydBase.jar --spring.profiles.active=prod >/dev/null 2>&1 &
注意,一定要设置hostname,否则无法被连接
在安装了jdk的电脑上,启动 jvisualvm
,就能够看到
- 设置密码
#!/bin/sh
nohup java -Dcom.sun.management.jmxremote.password.file=/home/yiding/opt/pig-yd-base/jmxremote.password \
-Djava.rmi.server.hostname=118.31.117.131 \
-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.authenticate=true \
-Dcom.sun.management.jmxremote.port=22222 -Xms2048m -Xmx2048m \
-jar ydBase.jar --spring.profiles.active=prod >/dev/null 2>&1 &
提供一个jmxremote.password
文件,在java启动参数中指定文件路径。
文件的读写权限必须是 600
,文件内容为
monitorRole QED
controlRole R&D
左边是用户名,右边是密码
- 设置权限
类似的,java参数为:-Dcom.sun.management.jmxremote.access.file=jmxremote.access
jmxremote.access
文件内容为:
monitorRole readonly
controlRole readwrite \
create javax.management.monitor.*,javax.management.timer.* \
unregister
普通监控用户和控制用户,他们监控界面上能够看到的东西是不一样的