jvisualvm远程监控jvm设置

本文介绍了如何正确配置Tomcat的JMX以实现远程监控,避免因端口冲突导致的问题,并详细解释了CATALINA_OPTS与JAVA_OPTS的区别及正确使用方式。

有些时候,需要对特定环境中的Java应用进行实时性能分析,大部分非开发和测试环境,一般都是用jvisualvm进行基本检测以最小化对系统的影响(其开启后,负载影响大约20%—30%),jvisualvm没有提供cli模式,只提供了GUI。在centos 6之后,默认不在安装图形化窗口如gnome,在有些生产环境中,因为网络和其他限制,无法通过系统盘或者yum安装相关界面。此时我们就需要预先在java启动脚本中进行JMX开启,在tomcat中,如下:

export CATALINA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=1099 -Djava.rmi.server.hostname=172.18.30.193 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"

172.18.30.193为本机IP地址。

代理抛出异常 : java.rmi.server.ExportException: Port already in use: 1099; nested exception is: 
java.net.BindException: Address already in use: JVM_Bind

上述选项必须设置在CATALINA_OPTS变量中,设置在JAVA_OPTS中,就会出现该问题。

# CATALINA_OPTS (Optional) Java runtime options used when the "start",
# "run" or "debug" command is executed.
# Include here and not in JAVA_OPTS all options, that should
# only be used by Tomcat itself, not by the stop process,
# the version command etc.
# Examples are heap size, GC logging, JMX ports etc.

# JAVA_OPTS (Optional) Java runtime options used when any command
# is executed.
# Include here and not in CATALINA_OPTS all options, that
# should be used by Tomcat and also by the stop process,
# the version command etc.
# Most options should go into CATALINA_OPTS.

由tomcat的停止脚本来看,其实是调用另外一个java运行时socket发到8005过去的,所以放置在JAVA_OPTS中导致有开启了一次JMX,所以出现这个错误。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值