1 一个war包或者jar包,这里我用springboot的java
2 linux环境,安装tomcat,jdk,我用的jdk11和tomcat9,jdk11和8的拷贝权限文件路径有点不同,这个须要注意linux
3 无论是Jconsole仍是VisualVM,项目或者tomcat的配置都是同样的!spring
参考文章: http://www.javashuo.com/article/p-xsdbsflf-mv.htmlapache
vim /etc/hosts 添加:vim
添加JMX启动参数:tomcat
CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.password.file=../conf/jmxremote.password
-Dcom.sun.management.jmxremote.access.file=../conf/jmxremote.access -Djava.rmi.server.hostname=公有IP"
springboot
添加监听端口:mvc
<Listener className="org.apache.catalina.mbeans.JmxRemoteLifecycleListener" rmiRegistryPortPlatform="6379" rmiServerPortPlatform="3306" />测试
这里jdk11和jdk8目录不同,jdk11在jdk-11.0.4/conf/management/ 下面,拷贝到tomcat刚才配置的路径便可.net
编辑jmxremote.password:
编辑jmxremote.access:
下载地址:http://mvnrepository.com/artifact/org.apache.tomcat/tomcat-catalina-jmx-remote 我用的9.0.14,放到tomcat/lib下面,正常启动就能够了
注意: 若是链接不通,能够先看端口可否Telnet,而后 hostname -i Ip是否正常!
项目 pom加入JMX依赖,须要和tomcat版本对应:
tomcat-catalina-jmx-remote: springboot 2.0.6对应的是8.5.34
<!-- https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-catalina-jmx-remote -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina-jmx-remote</artifactId>
<version>8.5.34</version>
</dependency>
权限文件处理和war包同样,jar项目启动直接在后面加上配置权限便可,权限是必须配置的,还有端口在这里直接配置:
java -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.password.file=~/jmxremote.password -Dcom.sun.management.jmxremote.access.file=~/jmxremote.access -Djava.rmi.server.hostname=47.93.1.227 -Dcom.sun.management.jmxremote.port=8011 -jar springmvc-0.0.1-SNAPSHOT.jar