1.修改zabbix_java相关选项
[root@zabbix-16 zabbix]# cd /usr/local/sbin/zabbix_java [root@zabbix-16 zabbix_java]# vim settings.sh [root@zabbix-16 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
2.修改zabbix_server文件
[root@zabbix-16 zabbix_java]# sed -e '/^#/d;/^$/d' /usr/local/etc/zabbix_server.conf LogFile=/tmp/zabbix_server.log DBName=zabbix DBUser=zabbix DBPassword=zabbix [root@zabbix-16 zabbix_java]# vim /usr/local/etc/zabbix_server.conf [root@zabbix-16 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
3.执行startup.sh
[root@zabbix-16 zabbix_java]# sh startup.sh & [root@zabbix-16 ~]# netstat -tnlup | grep 10052 tcp 0 0 :::10052 :::* LISTEN 29326/java
4.tomcat端,安装catalina-jmx-remote.jar
[root@zabbix-test-16 ~]# wget http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.8/bin/extras/catalina-jmx-remote.jar [root@zabbix-test-16 ~]# mv catalina-jmx-remote.jar /usr/share/java/tomcat6 #yum路径 mv catalina-jmx-remote.jar /usr/local/tomcat/lib/ #源码路径
5.修改catalina.sh文件
[root@zabbix-test-16 tomcat6]# vim /usr/share/tomcat6/bin/catalina.sh [root@zabbix-test-16 tomcat6]# cat /usr/share/tomcat6/bin/catalina.sh CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Djava.rmi.server.hostname=192.168.16.253 -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false" #tomcat端的IP和指定JMX端口,在/bin/sh下面添加此段
7.重启服务
[root@zabbix-test-16 tomcat6]# /etc/init.d/tomcat6 restart [root@zabbix-test-16 tomcat6]# /etc/init.d/zabbix-agent restart
8.服务端测试(jar包在附件)
[root@zabbix-16 ~]# java -jar /root/cmdline-jmxclient-0.10.3.jar - 192.168.16.251:12345 java.lang:type=Memory NonHeapMemoryUsage
错误一:
[root@zabbix-16 ~]# java -jar /root/cmdline-jmxclient-0.10.3.jar - 192.168.16.251:18090 java.lang:type=Memory NonHeapMemoryUsageException in thread "main" java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: 192.168.16.251; nested exception is: java.net.ConnectException: Connection refused] at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:369) at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:270) at org.archive.jmx.Client.execute(Client.java:225) at org.archive.jmx.Client.main(Client.java:154)Caused by: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: 192.168.16.251; nested exception is: java.net.ConnectException: Connection refused] at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:122) at com.sun.jndi.toolkit.url.GenericURLContext.lookup(GenericURLContext.java:205) at javax.naming.InitialContext.lookup(InitialContext.java:417) at javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(RMIConnector.java:1955) at javax.management.remote.rmi.RMIConnector.findRMIServer(RMIConnector.java:1922) at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:287) ... 3 more
解决:
cat /usr/share/tomcat6/bin/catalina.sh CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Djava.rmi.server.hostname=192.168.16.253 -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"
错误二:
解决:
sh startup.sh & #放入后台启动
jar包及tomcat模板在附件
转载于:https://blog.51cto.com/szk5043/1845131