#
# 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
1
|
[root@node2 ~]
# yum install -y zabbix-java-gateway java-1.8.0
|
#配置
1
2
3
4
5
6
7
8
|
[root@node2 ~]
# vim /etc/zabbix/zabbix_java_gateway.conf
[root@node2 ~]
# 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
[root@node2 ~]
#
|
我们使用默认配置即可
#开启服务
1
2
3
4
|
[root@node2 ~]
# systemctl start zabbix-java-gateway.service
[root@node2 ~]
# netstat -lntup | grep 10052
tcp6 0 0 :::10052 :::* LISTEN 3002
/java
[root@node2 ~]
#
|
#修改zabbix-server配置文件
1
2
3
4
5
|
[root@node2 ~]
# vim /etc/zabbix/zabbix_server.conf
[root@node2 ~]
# egrep '(^Java|^Start)' /etc/zabbix/zabbix_server.conf
JavaGateway=192.168.174.136
JavaGatewayPort=10052
StartJavaPollers=5
|
#重启zabbix-server服务
1
|
[root@node2 ~]
# systemctl restart zabbix-server.service
|
#Tomcat开启JMX
#参考文档:http://tomcat.apache.org/tomcat-8.0-doc/monitoring.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
[root@node4 tomcat]
# vim /usr/local/tomcat/bin/catalina.sh
[root@node4 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"
[root@node4 tomcat]
# /usr/local/tomcat/bin/startup.sh
[root@node4 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
[root@node4 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文件
[root@node4 tomcat]
# hostname
node4
[root@node4 tomcat]
# vim /etc/hosts
[root@node4 tomcat]
# tail -1 /etc/hosts
192.168.174.138 node4
[root@node4 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.
[root@node4 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启用
#查看图形
本文转自 chaunceyjiang 51CTO博客,原文链接:http://blog.51cto.com/cqwujiang/1927253,如需转载请自行联系原作者