1.在zabix服务端安装java工具(服务器已安装zabbix)
[root@db02 ~]# rpm -ivh
[root@db02 ~]# vim /etc/zabbix/zabbix_server.conf
JavaGateway=127.0.0.1JavaGatewayPort=10055StartJavaPollers=5[root@db02 ~]# vim /etc/zabbix/zabbix_java_gateway.confLISTEN_IP="0.0.0.0"LISTEN_PORT=10055START_POLLERS=5
[root@db02 ~]# /etc/init.d/zabbix-server restart
Shutting down Zabbix server: [ OK ]Starting Zabbix server: [ OK ][root@db02 ~]# /etc/init.d/zabbix-java-gateway restartShutting down zabbix java gateway: [ OK ]Starting zabbix java gateway: [ OK ][root@db02 ~]# netstat -antulp | grep 10055
tcp 0 0 :::10055 :::* LISTEN 15958/java [root@db02 ~]#2.在tomcat端添加一个端口,供zabbix获取数据
jmxcmd下载地址:
[root@web02 ~]# vim /usr/local/tomcat-7.0.67/bin/catalina.sh --添加以下行,获取tomcat服务器的IP地址
CATALINA_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=本机IP地址"[root@web02 ~]# vim /usr/local/tomcat-7.0.67Html/conf/server.xml --暴露一个端口给zabbix获取数据
<Listener className="org.apache.catalina.mbeans.JmxRemoteLifecycleListener" rmiRegistryPortPlatform="9999" rmiServerPortPlatform="9999"/>[root@web02 ~]# /usr/local/tomcat-7.0.67/bin/shutdown.sh --关闭tomcat服务[root@web02 ~]# /usr/local/tomcat-7.0.67/bin/startup.sh --启动tomcat服务[root@web02 ~]# netstat -antulp | grep 9999
tcp 0 0 :::9999 :::* LISTEN 12469/java [root@web02 ~]# java -jar jmxcmd.jar - localhost:9999 java.lang:type=Memory NonHeapMemoryUsage04/26/2016 16:21:38 +0800 de.layereight.jmxcmd.Client NonHeapMemoryUsage: committed: 136183808init: 134676480max: 318767104used: 36691992[root@web02 ~]#3.在zabbix中添加分类,项目,键
(1).启用jmx模块
(2).创建分类
错误处理:
[root@web02 ~]# java -jar jmxcmd.jar - 180.178.55.82:9999 java.lang:type=Memory NonHeapMemoryUsage
Exception in thread "main" java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.NameNotFoundException: jmxrmi
at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:369)
at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:268)
at de.layereight.jmxcmd.Client.execute(Client.java:126)
at de.layereight.jmxcmd.Client.main(Client.java:65)
Caused by: javax.naming.NameNotFoundException: jmxrmi
at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:116)
at com.sun.jndi.toolkit.url.GenericURLContext.lookup(GenericURLContext.java:203)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(RMIConnector.java:1936)
at javax.management.remote.rmi.RMIConnector.findRMIServer(RMIConnector.java:1903)
at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:286)
解决方法:是tomcat_java的端口被占用了