现在的位置: 首页 > 综合 > 正文

启动JMX远程功能,使用jConsole监控tomcat

2013年10月01日 ⁄ 综合 ⁄ 共 1384字 ⁄ 字号 评论关闭

在tomcat上测试的,理论上试用于任何JAVA进程,以及任何实现JMX规范的程序.

修改$CATALINA_HOME/bin/catalina.sh文件,添加如下JVM参数

 -Dcom.sun.management.jmxremote.port=18100  //指定jmx连接端口

-Dcom.sun.management.jmxremote.authenticate=false  //This configuration is insecure. Any remote user who knows (or guesses) your JMX port number and host name will be
able to monitor and control your Java application and platform. While it may be acceptable for development, it is not recommended for production systems. 这个参数默认是enabled  

 -Dcom.sun.management.jmxremote.pwd.file=/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/management/jmxremote.password 

-Dcom.sun.management.jmxremote.ssl=false  //默认是true,需要指定

 -Dcom.sun.management.jmxremote.pwd.file 这个参数指定的file路径,默认是在$JRE_HOME/lib/management下,默认是只有一个jmxremote.password.template文件,把这个文件拷贝成jmxremote.password,修改最后2行指定用户名密码,如:monitorRole  123456(用jconsole连接的时候就用这对用户名和密码)当然,JVM参数

-Dcom.sun.management.jmxremote.authenticate=false 的时候,不用密码就可以连接

启用JMX还有很多另外的JVM参数可以配置,配置使用密码连接以及使用SSL安全连接等等,不一个个去尝试了,方法见http://docs.oracle.com/javase/6/docs/technotes/guides/management/agent.html

过程中还需要修改机器的hosts,

# vi /etc/hosts 

127.0.0.1   (修改成机器ip)                   localhost localhost.localdomain localhost

修改机器主机名的文件(可不修改,但是要跟hosts匹配):/etc/sysconfig/network


注意:在catalina.sh文件中添加上面这些JVM参数后,运行shutdown.sh的时候,会提示jmxremote端口被占用,原因是运行shutdown.sh脚本的时候会启动一个JVM,又会尝试绑定jmxremote的端口,导致这个问题。见https://issues.apache.org/bugzilla/show_bug.cgi?id=36976。暂时没想办法去解决它,直接kill进程了(应该可以通过配置解决)。

抱歉!评论已关闭.