zabbix通过jmx监控tomcat
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zabbix通过jmx监控tomcat相关的知识,希望对你有一定的参考价值。
通过jmx监控tomcat 一、服务端配置 1、安装jdk(版本1.8.0_91) [[email protected] ~]# rpm -ivh jdk-8u91-linux-x64.rpm [[email protected] ~]# vi /etc/profile 最后添加: JAVA_HOME=/usr/java/jdk1.8.0_91 CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export JAVA_HOME export PATH export CLASSPATH [[email protected] ~]# source /etc/profile 安装与配置比较简单,过程省略。执行java -version命令,出现类似界面表示成功。 [[email protected] ~]# java -version java version "1.8.0_91" Java(TM) SE Runtime Environment (build 1.8.0_91-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode) 2、安装Zabbix-Java-gateway [[email protected] ~]# cd /usr/src/zabbix-3.0.0/ [[email protected] zabbix-3.0.0]# ./configure --enable-java -prefix=/usr/local/zabbix/zabbix_java [[email protected] zabbix-3.0.0]# make && make install [[email protected] ~]# cd /usr/local/zabbix/zabbix_java/sbin/zabbix_java/ [[email protected] zabbix_java]# ls bin lib settings.sh shutdown.sh startup.sh 3、修改Java-gateway的配置文件并启动它 配置文件路径为/data/zabbix/zabbix_java/sbin/zabbix_java/settings.sh 启用以下参数: [[email protected] zabbix_java]# vi settings.sh LISTEN_IP="0.0.0.0" LISTEN_PORT=10052 START_POLLERS=5 4、修改zabbix_server的配置文件并重启 [[email protected] ~]# vi /usr/local/zabbix/etc/zabbix_server.conf JavaGateway=127.0.0.1 JavaGatewayPort=10052 StartJavaPollers=5 启动zabbix_java [[email protected] ~]# cd /usr/local/zabbix/zabbix_java/sbin/zabbix_java/ [[email protected] zabbix_java]# ./startup.sh 重启zabbix_server # /etc/init.d/zabbix_server restart 二、Tomcat服务端 1、给tomcat启动脚本添加参数,开启JMX [[email protected] ~]# vi /usr/local/site/bin/catalina.sh 添加如下内容: CATALINA_OPTS="${CATALINA_OPTS} -Djava.rmi.server.hostname=10.44.21.14" ----备注(10.44.21.14是客户端ip地址) CATALINA_OPTS="${CATALINA_OPTS} -Djavax.management.builder.initial=" CATALINA_OPTS="${CATALINA_OPTS} -Dcom.sun.management.jmxremote=true" #CATALINA_OPTS="${CATALINA_OPTS} -Dcom.sun.management.jmxremote.port=12345"#端口配置不用了 CATALINA_OPTS="${CATALINA_OPTS} -Dcom.sun.management.jmxremote.ssl=false" CATALINA_OPTS="${CATALINA_OPTS} -Dcom.sun.management.jmxremote.authenticate=false" [[email protected] site]# vi conf/server.xml(tomcat8.5版本不要在conf/server.xml增加以下内容,tomcat会起不来) 省略... <Server port="8005" shutdown="SHUTDOWN"> <Listener className="org.apache.catalina.startup.VersionLoggerListener" /> <!-- Security listener. Documentation at /docs/config/listeners.html <Listener className="org.apache.catalina.security.SecurityListener" /> --> <!--APR library loader. Documentation at /docs/apr.html --> <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html --> <Listener className="org.apache.catalina.core.JasperListener" /> <!-- Prevent memory leaks due to use of particular java/javax APIs--> <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" /> <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" /> <Listener className="org.apache.catalina.mbeans.JmxRemoteLifecycleListener" rmiRegistryPortPlatform="10052" rmiServerPortPlatform="10053" /> ----默认添加最后两行 省略.. 2、下载catalina-jmx-remote.jar wget http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.56/bin/extras/catalina-jmx-remote.jar #我的tomcat版本是7.0.56 将下载后后的jar包放到被监控的tomcat实例的lib目录下。 3、重启tomcat [[email protected] ~]# /usr/local/site/bin/shutdown.sh [[email protected] ~]# /usr/local/site/bin/startup.sh 4、测试是否可以获取数据 下载cmdline-jmxclient-0.10.3.jar工具 在服务器端进行测试 [[email protected] ~]# java -jar cmdline-jmxclient-0.10.3.jar - 10.44.21.143:10052 java.lang:type=Memory NonHeapMemoryUsage 08/29/2016 17:40:15 +0800 org.archive.jmx.Client NonHeapMemoryUsage: committed: 105644032 init: 2555904 max: -1 used: 101895192 问题: web界面上显示cannot connect to [[192.168.18.20]:10052]: [111] Connection refused ,192.168.18.20是我一个agent端的ip地址。debug级别已经调整为4,没有看到报错。 tomcat8.5只需要在bin/catalina.sh增加,重启tomcat服务 CATALINA_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=12345 -Djava.rmi.server.hostname=10.27.242.110"
本文出自 “个人博客” 博客,请务必保留此出处http://lgs6666.blog.51cto.com/10845239/1974342
以上是关于zabbix通过jmx监控tomcat的主要内容,如果未能解决你的问题,请参考以下文章