Zabbix--Proxy主动被动部署
Posted IT科技 不拘一格
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Zabbix--Proxy主动被动部署相关的知识,希望对你有一定的参考价值。
续:
推荐阅读:
一. Zabbix Proxy 架构
分布式监控文档:
https://www.zabbix.com/documentation/4.0/zh/manual/distributed_monitoring
Zabbix 通过 Zabbix proxies 为 IT 基础设施提供有效和可用的分布式监控。代理(proxies)可用于代替 Zabbix server 本地收集数据,然后将数据报告给服务器。
zabbix 作为一个分布式监控系统(分布式监控解决方案),支持通过代理(proxy)收集zabbix agent 的监控数据然后由 zabbix proxy 再把数据发送给 zabbix server,也就是 zabbix proxy 可以代替 zabbix server 收集监控数据,然后把数据汇报给zabbix server,所以 zabbix proxy 可以在一定程度上分担了 zabbix server 的数据收集压力,从而降低了数据的采集时间、也相应的增加了 zabbix server 的监控能力。另外 zabbix proxy 也区分主动模式和被动模式,通信方式与 zabbix server主动模式和被动模式一样,区别是 zabbix proxy 由于没有 zabbix agent 的配置,所以 zabbix proxy 在主动模式下要周期性的向 zabbix server 申请获取 zabbix agent的监控项信息,zabbix proxy 在被动模式下也是等待 zabbix server 的连接并接受 zabbix server 发送的监控项指令,然后再由 zabbix proxy 向 zabbix agent发起请求获取数据。
zabbix proxy mysql用于临时存储收集的信息资源数据
二.Zabbix proxy 和 Zabbix server 对比
对比表格:
三. Zabbix proxy 部署与使用
zabbix proxy 版本选择
在使用 proxy 做分布式监控时 zabbix proxy 的大版本必须要和 zabbix server版本一致,否则会导致出现 zabbix server 与 zabbix proxy 不兼容问题,出现类似以下的错误提示:
proxy "zabbix-proxy-active" protocol version x.x differs from server version x.x
安装 proxy
官方安装参考手册:
https://www.zabbix.com/documentation/4.0/zh/manual/installation/install
ubuntu18.04系统
主机准备:
Ubuntu 1804 node1 apt安装
这里有两种方式安装对应的应用,这里在主动模式下用apt安装 在被动模式下用编译安装
root@Zabbix-proxy-active:~# wget https://repo.zabbix.com/zabbix/4.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_4.0-3+bionic_all.deb
root@Zabbix-proxy-active:~# dpkg -i zabbix-release_4.0-3+bionic_all.deb
root@Zabbix-proxy-active:~# apt update
上面的源在国外,可能比较慢,所以可以替换成阿里云的源
阿里开源参考
https://developer.aliyun.com/mirror/
阿里云镜像源
https://mirrors.aliyun.com/zabbix/
root@Zabbix-proxy-active:~# vim /etc/apt/sources.list.d/zabbix.list
#deb http://repo.zabbix.com/zabbix/4.0/ubuntu bionic main
#deb-src http://repo.zabbix.com/zabbix/4.0/ubuntu bionic main
deb http://mirrors.aliyun.com/zabbix/zabbix/4.0/ubuntu bionic main
deb-src http://mirrors.aliyun.com/zabbix/zabbix/4.0/ubuntu bionic main
root@Zabbix-proxy-active:~# apt update
Get:1 http://mirrors.aliyun.com/zabbix/zabbix/4.0/ubuntu bionic InRelease [7,096 B]
Get:2 http://mirrors.aliyun.com/zabbix/zabbix/4.0/ubuntu bionic/main Sources [1,182 B]
Get:3 http://mirrors.aliyun.com/zabbix/zabbix/4.0/ubuntu bionic/main amd64 Packages [2,683 B]
Get:4 http://mirrors.aliyun.com/zabbix/zabbix/4.0/ubuntu bionic/main i386 Packages [2,684 B]
Hit:5 http://security.ubuntu.com/ubuntu bionic-security InRelease
Hit:6 http://us.archive.ubuntu.com/ubuntu bionic InRelease
Hit:7 http://us.archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:8 http://us.archive.ubuntu.com/ubuntu bionic-backports InRelease
Fetched 13.6 kB in 2s (6,013 B/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
251 packages can be upgraded. Run 'apt list --upgradable' to see them.
可以看到上面的链接是到了阿里云上面
查看并且安装proxy-mysql
root@Zabbix-proxy-active:~# apt-cache madison zabbix-proxy-mysql
zabbix-proxy-mysql | 1:4.0.20-1+bionic | http://mirrors.aliyun.com/zabbix/zabbix/4.0/ubuntu bionic/main amd64 Packages
zabbix-proxy-mysql | 1:3.0.12+dfsg-1 | http://us.archive.ubuntu.com/ubuntu bionic/universe amd64 Packages
zabbix | 1:4.0.20-1+bionic | http://mirrors.aliyun.com/zabbix/zabbix/4.0/ubuntu bionic/main Sources
root@Zabbix-proxy-active:~# apt install zabbix-proxy-mysql -y
准备数据库
这里创建对应的主动和被动代理的数据库名称以及用户和密码。
root@Mysql-master:~# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 789
Server version: 5.7.29-0ubuntu0.18.04.1 (Ubuntu)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
mysql> CREATE DATABASE zabbix_proxy_active CHARACTER SET UTF8 COLLATE UTF8_BIN;
Query OK, 1 row affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON zabbix_proxy_active.* TO proxy@'172.20.32.%' IDENTIFIED BY '123456';
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> CREATE DATABASE zabbix_proxy_passive CHARACTER SET UTF8 COLLATE UTF8_BIN;
Query OK, 1 row affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON zabbix_proxy_passive.* TO kaivi@'172.20.32.%' IDENTIFIED BY '123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql>
Ubuntu 1804 node2 编译安装
编译安装 zabbix proxy 时直接使用 zabbix 的源码包,通过指定编译参数来编译 proxy。
root@Zabbix-proxy-passive:~# cd /usr/local/src/
root@Zabbix-proxy-passive:/usr/local/src# rz -E
rz waiting to receive.
root@Zabbix-proxy-passive:/usr/local/src# ll
total 16820
drwxr-xr-x 2 root root 4096 Apr 30 23:25 ./
drwxr-xr-x 10 root root 4096 Oct 26 2019 ../
-rw-r--r-- 1 root root 17215217 Apr 29 13:41 zabbix-4.0.20.tar.gz
root@Zabbix-proxy-passive:/usr/local/src# tar xf zabbix-4.0.20.tar.gz
root@Zabbix-proxy-passive:/usr/local/src# cd zabbix-4.0.20/
#解决数据库依赖关系
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# apt install libmysqld-dev libmysqlclient-dev libxml2-dev libxml2 snmp libsnmp-dev libevent-dev curl libcurl4-openssl-dev -y
#编译安装
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# ./configure --prefix=/apps/zabbix_proxy --enable-proxy --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --enable-java
......
checking for pthread.h... (cached) yes
checking for process shared libpthread support... yes
checking for javac... no
configure: error: Unable to find "javac" executable in path
#因为--enable-java参数所以需要解决Java依赖
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# apt install openjdk-8-jdk -y
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# ./configure --prefix=/apps/zabbix_proxy --enable-proxy --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --enable-java
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# make install
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# ll /apps/zabbix_proxy/
total 28
drwxr-xr-x 7 root root 4096 May 1 01:04 ./
drwxr-xr-x 3 root root 4096 May 1 01:04 ../
drwxr-xr-x 2 root root 4096 May 1 01:04 bin/
drwxr-xr-x 4 root root 4096 May 1 01:04 etc/
drwxr-xr-x 3 root root 4096 May 1 01:04 lib/
drwxr-xr-x 3 root root 4096 May 1 01:04 sbin/
drwxr-xr-x 4 root root 4096 May 1 01:04 share/
将 proxy 所需的导入数据库
在机器172.20.32.103中测试是否可以连到远程数据库
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# mysql -ukaivi -p123456 -h172.20.32.104
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 897
Server version: 5.7.29-0ubuntu0.18.04.1 (Ubuntu)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
mysql> show databases;
+----------------------+
| Database |
+----------------------+
| information_schema |
| zabbix_proxy_passive |
+----------------------+
2 rows in set (0.00 sec)
mysql>
导入数据
这里只需要导入数据schema.sql 即可
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# pwd
/usr/local/src/zabbix-4.0.20
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# mysql -ukaivi -p123456 -h172.20.32.104 zabbix_proxy_passive < database/mysql/schema.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20#
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# mysql -ukaivi -p123456 -h172.20.32.104 zabbix_proxy_passive
mysql: [Warning] Using a password on the command line interface can be insecure.
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 937
Server version: 5.7.29-0ubuntu0.18.04.1 (Ubuntu)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
mysql> show tables;
+--------------------------------+
| Tables_in_zabbix_proxy_passive |
+--------------------------------+
| acknowledges |
| actions |
| alerts |
| application_discovery |
| application_prototype |
| application_template |
| applications |
......
| triggers |
| users |
| users_groups |
| usrgrp |
| valuemaps |
| widget |
| widget_field |
+--------------------------------+
144 rows in set (0.00 sec)
编写 proxy 的启动文件
主动模式是用apt安装的proxy。把主动模式下的启动文件拷贝到被动模式下
root@Zabbix-proxy-active:~# ll /lib/systemd/system/zabbix-proxy.service
-rw-r--r-- 1 root root 491 Dec 18 18:46 /lib/systemd/system/zabbix-proxy.service
root@Zabbix-proxy-active:~# scp /lib/systemd/system/zabbix-proxy.service 172.20.32.103:/lib/systemd/system/zabbix-proxy.service
The authenticity of host '172.20.32.103 (172.20.32.103)' can't be established.
ECDSA key fingerprint is SHA256:0ze4VLdSnOsoO+pl/Hj+Ln8kc5lPyF1En6W6MEV22jM.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.20.32.103' (ECDSA) to the list of known hosts.
root@172.20.32.103's password:
zabbix-proxy.service 100% 491 762.0KB/s 00:00
root@Zabbix-proxy-active:~#
编辑启动文件
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# vim /lib/systemd/system/zabbix-proxy.service
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# cat /lib/systemd/system/zabbix-proxy.service
[Unit]
Description=Zabbix Proxy
After=syslog.target
After=network.target
#After=mysql.service
#After=mysqld.service
#After=mariadb.service
[Service]
Environment="CONFFILE=/apps/zabbix_proxy/etc/zabbix_proxy.conf"
EnvironmentFile=-/etc/default/zabbix-proxy
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_proxy.pid
KillMode=control-group
ExecStart=/apps/zabbix_proxy/sbin/zabbix_proxy -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
TimeoutSec=infinity
[Install]
WantedBy=multi-user.target
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# useradd zabbix
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# chown zabbix.zabbix /apps/zabbix_proxy/ -R
配置被动模式的 proxy
配置并使用被动模式(Passive Proxy Mode)的 zabbix proxy 收集 zabbix agent 监控数据。
zabbix server : 172.20.32.101
zabbix proxy passive : 172.20.32.103
web server : 172.20.32.104
修改配置文件
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# vim /apps/zabbix_proxy/etc/zabbix_proxy.conf
# 注意,配置文件的选项后接注释会报错,注释从头开始
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# grep "^[a-Z]" /apps/zabbix_proxy/etc/zabbix_proxy.conf
ProxyMode=1 # 0为主动,1为被动
Server=172.20.32.101 # zabbix server服务器的地址或主机名
Hostname=kaivi-zabbix-proxy-passive # 代理服务器名称,需要与zabbix server添加代理时候的 proxy name是一致的!
ListenPort=10051 # zabbix proxy监听端口
LogFile=/tmp/zabbix_proxy.log
EnableRemoteCommands=1 # 允许zabbix server执行远程命令
PidFile=/tmp/zabbix_proxy.pid
DBHost=172.20.32.104
DBName=zabbix_proxy_passive
DBUser=kaivi
DBPassword=123456
DBPort=3306
ProxyLocalBuffer=720 # 已经提交到zabbix server的数据保留时间
ProxyOfflineBuffer=720 # 未提交到zabbix server的时间保留时间
ConfigFrequency=5 # 一般设置较长,此处5秒是为了看效果 一般300s
StartPollers=10 # 启动的数据采集器数量
JavaGateway=172.20.32.102 # java gateway服务器地址,当需要监控java的时候必须配置否则监控不到数据
JavaGatewayPort=10052
StartJavaPollers=10
CacheSize=16M # 保存监控项而占用的最大内存
HistoryCacheSize=128M # 保存监控历史数据占用的最大内存
HistoryIndexCacheSize=16M # 历史索引缓存的大小
Timeout=30 # 监控项超时时间,单位为秒
LogSlowQueries=3000 # 毫秒,多久的数据库查询会被记录到日志
启动验证启动文件
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# systemctl status zabbix-proxy
● zabbix-proxy.service - Zabbix Proxy
Loaded: loaded (/lib/systemd/system/zabbix-proxy.service; disabled; vendor preset: enabled)
Active: inactive (dead)
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# systemctl daemon-reload
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# systemctl start zabbix-proxy
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# systemctl enable zabbix-proxy
Created symlink /etc/systemd/system/multi-user.target.wants/zabbix-proxy.service → /lib/systemd/system/zabbix-proxy.service.
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# systemctl status zabbix-proxy
● zabbix-proxy.service - Zabbix Proxy
Loaded: loaded (/lib/systemd/system/zabbix-proxy.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2020-05-01 02:12:23 CST; 15s ago
Main PID: 34160 (zabbix_proxy)
Tasks: 37 (limit: 2216)
CGroup: /system.slice/zabbix-proxy.service
.......
root@Zabbix-proxy-passive:/usr/local/src/zabbix-4.0.20# tail /tmp/zabbix_proxy.log
34104:20200501:020939.688 proxy #30 started [poller #6]
34100:20200501:020939.688 proxy #26 started [poller #2]
34103:20200501:020939.689 proxy #29 started [poller #5]
34106:20200501:020939.690 proxy #32 started [poller #8]
34102:20200501:020939.692 proxy #28 started [poller #4]
34107:20200501:020939.693 proxy #33 started [poller #9]
34101:20200501:020939.694 proxy #27 started [poller #3]
34108:20200501:020939.697 proxy #34 started [poller #10]
34109:20200501:020939.699 proxy #35 started [unreachable poller #1]
34110:20200501:020939.700 proxy #36 started [icmp pinger #1]
在 web 界面添加被动 proxy
配置之文件中Hostname=zabbix_proxy_passive,最好保持一致
主机关联被动模板
这里为了效果明显,复用数据库的172.20.32.104的数据库服务器添加一个agent代理服务器
在172.20.32.104机器
#从172.20.32.102拷贝deb包到172.20.32.104
root@Zabbix-proxy-active:~# scp zabbix-release_4.0-3+bionic_all.deb 172.20.32.104:/root
The authenticity of host '172.20.32.104 (172.20.32.104)' can't be established.
ECDSA key fingerprint is SHA256:0ze4VLdSnOsoO+pl/Hj+Ln8kc5lPyF1En6W6MEV22jM.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.20.32.104' (ECDSA) to the list of known hosts.
root@172.20.32.104's password:
zabbix-release_4.0-3+bionic_all.deb
#安装
root@Mysql-master:~# dpkg -i zabbix-release_4.0-3+bionic_all.deb
root@Mysql-master:~# apt update
root@Mysql-master:~# apt install zabbix-agent -y
#修改配置文件
root@Mysql-master:~# vim /etc/zabbix/zabbix_agentd.conf
root@Mysql-master:~# cat /etc/zabbix/zabbix_agentd.conf|grep ^[a-Z]
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=172.20.32.103,172.20.32.101 #指向proxy以及server用于探测是否存活
ListenPort=10050
ListenIP=0.0.0.0
StartAgents=5
ServerActive=127.0.0.1
Hostname=172.20.32.104
Include=/etc/zabbix/zabbix_agentd.d/*.conf
#启动
root@Mysql-master:~# systemctl restart zabbix-agent
root@Mysql-master:~# systemctl enable zabbix-agent
Synchronizing state of zabbix-agent.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable zabbix-agent
然后就可以配置主机
等几分钟,就可以看到变绿了:
这里可以通过自带的测试命名测试是否能够获取到数据:
root@Zabbix-server:~# /apps/zabbix_server/bin/zabbix_get -s 172.20.32.104 -p10050 -k "system.cpu.load[all,avg1]"
0.020000
验证监控数据
配置主动模式的 proxy
配置并使用主动模式(Active Proxy Mode)的 zabbix proxy 收集 zabbix agent 监控数据
zabbix server : 172.20.32.101
zabbix proxy active : 172.20.32.102
web server : 172.20.32.105
root@Zabbix-proxy-active:~# /etc/zabbix/zabbix_proxy.conf
root@Zabbix-proxy-active:~# grep "^[a-Z]" /etc/zabbix/zabbix_proxy.conf
ProxyMode=0
Server=172.20.32.101
ServerPort=10051
Hostname=duanxin-zabbix-proxy-active
ListenPort=10051
LogFile=/tmp/zabbix_proxy.log
LogFileSize=0
EnableRemoteCommands=1
PidFile=/run/zabbix/zabbix_proxy.pid
SocketDir=/var/run/zabbix
DBHost=172.20.32.104
DBName=zabbix_proxy_active
DBUser=proxy
DBPassword=123456
DBPort=3306
ProxyLocalBuffer=720
ProxyOfflineBuffer=720
HeartbeatFrequency=30
ConfigFrequency=5
StartPollers=10
JavaGateway=172.20.32.102
JavaGatewayPort=10052
StartJavaPollers=10
CacheSize=16M
HistoryCacheSize=128M
HistoryIndexCacheSize=16M
Timeout=30
LogSlowQueries=3000
导入数据到 proxy 的数据库
在机器172.20.32.103中测试是否能够正常连接数据库
root@Zabbix-proxy-active:~# mysql -uproxy -p123456 -h172.20.32.104
Welcome to the MariaDB monitor. Commands end with ; or g.
Your MySQL connection id is 113
Server version: 5.7.29-0ubuntu0.18.04.1 (Ubuntu)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
MySQL [(none)]>
这里的数据库的路径以及对应的schema.sql文件和编译安装的都不一致,但是可以通过zcat和管道符的方法读到数据库中
root@Zabbix-proxy-active:~# cd /usr/share/doc/zabbix-proxy-mysql/
root@Zabbix-proxy-active:/usr/share/doc/zabbix-proxy-mysql# ll
total 48
drwxr-xr-x 2 root root 4096 Apr 30 23:58 ./
drwxr-xr-x 546 root root 20480 Apr 30 23:58 ../
-rw-r--r-- 1 root root 2460 Apr 27 15:00 changelog.Debian.gz
-rw-r--r-- 1 root root 980 Nov 21 20:16 copyright
-rw-r--r-- 1 root root 12946 Apr 27 15:00 schema.sql.gz
root@Zabbix-proxy-active:/usr/share/doc/zabbix-proxy-mysql# zcat schema.sql.gz | mysql -uproxy -p123456 -h172.20.32.104 zabbix_proxy_active
root@Zabbix-proxy-active:/usr/share/doc/zabbix-proxy-mysql# mysql -uproxy -p123456 -h172.20.32.104 zabbix_proxy_active
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MariaDB monitor. Commands end with ; or g.
Your MySQL connection id is 122
Server version: 5.7.29-0ubuntu0.18.04.1 (Ubuntu)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
MySQL [zabbix_proxy_active]>
MySQL [zabbix_proxy_active]> show tables;
+-------------------------------+
| Tables_in_zabbix_proxy_active |
+-------------------------------+
| acknowledges |
| actions |
| alerts |
| application_discovery |
| application_prototype |
| application_template |
......
| users |
| users_groups |
| usrgrp |
| valuemaps |
| widget |
| widget_field |
+-------------------------------+
144 rows in set (0.00 sec)
MySQL [zabbix_proxy_active]>
重启proxy
root@Zabbix-proxy-active:/usr/share/doc/zabbix-proxy-mysql# cd
root@Zabbix-proxy-active:~# systemctl restart zabbix-proxy
root@Zabbix-proxy-active:~# systemctl enable zabbix-proxy
Synchronizing state of zabbix-proxy.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable zabbix-proxy
root@Zabbix-proxy-active:~# tail -f /tmp/zabbix_proxy.log #查看日志看是否报错
web 界面添加主动代理
代理地址可写可不写
主机关联被动模板
这里为了效果明显,复用数据库从库的172.20.32.105的slave数据库服务器添加一个agent代理服务器
在172.20.32.105机器
#从172.20.32.102拷贝deb包到172.20.32.105
root@Zabbix-proxy-active:~# scp zabbix-release_4.0-3+bionic_all.deb 172.20.32.105:/root
The authenticity of host '172.20.32.105 (172.20.32.105)' can't be established.
ECDSA key fingerprint is SHA256:0ze4VLdSnOsoO+pl/Hj+Ln8kc5lPyF1En6W6MEV22jM.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.20.32.105' (ECDSA) to the list of known hosts.
root@172.20.32.105's password:
zabbix-release_4.0-3+bionic_all.deb
#安装
root@Mysql-slave:~# dpkg -i zabbix-release_4.0-3+bionic_all.deb
root@Mysql-slave:~# apt update
root@Mysql-slave:~# apt install zabbix-agent -y
#修改配置文件
root@Mysql-slave:~# vim /etc/zabbix/zabbix_agentd.conf
root@Mysql-slave:~# cat /etc/zabbix/zabbix_agentd.conf|grep ^[a-Z]
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=172.20.32.102,172.20.32.101 #指向proxy以及server用于探测是否存活
ListenPort=10050
ListenIP=0.0.0.0
StartAgents=5
ServerActive=172.20.32.102 #配置主动模式代理服务器
Hostname=172.20.32.105
Include=/etc/zabbix/zabbix_agentd.d/*.conf
#重新启动
root@Mysql-slave:~# systemctl restart zabbix-agent
root@Mysql-slave:~# systemctl enable zabbix-agent
Synchronizing state of zabbix-agent.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable zabbix-agent
然后就可以配置主机
命令测试是否主动获取到数据:
root@Zabbix-server:~# /apps/zabbix_server/bin/zabbix_get -s 172.20.32.105 -p10050 -k "system.cpu.load[all,avg1]"
0.000000
稍等一下 然后最终界面:
验证监控数据
扩展
root@Zabbix-server:~# /apps/zabbix_server/bin/zabbix_get -s 172.20.32.104 -p10050 -k "agent.ping"
1
root@Zabbix-server:~# /apps/zabbix_server/bin/zabbix_get -s 172.20.32.105 -p10050 -k "agent.ping"
1
root@Zabbix-server:~# /apps/zabbix_server/bin/zabbix_get -s 172.20.32.106 -p10050 -k "agent.ping"
1
root@Zabbix-server:~# /apps/zabbix_server/bin/zabbix_get -s 172.20.32.107 -p10050 -k "agent.ping"
1
实现主动模式java-getewat代理
实现架构
安装java环境
主机duanxin-zabbix-proxy-active: 172.20.32.105-mysql-slave 主动模式下配置java-getewat代理
先要要web主机 172.20.32.105部署Java环境,这里就直接apt安装jdk
root@Mysql-slave:/apps# apt install openjdk-8-jdk -y
#部署tomcat,这里上传到/usr/local/src
# tar xf apache-tomcat-8.5.54.tar.gz
# ln -sv /usr/local/src/apache-tomcat-8.5.54 /apps/tomcat
root@Mysql-slave:/apps# cd /apps/
root@Mysql-slave:/apps# mkdir tomcat/webapps/myapp -p
root@Mysql-slave:/apps# vim tomcat/webapps/myapp/index.html
root@Mysql-slave:/apps# cat tomcat/webapps/myapp/index.html
mysql slave jsp for tomcat test
root@Mysql-slave:/apps# vim tomcat/bin/catalina.sh
......
117
CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=172.20.32.105"
......
#重启tomcat
root@Mysql-slave:/apps# tomcat/bin/catalina.sh stop
root@Mysql-slave:/apps# tomcat/bin/catalina.sh start
root@Mysql-slave:/apps# ss -ntl|grep 12345
LISTEN 0 50 *:12345 *:*
访问测试页面:
添加主机和模板
配置Zabbix-proxy-active的zabbix_proxy
root@Zabbix-proxy-active:~# vim /etc/zabbix/zabbix_proxy.conf
......
317
### Option: JavaGateway
# IP address (or hostname) of Zabbix Java gateway.
# Only required if Java pollers are started.
#
# Mandatory: no
# Default:
JavaGateway=172.20.32.102
### Option: JavaGatewayPort
# Port that Zabbix Java gateway listens on.
#
# Mandatory: no
# Range: 1024-32767
# Default:
JavaGatewayPort=10052
### Option: StartJavaPollers
# Number of pre-forked instances of Java pollers.
#
# Mandatory: no
# Range: 0-1000
# Default:
StartJavaPollers=10
......
root@Zabbix-proxy-active:~# systemctl restart zabbix-proxy
root@Zabbix-proxy-active:~# ss -ntl|grep 10052
LISTEN 0 50 *:10052 *:*
验证数据
root@Zabbix-proxy-active:~# netstat -tanlp|grep 172.20.32.105
tcp 0 0 172.20.32.102:10051 172.20.32.105:37169 TIME_WAIT -
tcp 0 0 172.20.32.102:10051 172.20.32.105:37185 TIME_WAIT -
tcp 0 0 172.20.32.102:16913 172.20.32.105:10050 TIME_WAIT -
tcp 0 0 172.20.32.102:10051 172.20.32.105:37177 TIME_WAIT -
tcp 0 0 172.20.32.102:10051 172.20.32.105:37163 TIME_WAIT -
tcp 0 0 172.20.32.102:10051 172.20.32.105:37165 TIME_WAIT -
tcp 0 0 172.20.32.102:10051 172.20.32.105:37183 TIME_WAIT -
tcp 0 0 172.20.32.102:10051 172.20.32.105:37187 TIME_WAIT -
tcp 0 0 172.20.32.102:10051 172.20.32.105:37167 TIME_WAIT -
tcp 0 0 172.20.32.102:10051 172.20.32.105:37175 TIME_WAIT -
tcp 0 0 172.20.32.102:10051 172.20.32.105:37181 TIME_WAIT -
tcp 0 0 172.20.32.102:10051 172.20.32.105:37171 TIME_WAIT -
tcp 0 0 172.20.32.102:10051 172.20.32.105:37179 TIME_WAIT -
tcp 0 0 172.20.32.102:10051 172.20.32.105:37173 TIME_WAIT -
tcp6 0 0 172.20.32.102:39953 172.20.32.105:12345 ESTABLISHED 828/java
tcp6 0 0 172.20.32.102:48279 172.20.32.105:17694 ESTABLISHED 828/java
tcp6 0 0 172.20.32.102:48163 172.20.32.105:17694 TIME_WAIT -
tcp6 0 0 172.20.32.102:39715 172.20.32.105:12345 TIME_WAIT -
tcp6 0 0 172.20.32.102:48041 172.20.32.105:17694 TIME_WAIT -
tcp6 0 0 172.20.32.102:48165 172.20.32.105:17694 TIME_WAIT -
tcp6 0 0 172.20.32.102:39837 172.20.32.105:12345 TIME_WAIT -
root@Mysql-slave:~# netstat -tanlp|grep 172.20.32.102
tcp 0 0 172.20.32.105:10050 172.20.32.102:17839 TIME_WAIT -
tcp 0 0 172.20.32.105:10050 172.20.32.102:17871 TIME_WAIT -
tcp 0 0 172.20.32.105:10050 172.20.32.102:17903 TIME_WAIT -
tcp 0 0 172.20.32.105:10050 172.20.32.102:17887 TIME_WAIT -
tcp 0 0 172.20.32.105:10050 172.20.32.102:17855 TIME_WAIT -
tcp 0 0 172.20.32.105:10050 172.20.32.102:17741 TIME_WAIT -
tcp 0 0 172.20.32.105:10050 172.20.32.102:17783 TIME_WAIT -
tcp 0 0 172.20.32.105:10050 172.20.32.102:17891 TIME_WAIT -
tcp6 0 0 172.20.32.105:12345 172.20.32.102:40773 ESTABLISHED 12370/java
# 172.20.32.105:12345 端口连接
tcp6 0 0 172.20.32.105:17694 172.20.32.102:49099 ESTABLISHED 12370/java
......
推荐阅读:
以上是关于Zabbix--Proxy主动被动部署的主要内容,如果未能解决你的问题,请参考以下文章