本地java监控远程Linux服务器-jconsole

发布时间 2023-04-28 11:20:42作者: 旺财队长

一、配置远程服务器需要监控的服务项目(本文以ps为例)

需要监控的ps项目,此项目启动文件为ps.sh,编辑sh文件,

找到JAVA_OPTS项,在后面添加

JAVA_OPTS="-XX:+UseParallelGC -XX:+UseParallelOldGC $JVM_FLAGS $GC_LOG -Dfile.encoding=UTF-8 -DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector"
后面添加
-Djava.rmi.server.hostname=172.16.xxx.xx -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=3214  -Dcom.sun.management.jmxremote.ssl=false  -Dcom.sun.management.jmxremote.authenticate=false
变为
JAVA_OPTS="-XX:+UseParallelGC -XX:+UseParallelOldGC $JVM_FLAGS $GC_LOG -Dfile.encoding=UTF-8 -DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector -Djava.rmi.server.hostname=172.16.xxx.xx -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=3214  -Dcom.sun.management.jmxremote.ssl=false  -Dcom.sun.management.jmxremote.authenticate=false"
解释如下:

开启JConsole远程连接的
-Djava.rmi.server.hostname=10.160.xx.xx #远程服务器ip,即本机ip
-Dcom.sun.management.jmxremote #允许JMX远程调用
-Dcom.sun.management.jmxremote.port=3214 #自定义jmx 端口号(不可被占用,不要和服务重复)
-Dcom.sun.management.jmxremote.ssl=false # 是否需要ssl 安全连接方式
-Dcom.sun.management.jmxremote.authenticate=false #是否需要秘钥

保存sh文件,按照原本的启动方式启动服务,如本文启动命令为:./ps.sh start

二、本地找到jconsole,配置远程链接,开始监控

位置如下(对应自己安装的java位置),启动jconsole:

 

启动后在下方填入远程服务器的ip和监控端口(上文的Dcom.sun.management.jmxremote.port=3214)

 

出现此类点击“不安全的链接”即可进入监控

 可实现同时对多个服务器的监控,监控数据也很多