jconsole可以远程连接的前提(需要在部署应用时像下面示例这样设置):
-Djava.rmi.server.hostname=127.0.0.1
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=3214
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
如此设置后,启动应用,Linux通过jinfo pid|grep "management"
可看到如上属性生效,以下为Windows上:
C:\Users\Administrator>jinfo 10416|findstr "management"
sun.management.compiler = HotSpot 64-Bit Tiered Compilers
com.sun.management.jmxremote =
com.sun.management.jmxremote.port = 62355
com.sun.management.jmxremote.ssl = false
com.sun.management.jmxremote.authenticate = false
FINDSTR: 行 60 太长。
Command line: -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:62356,suspend=y,server=n -XX:TieredStopAtLevel=1 -Xverify:none -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=62355 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=localhost -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true -javaagent:C:\Users\Administrator\.IntelliJIdea2018.3\system\captureAgent\debugger-agent.jar -Dfile.encoding=UTF-8
也可通过arthas
的jvm
查看是否添加成功:
也可通过arthas
的sysprop
:
[arthas@10416]$ sysprop | grep management
com.sun.management.jmxremote.authenticate false
1.8.0_162\jre\lib\management-agent.jar;D:\Program Files\Java\jdk1.8.0_162\jre\lib\plugin.jar;D:\Program Files\Java\jdk1.8.0_162\jre\lib\resources.jar;D:\Program Files\Java\jdk1.8.0_162\jr
com.sun.management.jmxremote.ssl false
com.sun.management.jmxremote
sun.management.compiler HotSpot 64-Bit Tiered Compilers
com.sun.management.jmxremote.port 62355
jconsole远程连接host:port
即可:
注意:idea默认打开JMX,只是JMX端口是动态的,所以可直接远程连接;但普通直接部署应用不会打开JMX,需要主动设置。