Linux下Tomcat jvm远程监控搭建

背景:项目运行一段时间,top显示tomcat进程内存占用较高,故基于tomcat自带jmx remote进行内存监控。本文采用tomcat8.5版本进行搭建

1、tomcat/bin/catalina.sh文件添加如下内容

CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Djava.rmi.server.hostname=54.156.200.179 -Dcom.sun.management.jmxremote.port=7003 -Dcom.sun.management.jmxremote.rmi.port=7003 -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.password.file=/workspace/config/jvmpassword.cfg -Dcom.sun.management.jmxremote.access.file=/workspace/config/jvmaccess.cfg"

参数说明:

-Dcom.sun.management.jmxremote //启动原程访问

-Djava.rmi.server.hostname=54.156.200.179 //服务器地址

-Dcom.sun.management.jmxremote.port=7003 //远程端口,必须开放该端口

-Dcom.sun.management.jmxremote.authenticate=true //是否鉴权

-Dcom.sun.management.jmxremote.ssl=false //是否ssl

-Dcom.sun.management.jmxremote.password.file=/workspace/config/jvmpassword.cfg //密码文件

-Dcom.sun.management.jmxremote.access.file=/workspace/config/jvmaccess.cfg //用户名及其权限

2、添加权限文件 jvmpassword.cfg 和jvmaccess.cfg

jvmpassword.cfg内容为(用户名,密码)

monitor a123456
controller a654321

jvmaccess.cfg内容为(用户名,控制权限)

monitor readonly
controller readwrite

3、设置jvmpassword和jvmaccess的文件权限,不然无法访问

chmod 600 jvm*

4、本地打开cmd,进入jdk/bin目录,运行 jvisualvm.exe

jvisualvm.exe

出现如下界面:

5、右键Java VisualVM左部菜单“远程”,点击“添加远程主机”,输入服务器ip:54.156.200.179,点击“确定”

6、右键刚新建的远程主机,选择“添加JMX连接”,键入之前设置的端口、凭证用户名、密码,点击“确定”

⚠注意:

外网远程访问:需要在tomcat/lib/下添加jmx remote.jar

wget http://archive.apache.org/dist/tomcat/tomcat-8/v8.5.15/bin/extras/catalina-jmx-remote.jar

7、接下来请开始你的表演!!!

背景:项目运行一段时间,top显示tomcat进程内存占用较高,故基于tomcat自带jmx remote进行内存监控。本文采用tomcat8.5版本进行搭建 1、tomcat/bin/catalina.sh文件添加如下内容 CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Djava.rmi.server.hostname=54.156.200.179 -Dcom.sun.management.jmxremote.port=7003 -Dcom.sun.management.jmxremote.rmi.port=7003 -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.password.file=/workspace/config/jvmpassword.cfg -Dcom.sun.management.jmxremote.access.file=/workspace/config/jvmaccess.cfg" 参数说明: -Dcom.sun.management.jmxremote //启动原程访问 -Djava.rmi.server.hostname=54.156.200.179 //服务器地址 -Dcom.sun.management.jmxremote.port=7003 //远程端口,必须开放该端口 -Dcom.sun.management.jmxremote.authenticate=true //是否鉴权 -Dcom.sun.management.jmxremote.ssl=false //是否ssl -Dcom.sun.management.jmxremote.password.file=/workspace/config/jvmpassword.cfg //密码文件 -Dcom.sun.management.jmxremote.access.file=/workspace/config/jvmaccess.cfg //用户名及其权限 2、添加权限文件 jvmpassword.cfg 和jvmaccess.cfg jvmpassword.cfg内容为(用户名,密码) monitor a123456 controller a654321 jvmaccess.cfg内容为(用户名,控制权限) monitor readonly controller readwrite 3、设置jvmpassword和jvmaccess的文件权限,不然无法访问 chmod 600 jvm* 4、本地打开cmd,进入jdk/bin目录,运行 jvisualvm.exe jvisualvm.exe 出现如下界面: 5、右键Java VisualVM左部菜单“远程”,点击“添加远程主机”,输入服务器ip:54.156.200.179,点击“确定” 6、右键刚新建的远程主机,选择“添加JMX连接”,键入之前设置的端口、凭证用户名、密码,点击“确定” ⚠注意: 外网远程访问:需要在tomcat/lib/下添加jmx remote.jar wget http://archive.apache.org/dist/tomcat/tomcat-8/v8.5.15/bin/extras/catalina-jmx-remote.jar 7、接下来请开始你的表演!!!
经验分享 程序员 微信小程序 职场和发展