以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'