首先我们要安装上tomcat+jdk
我这里使用rpm包直接安装的:
[root@zabbix-node2 ~]# rpm -ivh jdk-8u102-linux-x64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:jdk1.8.0_102-2000:1.8.0_102-fcs ################################# [100%]
[root@zabbix-node2 ~]# java -version
java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)
#安装tomcat
[root@zabbix-node2 ~]# tar xf apache-tomcat-7.0.53.tar.gz -C /usr/local
[root@zabbix-node2 ~]# ls /usr/local/apache-tomcat-7.0.53/
bin conf lib LICENSE logs NOTICE RELEASE-NOTES RUNNING.txt temp webapps work
[root@zabbix-node2 ~]# ln -s /usr/local/apache-tomcat-7.0.53/ /usr/local/tomcat
[root@zabbix-node2 ~]# cd /usr/local/tomcat/bin/
[root@zabbix-node2 bin]# ./startup.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@zabbix-node2 bin]# netstat -lntup|grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 2850/nginx: master
tcp6 0 0 :::8009 :::* LISTEN 4795/java
tcp6 0 0 :::8080 :::* LISTEN 4795/java
验证:
这里可以使用官方的java-gatway来监控
zabbix-server会去找java-gateway,由javagateywa去找jmx
所以我们这里要找一台设备安装javagateway,这里安装到server-zabbix上
[root@zabbix-node1 ~]# yum install zabbix-java-gateway^V^C
[root@zabbix-node1 ~]# systemctl start zabbix-java-gateway.service
[root@zabbix-node1 ~]# netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 5506/mysqld
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1274/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1857/master
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 7923/zabbix_agentd
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 7117/zabbix_server
tcp6 0 0 :::80 :::* LISTEN 5588/httpd
tcp6 0 0 :::22 :::* LISTEN 1274/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1857/master
tcp6 0 0 :::10050 :::* LISTEN 7923/zabbix_agentd
tcp6 0 0 :::10051 :::* LISTEN 7117/zabbix_server
tcp6 0 0 :::10052 :::* #监听的这个端口 LISTEN 8776/java
window上安装jdk
配置zabbix-server去连接java-gateway
vim /etc/zabbix/zabbix_server.conf
JavaGateway=192.168.56.11
StartJavaPollers=5 #如果tomcat很多的话,这个采集器要配置的大点
重启服务:systemctl restart zabbix-java-gateway.service
这里可以zabbix可以监控java程序来。下面要多tomcat开启jmx。下面我们修改catalina。sh这个文件
加入以下内容
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=192.168.56.21"
# OS specific support. $var _must_ be set to either true or false.
然后tomcat重启服务。就可以看到端口12345
======================================================
下面window上面安装完成后,我们在这个路径下面C:\Program Files\Java\jdk1.8.0_66\bin找到“jconsole”点击打开,如下图:
通过远程连接,输入192.168.56.21:12345连接到刚刚配置的tomcat。这个也是刚刚添加catalina里面配置的信息才能连接
上传一个cmdline-jmxclient-0.10.3到21上面。
使用cmdline-jmxclient-0.10.3到
测试取内存的值:
如何取上面输出的值那???
下面我们新创建一个主机
上面这几步完成一个主机的创建
对于如下图的不支持的items我们要从jconsole里面找到新的内容,让他支持。
如果从jconsole里面没有找到,说明新的设备的java已经没有这个项了。我们要选择删除这部分,如果有我们把jconsole里面显示的新的内容替换item模板里面的key
下面演示一个8080的错误,按照找的方法,我们找到了jconsole上面的对应的项目值,然后从server上测试发现没有注册,这个是什么原因?如图:
这里是因为名字中有双引号的原因,我们需要转移,如下命令
[root@zabbix-node2 ~]# java -jar cmdline-jmxclient-0.10.3.jar - 192.168.56.21:12345 Catalina:type=GlobalRequestProcessor,name=\"http-bio-8080\"
Attributes:
requestCount: Introspected attribute requestCount (type=int)
maxTime: Introspected attribute maxTime (type=long)
bytesReceived: Introspected attribute bytesReceived (type=long)
modelerType: Type of the modeled resource. Can be set only once (type=java.lang.String)
bytesSent: Introspected attribute bytesSent (type=long)
processingTime: Introspected attribute processingTime (type=long)
errorCount: Introspected attribute errorCount (type=int)
Operations:
resetCounters: Introspected operation resetCounters
Parameters 0, return type=void
[root@zabbix-node2 ~]# java -jar cmdline-jmxclient-0.10.3.jar - 192.168.56.21:12345 Catalina:type=GlobalRequestProcessor,name=\"http-bio-8080\" requestCount
03/21/2017 13:24:01 -0400 org.archive.jmx.Client requestCount: 0
然后我们修改模板中item的key值
tomcat 7和8 都会不同,需要自己修改自己的模板,然后导出