1.项目规划
1.1 项目流程图
1.2 监控原理
◢使用Zabbix Java Gateway代理
2.Zabbix监控JMX
2.1 安装Java Gateway和jdk1.8
[root@linux-node1 ~]# yum install -y zabbix-java-gateway java-1.8.0 [root@linux-node1 ~]# java -version openjdk version "1.8.0_101" OpenJDK Runtime Environment (build 1.8.0_101-b13) OpenJDK 64-Bit Server VM (build 25.101-b13, mixed mode)
2.2 配置Java Gateway(一般无需修改,生产中按经验设置)
[root@linux-node1 ~]# vim /etc/zabbix/zabbix_java_gateway.conf ### Option: zabbix.listenIP # IP address to listen on. # # Mandatory: no # Default: # LISTEN_IP="0.0.0.0" #监控IP地址 ### Option: zabbix.listenPort # Port to listen on. # # Mandatory: no # Range: 1024-32767 # Default: # LISTEN_PORT=10052 #监控端口,默许10052 ### Option: zabbix.startPollers # Number of worker threads to start. # # Mandatory: no # Range: 1-1000 # Default: # START_POLLERS=5 #监控的线程数,用来轮询java应用,生产中值可设置为java应用数一半或相等 ### Option: zabbix.timeout # How long to wait for network operations. # # Mandatory: no # Range: 1-30 # Default: # TIMEOUT=3 TIMEOUT=3 #超时时间,按照网络状态来设置
2.3 启动Java Gateway
[root@linux-node1 ~]# systemctl start zabbix-java-gateway.service [root@linux-node1 ~]# lsof -i :10052 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME java 27118 root 11u IPv6 1011826 0t0 TCP *:10052 (LISTEN)
2.4 设置Java Gateway地址
[root@linux-node1 ~]# grep Java* /etc/zabbix/zabbix_server.conf ### Option: JavaGateway # IP address (or hostname) of Zabbix Java gateway. # Only required if Java pollers are started. JavaGateway=192.168.56.11 ### Option: JavaGatewayPort # Port that Zabbix Java gateway listens on. # JavaGatewayPort=10052 ### Option: StartJavaPollers # Number of pre-forked instances of Java pollers. StartJavaPollers=3 #预启用进程去轮询JavaGateway [root@linux-node1 ~]# systemctl restart zabbix-server.service #修改配置重启zabbix-server
2.5 安装tomcat8
[root@linux-node2 ~]# cd /usr/local/src [root@linux-node2 src]# wget http://mirrors.cnnic.cn/apache/tomcat/tomcat-8/v8.0.37/bin/apache-tomcat-8.0.37.tar.gz [root@linux-node2 src]# tar zxf apache-tomcat-8.0.37.tar.gz [root@linux-node2 src]# mv apache-tomcat-8.0.37 /usr/local/ [root@linux-node2 src]# ln -s /usr/local/apache-tomcat-8.0.37/ /usr/local/tomcat [root@linux-node2 src]# /usr/local/tomcat/bin/startup.sh [root@linux-node2 conf]# lsof -i :8088 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME java 93832 root 43u IPv6 516716 0t0 TCP *:radan-http (LISTEN)
2.6 开启jmx远程监控
JMX远程监控支持三种类型:1.无密码认证 2.用户名密码认证 3.ssl
[root@linux-node2 ~]# vim /usr/local/tomcat/bin/catalina.sh CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8888 #监控端口 -Dcom.sun.management.jmxremote.ssl=false #不使用ssl认证 -Dcom.sun.management.jmxremote.authenticate=false #不使用用户名密码认证 -Djava.rmi.server.hostname=192.168.56.12" #被监控的主机地址 [root@linux-node2 ~]# /usr/local/tomcat/bin/shutdown.sh #重启tomcat [root@linux-node2 ~]# /usr/local/tomcat/bin/startup.sh
2.7 使用jconsole远程测试
打开jconsole(D:\Program Files\Java\jdk1.7\bin\jconsole.exe)
2.8 使用zabbix监控jmx
创建一个items监控tomcat的threads allocated状态,添加graph,远程ab压测一下查看监控显示(ab -c 1000 -n 100000 http://192.168.56.12:8088/)
◢搞定,想监测tomcat的各种状态可以自定义item,非常方便,赶快去试试吧!