如题

安装方法:自己百度

步骤如下:

  1. 在Zabbix-Server上开启Zabbix-Java-gateway
    我的zabbix是用yum安装的,那么zabbix-java-gateway也用yum来装
    # rpm -i https://repo.zabbix.com/zabbix/3.5/rhel/7/x86_64/zabbix-release-3.5-1.el7.noarch.rpm       --导入zabbix官方repo和key证书
    # yum -y install  java-1.8.0  Zabbix-Java-gateway

zabbix-server的环境:

--Zabbix-Server:
[root@harbor bin]# ./version.sh 
Using CATALINA_BASE:   /usr/local/tomcat8
Using CATALINA_HOME:   /usr/local/tomcat8
Using CATALINA_TMPDIR: /usr/local/tomcat8/temp
Using JRE_HOME:        /usr/local/jdk1.8.0_181
Using CLASSPATH:       /usr/local/tomcat8/bin/bootstrap.jar:/usr/local/tomcat8/bin/tomcat-juli.jar
Server version: Apache Tomcat/8.0.53
Server built:   Jun 29 2018 14:42:45 UTC
Server number:  8.0.53.0
OS Name:        Linux
OS Version:     3.10.0-862.9.1.el7.x86_64
Architecture:   amd64
JVM Version:    1.8.0_181-b13
JVM Vendor:     Oracle Corporation
  1. 配置

--配置监听zabbix_java_gateway

[root@zabbix-server ~]# egrep -v '^#|^$'  /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

--配置zabbix-server.con配置文件连接zabbix_java_gateway

[root@zabbix-server ~]# egrep -v '^#|^$' /etc/zabbix/zabbix_server.conf 
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
SocketDir=/var/run/zabbix
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=123
**JavaGateway=127.0.0.1
JavaGatewayPort=10052**
StartJavaPollers=3
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
Timeout=4
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
FpingLocation=/usr/sbin/fping
LogSlowQueries=3000

--启动zabbix_java_gateway

[root@zabbix-server ~]# systemctl restart zabbix-java-gateway.service 
[root@zabbix-server ~]# 
[root@zabbix-server ~]# lsof -i:10052
COMMAND  PID   USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
java    2251 zabbix   13u  IPv6 1587393      0t0  TCP *:10052 (LISTEN)

--重启zabbix-server让配置生效

[root@zabbix-server ~]# systemctl restart zabbix-server.service 
[root@zabbix-server ~]# lsof -i:10051
COMMAND    PID   USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
zabbix_se 2320 zabbix    5u  IPv4 1588014      0t0  TCP *:zabbix-trapper (LISTEN)
zabbix_se 2320 zabbix    6u  IPv6 1588015      0t0  TCP *:zabbix-trapper (LISTEN)
zabbix_se 2325 zabbix    5u  IPv4 1588014      0t0  TCP *:zabbix-trapper (LISTEN)
zabbix_se 2325 zabbix    6u  IPv6 1588015      0t0  TCP *:zabbix-trapper (LISTEN)
zabbix_se 2326 zabbix    5u  IPv4 1588014      0t0  TCP *:zabbix-trapper (LISTEN)
zabbix_se 2326 zabbix    6u  IPv6 1588015      0t0  TCP *:zabbix-trapper (LISTEN)
zabbix_se 2327 zabbix    5u  IPv4 1588014      0t0  TCP *:zabbix-trapper (LISTEN

--至此zabbix-server端已经部署完成

  1. zabbix-agent端,也是tomcat服务器配置
    --tomcat or jdk version:
    [root@harbor bin]# ./version.sh 
    Using CATALINA_BASE:   /usr/local/tomcat8
    Using CATALINA_HOME:   /usr/local/tomcat8
    Using CATALINA_TMPDIR: /usr/local/tomcat8/temp
    Using JRE_HOME:        /usr/local/jdk1.8.0_181
    Using CLASSPATH:       /usr/local/tomcat8/bin/bootstrap.jar:/usr/local/tomcat8/bin/tomcat-juli.jar
    Server version: Apache Tomcat/8.0.53
    Server built:   Jun 29 2018 14:42:45 UTC
    Server number:  8.0.53.0
    OS Name:        Linux
    OS Version:     3.10.0-862.9.1.el7.x86_64
    Architecture:   amd64
    JVM Version:    1.8.0_181-b13
    JVM Vendor:     Oracle Corporation

修改tomcat家目录下的bin目录下的catalina.sh文件,添加以下内容

# vim /usr/local/tomcat8/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=12345     --监听的端口
-Djava.rmi.server.hostname=192.168.22.8"             -zabbix-server服务器ip

下载两个war包放到tomcat家目录下,用于监听用
http://repo.typesafe.com/typesafe/maven-releases/cmdline-jmxclient/cmdline-jmxclient/0.10.3/cmdline-jmxclient-0.10.3.jar --用于测试是否能获取数据用;
http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.76/bin/extras/catalina-jmx-remote.jar --用于收集tomcat信息用,注意版本一定要和tomcat版本一致。

--注意重启tomcat,确定12345端口已监听

### 执行以下命令,看能否收集到数据
[root@harbor ROOT]# java -jar cmdline-jmxclient-0.10.3.jar - localhost:12345 java.lang:type=Memory NonHeapMemoryUsage
08/03/2018 13:36:02 +0800 org.archive.jmx.Client NonHeapMemoryUsage: 
committed: 31653888
init: 2555904
max: -1
used: 30516656
  1. 导入tomcat模板,添加jmx监控
    下载tomcat_jvm_template:
[root@zabbix-server ~]# wget https://github.com/liuyjishg/DevOps/blob/master/zabbix/JVM_Tomcat_Template.zip
--2018-08-03 13:58:22--  https://github.com/liuyjishg/DevOps/blob/master/zabbix/JVM_Tomcat_Template.zip
正在解析主机 github.com (github.com)... 13.250.177.223, 13.229.188.59, 52.74.223.119
正在连接 github.com (github.com)|13.250.177.223|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:未指定 [text/html]
正在保存至: “JVM_Tomcat_Template.zip”

    [              <=>                                                                                                                                   ] 41,216      3.23KB/s 用时 12s    

2018-08-03 13:58:42 (3.23 KB/s) - “JVM_Tomcat_Template.zip” 已保存 [41216]

解压JVM_Tomcat_Template.zip文件,将里面的文件导入到zabbix模板中

再添加监控jmx就可以了