zabbix
监控tomcat
1.编译zabbix的时候需要添加参数--enable-java
关于如何安装zabbix
,可以参考上一篇文章http://blog.unix178.com/
备份zabbix_server.conf
和zabbix_agentd.conf
文件,重新编译安装zabbix
[root@nginx zabbix-2.2.0]# ./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-ssh2 --enable-java
2.zabbix_server端安装jdk
安装jdk
[root@nginx tmp]# tar xf jdk-7u9-linux-x64.tar.gz -C /usr/local/ [root@nginx tmp]# ls /usr/local/jdk1.7.0_09/ bin jre README.html THIRDPARTYLICENSEREADME.txt COPYRIGHT lib release db LICENSE src.zip include man THIRDPARTYLICENSEREADME-JAVAFX.txt
3.修改zabbix_java相关选项
然后进入到下面的目录下面进行seeting.sh
脚本编辑
[root@nginx zabbix-2.2.0]# find / -name zabbix_java /usr/local/sbin/zabbix_java /tmp/zabbix-2.2.0/src/zabbix_java [root@nginx zabbix-2.2.0]# [root@nginx zabbix-2.2.0]# ls bin lib settings.sh shutdown.sh startup.sh
该文件默认全部注释的,启用下面几项即可
[root@nginx zabbix_java]# vim settings.sh [root@nginx zabbix_java]# sed -e '/^#/d;/^$/d' settings.sh LISTEN_IP="0.0.0.0" LISTEN_PORT=10052 PID_FILE="/tmp/zabbix_java.pid" START_POLLERS=5 [root@nginx zabbix_java]#
4.修改zabbix_server文件
启用其中的几项
[root@nginx zabbix_java]# sed -e '/^#/d;/^$/d' /usr/local/etc/zabbix_server.conf LogFile=/tmp/zabbix_server.log DBName=zabbix DBUser=zabbix DBPassword=zabbix [root@nginx zabbix_java]# vim /usr/local/etc/zabbix_server.conf [root@nginx zabbix_java]# sed -e '/^#/d;/^$/d' /usr/local/etc/zabbix_server.conf LogFile=/tmp/zabbix_server.log DBName=zabbix DBUser=zabbix DBPassword=zabbix JavaGateway=127.0.0.1 JavaGatewayPort=10052 StartJavaPollers=5
5.启动zabbix_java
找到zabbix_java
目录路径,然后执行命令./startup.sh
[root@nginx zabbix-2.2.0]# find / -name zabbix_java /usr/local/sbin/zabbix_java /tmp/zabbix-2.2.0/src/zabbix_java [root@nginx zabbix-2.2.0]# [root@nginx zabbix-2.2.0]# ls bin lib settings.sh shutdown.sh startup.sh [root@nginx zabbix-2.2.0]# ss -tunlp | grep 10052 tcp LISTEN 0 50 :::10052 :::* users:(("java",16405,12))
6.调整tomcat
端,安装catalina-jmx-remote.jar
下载来安装:
root@tomcat5 tmp]# wget http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.8/bin/extras/catalina-jmx-remote.jar
将下载好的文件存放到tomcat
子目录目录lib
录下
[root@tomcat5 tmp]# mv catalina-jmx-remote.jar /usr/local/tomcat/lib/ [root@tomcat5 tmp]#
7.修改catalina.sh
文件
修改catalina.sh文件,添加
CATALINA_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=172.17.8.24"
8.重启启动tomcat
服务和zabbix_agentd
服务
echo "172.17.8.24 Tomcat008024" >>/etc/rc.local #tomcat会解析hostname,否则tomcat启动失败
9.服务器端测试是否能正常获取信息
[root@nginx zabbix-2.2.0]# java -jar /root/cmdline-jmxclient-0.10.3.jar - 192.168.146.130:9999 java.lang:type=Memory NonHeapMemoryUsage 05/24/2014 15:42:02 +0800 org.archive.jmx.Client NonHeapMemoryUsage: committed: 47316992 init: 24313856 max: 136314880 used: 47012784
10.服务器端自定义监控项
添加jmx监控端口
自定义监控项
查看绘图结果
直接上图,自己看吧
添加jmx监控端口
自定义监控项
查看绘图结果
如果你的tomcat端没有打开iptables或者允许全部端口,按照如上方式没问题。
-A INPUT -m state --state NEW -m tcp -p tcp --dport 12345:65535 -j ACCEPT
如果开启了防火墙,按照以上办法只允许12345没有作用,tomcat分为数据端口和连接端口,数据端口是动态的。所以按照以下操作:
http://tomcat.apache.org/download-70.cgi
cd /usr/local/tomcat/bin [按照tomcat版本选择jar]
wget http://apache.dataguru.cn/tomcat/tomcat-7/v7.0.65/bin/extras/catalina-jmx-remote.jar
chown tomcat:tomcat catalina-jmx-remote.jar
省略...<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.mbeans.JmxRemoteLifecycleListener" rmiRegistryPortPlatform="12345" rmiServerPortPlatform="12346" />
service iptables restart