使用visualvm jmx方式连接线上tomcat查看线程使用情况,发现无法连接,但是连接测试环境的tomcat是没有问题的。
jmx配置如下:
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=20002 -Dcom.sun.management.jmxremote"
而线上环境jstatd能够使用jmx的方式连接,检查jvm参数发现,jstatd的参数中多了
-Djava.rmi.server.hostname=ip地址
将tomcat启动参数改为
JAVA_OPTS="$JAVA_OPTS -Djava.rmi.server.hostname=ip地址 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=20002 -Dcom.sun.management.jmxremote"
使用jmx连接成功。
##测试hostname命令
在测试环境中,使用hostname -i命令,成功显示在当前环境中ip。
而在线上环境中,使用hostname -i命令,显示为127.0.0.1。
查看oracle文档中描述
java.rmi.server.hostname
The value of this property represents the host name string that should be associated with remote stubs for locally created remote objects, in order to allow clients to invoke methods on the remote object. The default value of this property is the IP address of the local host, in "dotted-quad" format.
http://docs.oracle.com/javase/7/docs/technotes/guides/rmi/javarmiproperties.html