1、啟動java進程的命令
在啟動命令中添加如下信息
-Djava.rmi.server.hostname=192.169.1.71 -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=10099 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false
說明
-Djava.rmi.server.hostname為java程序運行所在的機器ip
-Dcom.sun.management.jmxremote.port為端口,自定義,保證是未使用的端口即可。jconsole通過這個端口來連接。
-Dcom.sun.management.jmxremote.authenticate=false表示在jconsole連接時可以不用輸入賬號和密碼
示例
nohup java -Xms128M -Xmx256M -Djava.rmi.server.hostname=192.169.1.71 -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=10099 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -jar appgateway-1.0.0.9.jar --spring.config.location=/usr/local/csnsh/ums/appgateway/application-appgateway.properties >appgateway.txt &
2、使用jvisualvm通過啟動命令中的ip和端口進行連接
點擊遠程——》添加遠程主機
輸入遠程主機名,點擊確定
右鍵添加JMX連接,輸入連接的ip和端口(上面啟動命令中的ip和端口)
點擊確定,成功連接 ,右邊是監控視圖