工作中常常遇到线上服务问题,所以有时会打开实时监控跟踪服务状况。
下面对自己工作中使用过的JMX监控Tomcat的相关配置流程做一下总结回顾:
环境介绍:
服务器:ECS CentOS 7.7.1908 [CentOS Linux release 7.7.1908]
开启JVM远程性能监控
1.复制jmx权限文件到Tomcat/conf目录下
操作:
# step 1:cd $JAVA_HOME/jre/lib/management/
# step 2:cp jmxremote.* /usr/local/soft/tomcat/apache-tomcat-7.0.96/conf
# step 3:cd $CATALINA_BASE/conf
# step 4:mv jmxremote.password.template jmxremote.password
# step 5:chmod 777 jmxremote.*
# step 6:修改 jmxremote.access,在末尾添加:用户名,权限,如:admin readwrite
# step 7:修改 jmxremote.password,在末尾添加:用户名,密码,如:admin 123456
# step 8:chmod -R 600 jmxremote.*
# step 9:两个文件分别保存退出
2.修改服务器 hosts 文件中的 IP 地址:
hosts文件的格式为:IP地址 主机名/域名
切换用户到root,修改/etc/hosts,在末尾添加你用来访问jmx的IP地址(可以是外网IP)
操作:
# step 1:vim /etc/hosts
# step 2:在尾部添加如下内容:47.97.27.199 fmcods.localdomain fmcods localhost.localdomain localhost
# step 3:reboot 重启主机,使配置生效
3.修改$CATALINA_BASE/bin目录下catalina.sh文件
操作:
# step 1:找到# ----- Execute The Requested Command ------这一行
# step 2:在step 1中内容的上一行添加如下配置:
CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Djava.rmi.server.hostname=47.97.27.199 -Dcom.sun.management.jmxremote.port=1100 -Dcom.sun.management.jmxremote.rmi.port=1100 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.password.file=$CATALINA_BASE/conf/jmxremote.password -Dcom.sun.management.jmxremote.access.file=$CATALINA_BASE/conf/jmxremote.access"
export CATALINA_OPTS
# ----- Execute The Requested Command -----------------------------------------
说明:
CATALINA_OPTS="$CATALINA_OPTS
-Dcom.sun.management.jmxremote
-Djava.rmi.server.hostname=47.97.27.199 -- 绑定远程主机IP,即用来访问JMX的IP地址
-Dcom.sun.management.jmxremote.port=1100
-Dcom.sun.management.jmxremote.rmi.port=1100 -- 配置jmx远程监听端口:1100,该端口可以指定任意未被占用的端口
-Dcom.sun.management.jmxremote.ssl=false -- 禁用ssl
-Dcom.sun.management.jmxremote.authenticate=true -- 启用用户认证
-Dcom.sun.management.jmxremote.password.file=$CATALINA_BASE/conf/jmxremote.password -- 用户信息配置文件位置,包括用户名和密码配置
-Dcom.sun.management.jmxremote.access.file=$CATALINA_BASE/conf/jmxremote.access" -- 用户访问权限的配置文件位置
4.重启Tomcat服务
5.在本地windows系统打开jconsole 或者 jvisualvm 开始远程服务监控
总结:刚开始学习监控服务监控时,无人指导,查阅了很多资料,也被各种误导,然后踩坑。最后终于尝试着走通了。觉得还是很有必要记录一下,供以后回顾。所有的问题总是自己实践一次才会真正掌握,别人的经验永远都是别人总结的最深刻体验。所以在学习这条路上自己也要不断的总结属于你自己的成功经验。