1. Zabbix 6.0.4 Proxy 概述
本次实验在 Zabbix 6.0.4 版本下完成。
Zabbix通过主动和被动Proxy代理分别主动方式和被动方式监控跨网段两台Linux主机。我们可以理解Zabbix的Proxy代理就是一个简化版的Zabbix-Server软件包,它可以被部署在异地的备份机房或者分支机构,完成当地监控数据收集再上报给zabbix server。
功能
zabbxy proxy
zabbix server
轻量级
是
相对重量级
图形界面
无
带图形控制界面
可以独立工作
是,可以独立采集数据并存储
是,即数据采集、存储、分析、展示于一体
易维护
是,配置完成后基本无需管理
维护并不复杂
独立数据库
保留少量最近数据
保留指定时间内的所有数据
报警通知
否,代理服务器不发送
邮件通知支持邮件、短信等告警机制
2. 实验架构图
本次实验在 Zabbix 6.0.4 版本下完成。
Zabbix代理主机名定义为:proxy_active Zabbix代理主机IP地址:172.16.0.118
3. Zabbix-Agent 主动代理模式Linux主机的安装及配置
[root@CentOS84-IP172-18 ]#hostname -I
172.16.0.18
[root@CentOS84-IP172-18 ]#cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.0.118 proxy_active
[root@CentOS84-IP172-18 ]#
[root@CentOS84-IP172-18 ]#rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/8/x86_64/zabbix-release-6.0-1.el8.noarch.rpm
[root@CentOS84-IP172-18 ]#dnf clean all
[root@CentOS84-IP172-18 ]#yum -y install zabbix-agent
[root@CentOS84-IP172-18 ]#systemctl enable --now zabbix-agent
[root@CentOS84-IP172-18 ]#grep "^[a-Z]" /etc/zabbix/zabbix_agentd.conf
PidFile=/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=192.168.250.18 #Zabbix-Server的IP地址
ServerActive=172.16.0.118 #主动模式的zabbix-proxy的IP地址
Hostname=172.16.0.18 #agent 本机地址,也可以用名称,DNS-hosts中就要做好解析
Timeout=10 # 建议用10,网上有大神说太小会报错,我没碰到
Include=/etc/zabbix/zabbix_agentd.d/*.conf
[root@CentOS84-IP172-18 ]#
[root@CentOS84-IP172-18 ]#systemctl restart zabbix-agent
## 查看日志
[root@CentOS84-IP172-18 ]#tail /var/log/zabbix/zabbix_agentd.log
8574:20220527:224432.733 IPv6 support: YES
8574:20220527:224432.733 TLS support: YES
8574:20220527:224432.733 **************************
8574:20220527:224432.733 using configuration file: /etc/zabbix/zabbix_agentd.conf
8574:20220527:224432.734 agent #0 started [main process]
8575:20220527:224432.734 agent #1 started [collector]
8576:20220527:224432.735 agent #2 started [listener #1]
8577:20220527:224432.735 agent #3 started [listener #2]
8578:20220527:224432.736 agent #4 started [listener #3]
8579:20220527:224432.737 agent #5 started [active checks #1]
[root@CentOS84-IP172-18 ]#
4. 主动代理模式 Zabbix-Proxy 安装及配置
#### DNS域名问题
## 在Zabbix-Server 和 Zabbix-Proxy 两台主机最好都加上下面地域名解析,尤其是Zabbix-Proxy 必加否则会报错,抓不到数据。
[root@CentOS84-IP172-118 ]#cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.0.118 proxy_active #这条信息容易理解
172.16.0.18 172.16.0.18 #这条不加偶尔出现错误: cannot send list of active checks to "172.16.0.18": host [172.16.0.18] not found
[root@CentOS84-IP172-118 ]#
############################################################################
#### 特别提示:Zabbix对MariaDB数据库版本有具体要求,在后来的日志提示看到是要求10.5,不符合要求服务启动不了,在日志内有相关的信息。
#### Zabbix-Proxy 数据库安装和准备
[root@CentOS84-IP172-118 ]#cat /etc/yum.repos.d/MariaDB.repo
# MariaDB 10.7 CentOS repository list - created 2022-05-08 05:20 UTC
# https://mariadb.org/download/
[mariadb]
name = MariaDB
baseurl = https://tw1.mirror.blendbyte.net/mariadb/yum/10.7/centos8-amd64
module_hotfixes=1
gpgkey=https://tw1.mirror.blendbyte.net/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1
[root@CentOS84-IP172-118 ]#
[root@CentOS84-IP172-118 ]#dnf install -y MariaDB-server
[root@CentOS84-IP172-118 ]#systemctl enable --now mariadb
[root@CentOS84-IP172-118 ]#mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.7.4-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database zabbix_proxy_active character set utf8mb4 collate utf8mb4_bin;
Query OK, 1 row affected (0.001 sec)
MariaDB [(none)]> grant all privileges on zabbix_proxy_active.* to proxy@'172.16.0.%' identified by '123456';
Query OK, 0 rows affected (0.002 sec)
## 提示:数据库的用户名尽量不要出现空,建库或者导入库容易报错
MariaDB [(none)]> select user,host from mysql.user;
+-------------+------------+
| User | Host |
+-------------+------------+
| proxy | 172.16.0.% |
| mariadb.sys | localhost |
| mysql | localhost |
| proxy | localhost |
| root | localhost |
+-------------+------------+
5 rows in set (0.208 sec)
MariaDB [(none)]> quit
Bye
[root@CentOS84-IP172-118 ]#
############################################################################
#### 安装zabbix-proxy及依赖包、工具包等
[root@CentOS84-IP172-118 ]#rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/8/x86_64/zabbix-release-6.0-1.el8.noarch.rpm
[root@CentOS84-IP172-118 ]#dnf clean all
[root@CentOS84-IP172-118 ]#yum -y install zabbix-proxy zabbix-proxy-mysql zabbix-sql-scripts zabbix-get
[root@CentOS84-IP172-118 ]#cat /usr/share/doc/zabbix-sql-scripts/mysql/proxy.sql | mysql -uproxy -p123456 -h172.16.0.118 zabbix_proxy_active
[root@CentOS84-IP172-118 ]#mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 10.7.4-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases;
+---------------------+
| Database |
+---------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test |
| zabbix_proxy_active |
+---------------------+
6 rows in set (0.124 sec)
MariaDB [(none)]> quit
[root@CentOS84-IP172-118 ]#
[root@CentOS84-IP172-118 ]#vim /etc/zabbix/zabbix_proxy.conf
[root@CentOS84-IP172-118 ]#grep "^[a-Z]" /etc/zabbix/zabbix_proxy.conf
ProxyMode=0
Server=192.168.250.18
Hostname=proxy_active
ListenPort=10051
LogFile=/var/log/zabbix/zabbix_proxy.log
LogFileSize=0
EnableRemoteCommands=1
PidFile=/run/zabbix/zabbix_proxy.pid
SocketDir=/run/zabbix
DBHost=172.16.0.118
DBName=zabbix_proxy_active
DBUser=proxy
DBPassword=123456
DBPort=3306
ProxyLocalBuffer=720
ProxyOfflineBuffer=720
HeartbeatFrequency=60
ConfigFrequency=30
DataSenderFrequency=1
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
CacheSize=1G
HistoryCacheSize=1G
HistoryIndexCacheSize=256M
Timeout=30
LogSlowQueries=3000
StatsAllowedIP=0.0.0.0/0
[root@CentOS84-IP172-118 ]#
[root@CentOS84-IP172-118 ]#systemctl start zabbix-proxy
[root@CentOS84-IP172-118 ]#tail -n50 /var/log/zabbix/zabbix_proxy.log
7387:20220527:224645.245 SSH support: YES
7387:20220527:224645.245 IPv6 support: YES
7387:20220527:224645.245 TLS support: YES
7387:20220527:224645.245 **************************
7387:20220527:224645.245 using configuration file: /etc/zabbix/zabbix_proxy.conf
7387:20220527:224645.264 Unsupported DB! MariaDB version is 100704 which is higher than maximum of 100699
7387:20220527:224645.266 current database version (mandatory/optional): 06000000/06000000
7387:20220527:224645.266 required mandatory version: 06000000
7387:20220527:224645.266 proxy #0 started [main process]
7388:20220527:224645.267 proxy #1 started [configuration syncer #1]
7389:20220527:224645.288 proxy #2 started [trapper #1]
7390:20220527:224645.289 proxy #3 started [trapper #2]
7391:20220527:224645.289 proxy #4 started [trapper #3]
7393:20220527:224645.291 proxy #6 started [trapper #5]
7394:20220527:224645.292 proxy #7 started [preprocessing manager #1]
7395:20220527:224645.293 proxy #8 started [preprocessing worker #1]
7396:20220527:224645.294 proxy #9 started [preprocessing worker #2]
7397:20220527:224645.295 proxy #10 started [preprocessing worker #3]
7392:20220527:224645.295 proxy #5 started [trapper #4]
7398:20220527:224645.295 proxy #11 started [heartbeat sender #1]
7399:20220527:224645.296 proxy #12 started [data sender #1]
7401:20220527:224645.298 proxy #14 started [http poller #1]
7402:20220527:224645.299 proxy #15 started [discoverer #1]
7403:20220527:224645.300 proxy #16 started [history syncer #1]
7405:20220527:224645.302 proxy #18 started [history syncer #3]
7406:20220527:224645.303 proxy #19 started [history syncer #4]
7407:20220527:224645.304 proxy #20 started [self-monitoring #1]
7408:20220527:224645.305 proxy #21 started [task manager #1]
7409:20220527:224645.305 proxy #22 started [poller #1]
7410:20220527:224645.306 proxy #23 started [poller #2]
7411:20220527:224645.307 proxy #24 started [poller #3]
7412:20220527:224645.308 proxy #25 started [poller #4]
7413:20220527:224645.309 proxy #26 started [poller #5]
7414:20220527:224645.310 proxy #27 started [unreachable poller #1]
7415:20220527:224645.311 proxy #28 started [icmp pinger #1]
7404:20220527:224645.311 proxy #17 started [history syncer #2]
7416:20220527:224645.312 proxy #29 started [history poller #1]
7417:20220527:224645.313 proxy #30 started [availability manager #1]
7418:20220527:224645.313 proxy #31 started [odbc poller #1]
7400:20220527:224645.314 proxy #13 started [housekeeper #1]
7388:20220527:224645.364 received configuration data from server at "192.168.250.18", datalen 18962
7388:20220527:224715.502 received configuration data from server at "192.168.250.18", datalen 18962
7388:20220527:224745.642 received configuration data from server at "192.168.250.18", datalen 18962
7388:20220527:224815.784 received configuration data from server at "192.168.250.18", datalen 18962
7388:20220527:224845.923 received configuration data from server at "192.168.250.18", datalen 18962
7388:20220527:224916.063 received configuration data from server at "192.168.250.18", datalen 18962
7388:20220527:224946.176 received configuration data from server at "192.168.250.18", datalen 18962
7388:20220527:225016.326 received configuration data from server at "192.168.250.18", datalen 18962
7388:20220527:225046.437 received configuration data from server at "192.168.250.18", datalen 18962
7388:20220527:225116.578 received configuration data from server at "192.168.250.18", datalen 18962
[root@CentOS84-IP172-118 ]#
5. 配置 Zabbix-Server -- 主动代理模式
5.1 Zabbix-Server添加主动代理
管理 --> agent代理程序 --> 创建代理:
5.2 创建主动式主机并关联模板
配置 --- 主机 --- 创建主机
5.3 zabbix_server 与代理模式相关的日志
[root@CentOS84-IP18 ]#tail -n50 /var/log/zabbix/zabbix_server.log
..............................
609389:20220527:222332.406 server #38 started [java poller #16]
609390:20220527:222332.407 server #39 started [java poller #17]
609391:20220527:222332.408 server #40 started [java poller #18]
609392:20220527:222332.409 server #41 started [java poller #19]
609393:20220527:222332.410 server #42 started [java poller #20]
609394:20220527:222332.411 server #43 started [proxy poller #1]
609395:20220527:222332.412 server #44 started [self-monitoring #1]
609396:20220527:222332.413 server #45 started [task manager #1]
609397:20220527:222332.414 server #46 started [poller #1]
609398:20220527:222332.415 server #47 started [poller #2]
609399:20220527:222332.416 server #48 started [poller #3]
609400:20220527:222332.417 server #49 started [poller #4]
609402:20220527:222332.419 server #51 started [unreachable poller #1]
609403:20220527:222332.420 server #52 started [trapper #1]
609404:20220527:222332.421 server #53 started [trapper #2]
609405:20220527:222332.422 server #54 started [trapper #3]
609406:20220527:222332.423 server #55 started [trapper #4]
609407:20220527:222332.424 server #56 started [trapper #5]
609401:20220527:222332.425 server #50 started [poller #5]
609409:20220527:222332.426 server #58 started [alert syncer #1]
609410:20220527:222332.427 server #59 started [history poller #1]
609411:20220527:222332.428 server #60 started [history poller #2]
609412:20220527:222332.429 server #61 started [history poller #3]
609413:20220527:222332.430 server #62 started [history poller #4]
609414:20220527:222332.431 server #63 started [history poller #5]
609415:20220527:222332.432 server #64 started [availability manager #1]
609416:20220527:222332.433 server #65 started [trigger housekeeper #1]
609417:20220527:222332.434 server #66 started [odbc poller #1]
609408:20220527:222332.435 server #57 started [icmp pinger #1]
609406:20220527:222349.155 sending configuration data to proxy "proxy_active" at "172.16.0.118", datalen 13548, bytes 3013 with compression ratio 4.5
609405:20220527:222419.294 sending configuration data to proxy "proxy_active" at "172.16.0.118", datalen 13548, bytes 3013 with compression ratio 4.5
609406:20220527:222449.431 sending configuration data to proxy "proxy_active" at "172.16.0.118", datalen 13548, bytes 3013 with compression ratio 4.5
609406:20220527:222519.549 sending configuration data to proxy "proxy_active" at "172.16.0.118", datalen 13548, bytes 3013 with compression ratio 4.5
609403:20220527:222549.690 sending configuration data to proxy "proxy_active" at "172.16.0.118", datalen 13548, bytes 3013 with compression ratio 4.5
609406:20220527:222619.827 sending configuration data to proxy "proxy_active" at "172.16.0.118", datalen 13548, bytes 3013 with compression ratio 4.5
609405:20220527:222649.962 sending configuration data to proxy "proxy_active" at "172.16.0.118", datalen 13548, bytes 3013 with compression ratio 4.5
609407:20220527:222720.101 sending configuration data to proxy "proxy_active" at "172.16.0.118", datalen 13548, bytes 3013 with compression ratio 4.5
609404:20220527:222750.219 sending configuration data to proxy "proxy_active" at "172.16.0.118", datalen 13548, bytes 3013 with compression ratio 4.5
609403:20220527:222755.540 sending configuration data to proxy "proxy_active" at "172.16.0.118", datalen 13548, bytes 3013 with compression ratio 4.5
609403:20220527:222825.668 sending configuration data to proxy "proxy_active" at "172.16.0.118", datalen 13548, bytes 3013 with compression ratio 4.5
609403:20220527:222854.722 sending configuration data to proxy "proxy_active" at "172.16.0.118", datalen 13548, bytes 3013 with compression ratio 4.5
609406:20220527:222924.865 sending configuration data to proxy "proxy_active" at "172.16.0.118", datalen 13548, bytes 3013 with compression ratio 4.5
609403:20220527:222954.980 sending configuration data to proxy "proxy_active" at "172.16.0.118", datalen 13548, bytes 3013 with compression ratio 4.5
609406:20220527:223025.118 sending configuration data to proxy "proxy_active" at "172.16.0.118", datalen 13548, bytes 3013 with compression ratio 4.5
609403:20220527:223055.256 sending configuration data to proxy "proxy_active" at "172.16.0.118", datalen 13548, bytes 3013 with compression ratio 4.5
609404:20220527:223125.396 sending configuration data to proxy "proxy_active" at "172.16.0.118", datalen 13548, bytes 3013 with compression ratio 4.5
609405:20220527:223155.531 sending configuration data to proxy "proxy_active" at "172.16.0.118", datalen 13548, bytes 3013 with compression ratio 4.5
609403:20220527:223225.656 sending configuration data to proxy "proxy_active" at "172.16.0.118", datalen 13548, bytes 3013 with compression ratio 4.5
609407:20220527:223255.775 sending configuration data to proxy "proxy_active" at "172.16.0.118", datalen 13548, bytes 3013 with compression ratio 4.5
609407:20220527:223311.110 sending configuration data to proxy "proxy_active" at "172.16.0.118", datalen 13548, bytes 3013 with compression ratio 4.5
6. zabbix-server web验证主机监控状态
监测 --- 主机
7. 实践总结
在做本次实验中碰到很多个坑,总结如下:
- 保证防火墙和Selinux一定要关闭,同时要保证时间和时钟一定要同步。
- 关联的主机名和IP地址对应关系建议写到所有相关的主机的hosts文件中。
- 跨网段一定要是路由方式,NAT方式特别容易出现问题,来回数据不容易搞清晰。
- 出问题一定要看日志,按照日志提示去解决问题。