Zabbix自带了一部分对于JMX的监控,如果要想使用此模板对tomcat进行比较简单的监控可以考虑使用此模板。
与其他应用使用zabbix-agent不同,对JMX进行监控需要使用zabbix-java-gateway来与系统的JMX交互获取数据。zabbix-server 通过java-gateway的10052(默认端口)建立通信连接,java-gateway通过远程主机JMX的12345(默认端口)来获取数据。这里需要使用此Java命令行参数
“-Dcom.sun.management.jmxremote.port”在远程主机(JMX)上设置。通常它是在JAVA_OPTS环境变量中配置的。需要注意的是java-gateway仅仅作为一个转发数据的代理,不缓存任何数据。
提示:在一个zabbix-server环境中,只能有一个zabbix-java-gateway作为代理。
监控JMX配置步骤
1、在zabbix服务器上安装配置zabbix-java-gateway(也可单独安装在其他机器上)。
2、配置tomcat服务器 JMX服务相关参数
3、zabbix-serve配置zabbix-gateway.
4、zabbix web添加监控
Zabbix 服务器上安装配置zabbix-java-gateway
1、下载官方提供的软件包并进行安装:
1
<code>wget http:</code><code>//repo</code><code>.zabbix.com</code><code>/zabbix/3</code><code>.2</code><code>/rhel/7/x86_64/zabbix-java-gateway-3</code><code>.2.4-2.el7.x86_64.rpm</code>
<code>yum </code><code>install</code> <code>zabbix-java-gateway-3.2.4-2.el7.x86_64.rpm</code>
2、查看安装路径,使用rpm包的方式默认是安装在/usr/share/zabbix-java-gateway/目录
2
<code>rpm -qpl zabbix-java-gateway-3.2.4-2.el7.x86_64.rpm </code>
<code>cd</code> <code>/usr/share/zabbix-java-gateway/bin/</code>
<code>systemctl start zabbix-java-gateway</code>
配置tomcat JMX服务相关参数
1、修改tomcat配置文件,启用JMX
3
4
5
6
7
8
<code>vim </code><code>/usr/local/tomcat7/bin/catalina</code><code>.sh </code>
<code>#文件中添加如下内容:</code>
<code>CATALINA_OPTS="$CATALINA_OPTS</code>
<code>-Dcom.sun.management.jmxremote </code><code>#开启jmx远程监控</code>
<code>-Dcom.sun.management.jmxremote.port=12345</code>
<code>-Dcom.sun.management.jmxremote.authenticate=</code><code>false</code> <code>#免密码认证</code>
<code>-Dcom.sun.management.jmxremote.ssl=</code><code>false</code> <code>-Djava.rmi.server.</code><code>hostname</code><code>=192.168.56.11" </code><code>#tomcat服务器IP</code>
在另一台tomcat上使用相同的配置,IP改为本地的外网IP,此处的IP是JMX Interface的接口。
<code>-Dcom.sun.management.jmxremote </code>
<code>-Dcom.sun.management.jmxremote.authenticate=</code><code>false</code>
<code>-Dcom.sun.management.jmxremote.ssl=</code><code>false</code> <code>-Djava.rmi.server.</code><code>hostname</code><code>=192.168.56.12"</code>
2、重启tomcat 服务器,JMX的1234端口开启
<code>cd</code> <code>/usr/local/tomcat7/bin/</code>
<code>.</code><code>/shutdown</code><code>.sh</code>
<code>.</code><code>/startup</code><code>.sh</code>
zabbix-serve配置zabbix-gateway
1、修改zabbix-server的配置文件如下
9
10
<code>grep</code> <code>"^[A-Z]"</code> <code>/usr/local/zabbix_server/etc/zabbix_server</code><code>.conf</code>
<code>LogFile=</code><code>/tmp/zabbix_server</code><code>.log</code>
<code>DBName=zabbix</code>
<code>DBUser=zabbix</code>
<code>DBPassword=zabbix</code>
<code>JavaGateway=127.0.0.1 </code><code>#JavaGateway所在服务器的IP</code>
<code>JavaGatewayPort=10052 </code><code>#JavaGateway的默认端口</code>
<code>StartJavaPollers=5 </code><code>#JVM进行监控轮询实例数,默认是0,关闭状态,需要开启</code>
<code>Timeout=4</code>
<code>LogSlowQueries=3000</code>
2、重启zabbix-server
<code>killall zabbix_server</code>
<code>.</code><code>/zabbix_server</code> <code>-c </code><code>/usr/local/zabbix_server/etc/zabbix_server</code><code>.conf</code>
zabbix web添加监控
在web界面添加主机,并在主机上添加JMX模板:
<a href="https://s5.51cto.com/wyfs02/M01/93/45/wKiom1kJqeaD825RAAJQ_8QBuCg858.bmp" target="_blank"></a>
在主机模板中添加系统自带的两个JMX模板:
<a href="https://s5.51cto.com/wyfs02/M01/93/43/wKioL1kJqyLQHqIrAAHWKnaVzaM136.bmp" target="_blank"></a>
在配置了这些模板之后,默认情况下有些参数是获取不到的,这就需要我们对监控项目进行修改,具体如何修改我在zabbix 使用模板监控tomcat一文中有具体的配置过程。
本文转自 酥心糖 51CTO博客,原文链接:http://blog.51cto.com/tryingstuff/1921708