簡介
一般操作都不直接在服務器上進行,通過VisualVM連接到遠程服務器上可以更方便得進行jvm跟蹤調優。
配置JMX連接
啓動程序
java \
-Djava.rmi.server.hostname=127.0.0.1 \
-Dcom.sun.management.jmxremote.port=8877 \
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.authenticate=false \
Hello
查看端口占用
[hello@test hello]$ jps -lm
9263 Hello
[hello@test hello]$ netstat -anp | grep 9263
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp6 0 0 :::10027 :::* LISTEN 9263/java
tcp6 0 0 :::8877 :::* LISTEN 9263/java
tcp6 0 0 :::20928 :::* LISTEN 9263/java
這個步驟可以看到,不僅佔用了8877端口,還隨機多佔用了兩個端口。這點許多資料沒講,乾脆把防火牆給關了,實際上把端口打通即可。
建立隧道連接
開開心心連上去
JConsole連接
和VisualVM連接是一樣的