远程监控jvm内存
在网上查了好久的资料,也成功设置了catalina.sh 文件,可是就是不能链接上,心累啊,折腾了两个小时,所以说还是要看一手的资料,不然会走很多的弯路的。下面就是我设置的步骤:
(centos7+jdk8+tomcat 8)
1、vi打开catalina.sh 文件,就是在你tomcat路径下的bin文件夹下,在如下位置添加
- JAVA_OPTS="-Djava.rmi.server.hostname=127.0.0.1 -Dcom.sun.management.jmxremote.port=8099 -Dcom.sun.management.jmxremote.rmi.port=8099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"
JAVA_OPTS="-Djava.rmi.server.hostname=127.0.0.1 -Dcom.sun.management.jmxremote.port=8099 -Dcom.sun.management.jmxremote.rmi.port=8099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"
其中红色的部分-Dcom.sun.management.jmxremote.rmi.port=8099 一定要加上,网上都没有加,怎么都链接不上,“127.0.0.1”换成机器的真实的ip
2、netstat -tunlp|grep 8099查看8099端口是否被占用,如果占用另外换一个
3、防火墙端口的添加,/etc/firewalld/zones/public.xml 路径
4、防火墙重新加载,firewall-cmd --reload
5.本地jdk路径下jconsole启动
6、输入地址和端口,如果 -Dcom.sun.management.jmxremote.authenticate设置为false则不需要输入用户和密码
7、ok成功啦
内存
现在你就可以对自己的服务器进行监控了。
总结
第一次启动时tomcat不会报错,如果停止之后tomcat会提示端口被占用了, 问题原因是,在关闭Tomcat时,也执行了Catalish中的jmxremote的端口号。
解决办法:在catalish.sh文件中,判断是否为启动命令,如果是start,就设置变量,否则,就不设置。
- if [ "$1" = "start" ];then
- echo "set console";
- JAVA_OPTS="-Djava.rmi.server.hostname=127.0.0.1 -Dcom.sun.management.jmxremote.port=8099 -Dcom.sun.management.jmxremote.rmi.port=8099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"
- else
- echo "no startup";
- fi;