#
# zabbix提供了一个JMX通过java gateway 来监控java
#官方文档:https://www.zabbix.com/documentation/3.2/manual/appendix/config/zabbix_java
#java gatewa 需要独立安装 以为zabbix-server zabbix-agent都不能直接监控java
#Tomcat 安装参考:Tomcat安装与配置
#zabbix 安装参考:zabbix安装和基本介绍
主机名 | 角色 | IP地址 |
node2 | zabbix-server zabbix-java-gateway | 192.168.174.136 |
node4 | tomcat | 192.168.174.138 |
#安装java gateway
[[email protected] ~]# yum install -y zabbix-java-gateway java-1.8.0
#配置
[[email protected] ~]# vim /etc/zabbix/zabbix_java_gateway.conf [[email protected] ~]# grep ‘^[a-Z]‘ /etc/zabbix/zabbix_java_gateway.conf LISTEN_IP="0.0.0.0" LISTEN_PORT=10052 PID_FILE="/var/run/zabbix/zabbix_java.pid" START_POLLERS=5 TIMEOUT=3 [[email protected] ~]#
我们使用默认配置即可
#开启服务
[[email protected] ~]# systemctl start zabbix-java-gateway.service [[email protected] ~]# netstat -lntup | grep 10052 tcp6 0 0 :::10052 :::* LISTEN 3002/java [[email protected] ~]#
#修改zabbix-server配置文件
[[email protected] ~]# vim /etc/zabbix/zabbix_server.conf [[email protected] ~]# egrep ‘(^Java|^Start)‘ /etc/zabbix/zabbix_server.conf JavaGateway=192.168.174.136 JavaGatewayPort=10052 StartJavaPollers=5
#重启zabbix-server服务
[[email protected] ~]# systemctl restart zabbix-server.service
#Tomcat开启JMX
#参考文档:http://tomcat.apache.org/tomcat-8.0-doc/monitoring.html
[[email protected] tomcat]# vim /usr/local/tomcat/bin/catalina.sh [[email protected] tomcat]# sed -n ‘114,118p‘ /usr/local/tomcat/bin/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=8888 -Djava.rmi.server.hostname=192.168.174.138" [[email protected] tomcat]# /usr/local/tomcat/bin/startup.sh [[email protected] tomcat]# 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:22 0.0.0.0:* LISTEN 1186/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1512/master tcp6 0 0 :::22 :::* LISTEN 1186/sshd tcp6 0 0 ::1:25 :::* LISTEN 1512/master udp 0 0 0.0.0.0:20618 0.0.0.0:* 991/dhclient udp 0 0 0.0.0.0:68 0.0.0.0:* 991/dhclient udp6 0 0 :::36737 :::* 991/dhclient #发现服务没有启动 查看日志在最后一行发现错误,local host name unknow [roo[email protected] tomcat]# tail -10 logs/catalina.out 18-May-2017 23:19:33.887 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 32022 ms 18-May-2017 23:24:00.914 INFO [main] org.apache.catalina.core.StandardServer.await A valid shutdown command was received via the shutdown port. Stopping the Server instance. 18-May-2017 23:24:00.915 INFO [main] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["http-nio-8080"] 18-May-2017 23:24:00.970 INFO [main] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["ajp-nio-8009"] 18-May-2017 23:24:01.022 INFO [main] org.apache.catalina.core.StandardService.stopInternal Stopping service [Catalina] 18-May-2017 23:24:01.080 INFO [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["http-nio-8080"] 18-May-2017 23:24:01.081 INFO [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["ajp-nio-8009"] 18-May-2017 23:24:01.082 INFO [main] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["http-nio-8080"] 18-May-2017 23:24:01.083 INFO [main] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["ajp-nio-8009"] Error: Exception thrown by the agent : java.net.MalformedURLException: Local host name unknown: java.net.UnknownHostException: node4: node4: Name or service not known #修改hosts文件 [[email protected] tomcat]# hostname node4 [[email protected] tomcat]# vim /etc/hosts [[email protected] tomcat]# tail -1 /etc/hosts 192.168.174.138 node4 [[email protected] tomcat]# /usr/local/tomcat/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/local/jdk Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar Tomcat started. [[email protected] tomcat]# 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:22 0.0.0.0:* LISTEN 1186/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1512/master tcp6 0 0 :::8009 :::* LISTEN 4020/java tcp6 0 0 :::8080 :::* LISTEN 4020/java tcp6 0 0 :::22 :::* LISTEN 1186/sshd tcp6 0 0 :::53463 :::* LISTEN 4020/java tcp6 0 0 :::8888 :::* LISTEN 4020/java tcp6 0 0 ::1:25 :::* LISTEN 1512/master tcp6 0 0 :::45731 :::* LISTEN 4020/java tcp6 0 0 127.0.0.1:8005 :::* LISTEN 4020/java udp 0 0 0.0.0.0:20618 0.0.0.0:* 991/dhclient udp 0 0 0.0.0.0:68 0.0.0.0:* 991/dhclient udp6 0 0 :::36737 :::* 991/dhclient 服务正常启动
#添加主机
#选择模板
#JMX启用
#查看图形
时间: 2024-12-29 12:25:20