Zabbix企业级分布式监控系统(上)

Zabbix企业级分布式监控系统

概念

Zabbix 是一款开源的企业级分布式监控系统,专注于对 IT 基础设施(服务器、网络设备、云资源、应用程序等)的全面监控、告警和可视化,广泛应用于企业运维、云平台管理等场景。其核心优势在于功能全面、可扩展性强、支持多平台,且完全开源免费。

Zabbix 核心功能

  1. 全方位监控能力
    • 硬件监控:CPU、内存、磁盘、网卡等服务器硬件指标。
    • 系统监控:Linux、Windows、AIX 等操作系统的进程、负载、文件系统、服务状态等。
    • 网络监控:通过 SNMP、ICMP、TCP/UDP 等协议监控交换机、路由器、防火墙的带宽、端口状态、丢包率等。
    • 应用监控:支持 MySQL、Nginx、Java(JMX)、Docker、Kubernetes 等主流应用 / 容器,可监控连接数、响应时间、错误率等业务指标。
    • 自定义监控:通过脚本(Shell、Python 等)、API 接口采集业务数据(如订单量、用户在线数),灵活适配个性化需求。
  2. 智能告警机制
    • 基于阈值触发告警(如 CPU 使用率 > 90%、服务宕机),支持多级别告警(信息、警告、严重、灾难)。
    • 丰富的告警媒介:邮件、短信、企业微信、钉钉、Slack、Webhook 等,可自定义告警内容和接收对象。
    • 告警升级与抑制:未及时处理的告警自动通知上级;避免短时间内重复告警(如波动导致的频繁触发)。
  3. 可视化与报表
    • 直观的 Web 控制台:实时展示监控数据、拓扑图、仪表盘(Dashboard),支持自定义视图。
    • 图表分析:趋势图、饼图、柱状图等,可查看历史数据(分钟级、小时级、天级),辅助容量规划和问题溯源。
    • 自动生成报表:监控数据统计、告警汇总等,支持导出 PDF/CSV。
  4. 分布式架构支持
    • 适合大规模监控场景(上万台设备),通过 Zabbix Proxy 实现区域级数据汇聚,减轻 Server 压力,优化跨机房网络传输。
    • 支持高可用部署(Server 集群),避免单点故障。

Zabbix 核心组件

  1. Zabbix Server

    系统核心,负责接收监控数据、存储(依赖数据库,如 MySQL、PostgreSQL)、分析数据、触发告警、管理配置等。

  2. Zabbix Agent

    安装在被监控设备上的轻量客户端,负责采集本地数据(如 CPU、内存),通过主动 / 被动模式与 Server/Proxy 通信(默认端口 10050)。

Zabbix 的基本监控流程:Agent采集数据 → 发送给Server/Proxy → Server存储到数据库 → 分析数据触发告警 → Web界面展示

环境部署

bash 复制代码
需要两台虚拟机
zabbix-server
zabbix-agent

安装nginx(zabbix-server下面安装)

bash 复制代码
#配置主机名
hostnamectl set-hostname zabbix-server

#防火墙、selinux
systemctl disable firewalld.service
setenforce 0

#创建nginx的yum源
vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

#安装nginx
yum install -y nginx

#开启服务
systemctl start nginx 
systemctl enable nginx

去浏览器测试nginx是否安装成功

安装数据库

bash 复制代码
#配置Mariadb10.5 yum源
vim /etc/yum.repos.d/mariadb.repo
[mariadb]
name = MariaDB
baseurl = https://archive.mariadb.org/mariadb-10.5.23/yum/centos7-amd64/
gpgkey=https://archive.mariadb.org/mariadb-10.5.23/yum/centos7-amd64/RPM-GPG-KEY-MariaDB
gpgcheck=0

#安装mariadb
yum -y install mariadb-server mariadb

#开启服务             
systemctl enable mariadb --now

#自定义设置root密码
mysql_secure_installation
yy 设置密码 nnny

安装php

bash 复制代码
#安装php
yum -y install epel-release
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-gd php72w-mbstring php72w-pdo php72w-xml php72w-fpm php72w-mysqlnd php72w-opcache php72w-ldap php72w-bcmath

配置nginx支持php

bash 复制代码
#修改php-fpm配置文件,把apache改为nginx
vim /etc/php-fpm.d/www.conf 
//8行 user = nginx
//10行 group = nginx

#配置location,在index中添加index.php。以支持index.php的首页
vim /etc/nginx/conf.d/default.conf 
//9行  index  index.php index.html index.htm;
//配置php请求被传送到后端的php-fpm模块,默认情况下php配置块是被注释的,此时去掉注释并修改
//把fastcgi_param中的/scripts改为$document_root。root是配置php程序放置的根目录。
//29~35行     
location ~ \.php$ {
          root           /usr/share/nginx/html;
          fastcgi_pass   127.0.0.1:9000;
          fastcgi_index  index.php; 
          fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
          include        fastcgi_params;
      }


#配置php
#修改PHP配置文件
vim /etc/php.ini

//359 expose_php = Off    //隐藏php版本
//202 short_open_tag = On   //支持php短标签

//以下为zabbix优化配置要求
//368 max_execution_time = 300  //执行时间
//378 max_input_time = 300    //接收数据等待时间
//389 memory_limit = 128M    //每个脚本占用内存
//656 post_max_size = 16M    //POST数据大小
//799 upload_max_filesize = 2M //上传文件大小
//800 always_populate_raw_post_data = -1  //需要添加可以用 $HTTP_RAW_POST_DATA 接收post raw data(原始未处理数据)
//877 date.timezone = Asia/Shanghai  //时区

启动php-fpm服务

bash 复制代码
systemctl enable php-fpm --now
# 重启nginx
systemctl restart nginx

首页文件

bash 复制代码
vim /usr/share/nginx/html/info.php
<?php
 phpinfo();
?>

测试连接数据库

bash 复制代码
[root@zabbix-server ~]# cd /usr/share/nginx/html/
[root@zabbix-server html]# vim index.php 
[root@zabbix-server html]# cat index.php 
<?php
 $link=mysqli_connect('127.0.0.1','root','123');
 if ($link) echo "连接成功 !!!";
 else echo "连接失败 !!!";
?>

数据库内创建database和用户

bash 复制代码
[root@zabbix-server html]# mysql -u root -p123
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 17
Server version: 10.5.23-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 |
| test               |
+--------------------+
4 rows in set (0.003 sec)

MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.001 sec)

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
| zabbix             |
+--------------------+
5 rows in set (0.000 sec)

MariaDB [(none)]> grant all privileges on *.* to 'zabbix'@'%'identified by 'admin123';
Query OK, 0 rows affected (0.004 sec)

MariaDB [(none)]> grant all privileges on *.* to 'zabbix'@'localhost'identified by 'admin123';
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> exit
Bye

再次修改首页文件,看zabbix能否连接成功

bash 复制代码
[root@zabbix-server html]# vim index.php 
[root@zabbix-server html]# cat index.php 
<?php
 $link=mysqli_connect('127.0.0.1','zabbix','admin123');
 if ($link) echo "zabbix连接成功 !!!";
 else echo "zabbix连接失败 !!!";
?>

去浏览器访问网站:http://192.168.100.66/index.php

使用zabbix

导入数据库

把文件拖进来解压然后进入文件夹中把数据导入进数据库zabbix中

bash 复制代码
[root@zabbix-server ~]# rz -E
rz waiting to receive.
[root@zabbix-server ~]# ls
anaconda-ks.cfg  Downloads             nginx-release-centos-7-0.el7.ngx.noarch.rpm  Templates
Desktop          initial-setup-ks.cfg  Pictures                                     Videos
Documents        Music                 Public                                       zabbix-6.0.6.tar.gz

[root@zabbix-server ~]# tar zxvf zabbix-6.0.6.tar.gz
[root@zabbix-server ~]# cd /root/zabbix-6.0.6/
[root@zabbix-server zabbix-6.0.6]# cd database/
[root@zabbix-server database]# ls
elasticsearch  Makefile.am  Makefile.in  mysql  oracle  postgresql  sqlite3

[root@zabbix-server database]# cd mysql/
[root@zabbix-server mysql]# 
[root@zabbix-server mysql]# 
[root@zabbix-server mysql]# ls
data.sql  double.sql  history_pk_prepare.sql  images.sql  Makefile.am  Makefile.in  schema.sql
[root@zabbix-server mysql]# mysql -u root -p123 zabbix < schema.sql
[root@zabbix-server mysql]# mysql -u root -p123 zabbix < images.sql
[root@zabbix-server mysql]# mysql -u root -p123 zabbix < data.sql
[root@zabbix-server mysql]# mysql -u root -p123 zabbix < double.sql
[root@zabbix-server mysql]# mysql -u root -p123 zabbix < history_pk_prepare.sql

检查有没有导入成功

bash 复制代码
[root@zabbix-server mysql]# mysql -u root -p123
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 25
Server version: 10.5.23-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 |
| test               |
| zabbix             |
+--------------------+
5 rows in set (0.000 sec)

MariaDB [(none)]> use zabbix;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

MariaDB [zabbix]> show tables;
+----------------------------+
| Tables_in_zabbix           |
+----------------------------+
| acknowledges               |
| actions                    |
| alerts                     |
| auditlog                   |
| autoreg_host               |
| conditions                 |
| config                     |
| config_autoreg_tls         |
| corr_condition             |
| corr_condition_group       |
| corr_condition_tag         |
| corr_condition_tagpair     |
| corr_condition_tagvalue    |
| corr_operation             |
| correlation                |
| dashboard                  |
| dashboard_page             |
| dashboard_user             |
| dashboard_usrgrp           |
| dbversion                  |
| dchecks                    |
| dhosts                     |
| drules                     |
| dservices                  |
| escalations                |
| event_recovery             |
| event_suppress             |
| event_tag                  |
| events                     |
| expressions                |
| functions                  |
| globalmacro                |
| globalvars                 |
| graph_discovery            |
| graph_theme                |
| graphs                     |
| graphs_items               |
| group_discovery            |
| group_prototype            |
| ha_node                    |
| history                    |
| history_log                |
| history_log_old            |
| history_old                |
| history_str                |
| history_str_old            |
| history_text               |
| history_text_old           |
| history_uint               |
| history_uint_old           |
| host_discovery             |
| host_inventory             |
| host_tag                   |
| hostmacro                  |
| hosts                      |
| hosts_groups               |
| hosts_templates            |
| housekeeper                |
| hstgrp                     |
| httpstep                   |
| httpstep_field             |
| httpstepitem               |
| httptest                   |
| httptest_field             |
| httptest_tag               |
| httptestitem               |
| icon_map                   |
| icon_mapping               |
| ids                        |
| images                     |
| interface                  |
| interface_discovery        |
| interface_snmp             |
| item_condition             |
| item_discovery             |
| item_parameter             |
| item_preproc               |
| item_rtdata                |
| item_tag                   |
| items                      |
| lld_macro_path             |
| lld_override               |
| lld_override_condition     |
| lld_override_opdiscover    |
| lld_override_operation     |
| lld_override_ophistory     |
| lld_override_opinventory   |
| lld_override_opperiod      |
| lld_override_opseverity    |
| lld_override_opstatus      |
| lld_override_optag         |
| lld_override_optemplate    |
| lld_override_optrends      |
| maintenance_tag            |
| maintenances               |
| maintenances_groups        |
| maintenances_hosts         |
| maintenances_windows       |
| media                      |
| media_type                 |
| media_type_message         |
| media_type_param           |
| module                     |
| opcommand                  |
| opcommand_grp              |
| opcommand_hst              |
| opconditions               |
| operations                 |
| opgroup                    |
| opinventory                |
| opmessage                  |
| opmessage_grp              |
| opmessage_usr              |
| optemplate                 |
| problem                    |
| problem_tag                |
| profiles                   |
| proxy_autoreg_host         |
| proxy_dhistory             |
| proxy_history              |
| regexps                    |
| report                     |
| report_param               |
| report_user                |
| report_usrgrp              |
| rights                     |
| role                       |
| role_rule                  |
| script_param               |
| scripts                    |
| service_alarms             |
| service_problem            |
| service_problem_tag        |
| service_status_rule        |
| service_tag                |
| services                   |
| services_links             |
| sessions                   |
| sla                        |
| sla_excluded_downtime      |
| sla_schedule               |
| sla_service_tag            |
| sysmap_element_trigger     |
| sysmap_element_url         |
| sysmap_shape               |
| sysmap_url                 |
| sysmap_user                |
| sysmap_usrgrp              |
| sysmaps                    |
| sysmaps_element_tag        |
| sysmaps_elements           |
| sysmaps_link_triggers      |
| sysmaps_links              |
| tag_filter                 |
| task                       |
| task_acknowledge           |
| task_check_now             |
| task_close_problem         |
| task_data                  |
| task_remote_command        |
| task_remote_command_result |
| task_result                |
| timeperiods                |
| token                      |
| trends                     |
| trends_uint                |
| trigger_depends            |
| trigger_discovery          |
| trigger_queue              |
| trigger_tag                |
| triggers                   |
| users                      |
| users_groups               |
| usrgrp                     |
| valuemap                   |
| valuemap_mapping           |
| widget                     |
| widget_field               |
+----------------------------+
178 rows in set (0.003 sec)

安装环境包

bash 复制代码
[root@zabbix-server mysql]# yum install -y mysql-devel pcre-devel openssl-devel zlib-devel libxml2-devel net-snmp-devel net-snmp libssh2-devel OpenIPMI-devel libevent-devel openldap-devel libcurl-devel fping gcc gcc-c++ make

创建程序用户

bash 复制代码
[root@zabbix-server mysql]# useradd -s /sbin/nglogin -M zabbix
[root@zabbix-server mysql]# id zabbix
uid=1001(zabbix) gid=1001(zabbix) groups=1001(zabbix)

[root@zabbix-server mysql]# cd
[root@zabbix-server ~]# 
[root@zabbix-server ~]# 
[root@zabbix-server ~]# cd zabbix-6.0.6/

[root@zabbix-server zabbix-6.0.6]# export CFLAGS="-std=gnu99"

#编译安装
[root@zabbix-server zabbix-6.0.6]# ./configure --sysconfdir=/etc/zabbix/ --enable-server --with-mysql --with-net-snmp --with-libxml2 --with-ssh2 --with-openipmi --with-zlib --with-libpthread --with-libevent --with-openssl --with-ldap --with-libcurl --with-libpcre
bash 复制代码
#安装
[root@zabbix-server zabbix-6.0.6]# make install

#查看版本
[root@zabbix-server zabbix-6.0.6]# zabbix_server --version
zabbix_server (Zabbix) 6.0.6
Revision 3f7597e3ea3 27 June 2022, compilation time: Nov  5 2025 15:17:48

Copyright (C) 2022 Zabbix SIA
License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it according to
the license. There is NO WARRANTY, to the extent permitted by law.

This product includes software developed by the OpenSSL Project
for use in the OpenSSL Toolkit (http://www.openssl.org/).

Compiled with OpenSSL 1.0.2k-fips  26 Jan 2017
Running with OpenSSL 1.0.2k-fips  26 Jan 2017

修改配置文件

bash 复制代码
[root@zabbix-server zabbix-6.0.6]# vim /etc/zabbix/zabbix_server.conf

创建日志文件并修改属组和属主

bash 复制代码
[root@zabbix-server zabbix-6.0.6]# touch /var/log/zabbix_server.log
[root@zabbix-server zabbix-6.0.6]# chown zabbix.zabbix /var/log/zabbix_server.log
[root@zabbix-server zabbix-6.0.6]# ll /var/log/zabbix_server.log 
-rw-r--r-- 1 zabbix zabbix 0 Nov  5 15:20 /var/log/zabbix_server.log

启动zabbix-server

bash 复制代码
[root@zabbix-server zabbix-6.0.6]# vim /usr/lib/systemd/system/zabbix-server.service
[root@zabbix-server zabbix-6.0.6]# cat /usr/lib/systemd/system/zabbix-server.service
[Unit]
Description=Zabbix Server with MySQL DB
After=syslog.target network.target mysqld.service

[Service]
Type=simple
ExecStart=/usr/local/sbin/zabbix_server -f
User=zabbix

[Install]
WantedBy=multi-user.target


[root@zabbix-server zabbix-6.0.6]# systemctl start zabbix-server.service
[root@zabbix-server zabbix-6.0.6]# netstat -ntap | grep 10051
tcp        0      0 0.0.0.0:10051           0.0.0.0:*               LISTEN      14524/zabbix_server 

前端页面复制到站点

bash 复制代码
[root@zabbix-server zabbix-6.0.6]# cp -r /root/zabbix-6.0.6/ui/* /usr/share/nginx/html/
cp: overwrite '/usr/share/nginx/html/index.php'? y
[root@zabbix-server zabbix-6.0.6]# chown -R nginx:nginx /usr/share/nginx/html/

浏览器访问网站:192.168.100.66

访问zabbix前端

外链图片转存中...(img-QLN4NZCp-1762338898646)



账号:Admin

密码:zabbix


被监控端部署agent

bash 复制代码
#更新CA
[root@localhost ~]# yum update -y ca-certificates

#安装软件包
[root@localhost ~]# rpm -ivh https://repo.zabbix.com/zabbix/6.0/rhel/7/x86_64/zabbix-release-6.0-4.el7.noarch.rpm

[root@localhost ~]# yum install -y zabbix-agent2


#启动服务
[root@localhost ~]# systemctl enable zabbix-agent2.service --now
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent2.service to /usr/lib/systemd/system/zabbix-agent2.service.

#修改配置文件
[root@localhost ~]# vim /etc/zabbix/zabbix_agent2.conf 
13行 PidFile=/var/run/zabbix/zabbix_agent2.pid
32行 LogFile=/var/log/zabbix/zabbix_agent2.log
43行 LogFileSize=0
82行 Server=192.168.100.66           //指向监控服务器
135行 ServerActive=192.168.100.66   //指向监控服务器
146行 Hostname=test     //名称
283行 Include=/etc/zabbix/zabbix_agent2.d/*.conf

#查看状态
[root@localhost ~]# systemctl status zabbix-agent2.service 
● zabbix-agent2.service - Zabbix Agent 2
   Loaded: loaded (/usr/lib/systemd/system/zabbix-agent2.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2025-11-05 16:11:39 CST; 2min 57s ago
 Main PID: 2158 (zabbix_agent2)
   CGroup: /system.slice/zabbix-agent2.service
           └─2158 /usr/sbin/zabbix_agent2 -c /etc/zabbix/zabbix_agent2.conf

Nov 05 16:11:39 localhost.localdomain systemd[1]: Started Zabbix Agent 2.
Nov 05 16:11:39 localhost.localdomain systemd[1]: Starting Zabbix Agent 2...
Nov 05 16:11:39 localhost.localdomain zabbix_agent2[2158]: Starting Zabbix Agent 2 (6.0.42)
Nov 05 16:11:39 localhost.localdomain zabbix_agent2[2158]: Zabbix Agent2 hostname: [Zabbix server]
Nov 05 16:11:39 localhost.localdomain zabbix_agent2[2158]: Press Ctrl+C to exit.

ive: active (running) since Wed 2025-11-05 16:11:39 CST; 2min 57s ago

Main PID: 2158 (zabbix_agent2)

CGroup: /system.slice/zabbix-agent2.service

└─2158 /usr/sbin/zabbix_agent2 -c /etc/zabbix/zabbix_agent2.conf

Nov 05 16:11:39 localhost.localdomain systemd[1]: Started Zabbix Agent 2.

Nov 05 16:11:39 localhost.localdomain systemd[1]: Starting Zabbix Agent 2...

Nov 05 16:11:39 localhost.localdomain zabbix_agent2[2158]: Starting Zabbix Agent 2 (6.0.42)

Nov 05 16:11:39 localhost.localdomain zabbix_agent2[2158]: Zabbix Agent2 hostname: [Zabbix server]

Nov 05 16:11:39 localhost.localdomain zabbix_agent2[2158]: Press Ctrl+C to exit.

复制代码
相关推荐
现在,此刻2 小时前
李沐深度学习笔记D1-什么是深度学习
人工智能·笔记·深度学习
猿来是你_L4 小时前
UGUI笔记——3D坐标转换成UGUI坐标
笔记·3d
崎岖Qiu9 小时前
【设计模式笔记17】:单例模式1-模式分析
java·笔记·单例模式·设计模式
Chloeis Syntax10 小时前
MySQL初阶学习日记(1)--- 数据库的基本操作
数据库·学习·mysql
lkbhua莱克瓦2410 小时前
Java练习-正则表达式 1
java·笔记·正则表达式·github
musenh10 小时前
css样式学习
css·学习·css3
Larry_Yanan11 小时前
QML学习笔记(五十)QML与C++交互:QML中单例C++对象
开发语言·c++·笔记·qt·学习·ui·交互
im_AMBER11 小时前
算法笔记 09
c语言·数据结构·c++·笔记·学习·算法·排序算法
牛奶咖啡1311 小时前
zabbix实现监控Hadoop、Docker、SSL证书过期时间应用的保姆级实操流程
hadoop·zabbix·docker-ce引擎安装·监控docker容器·监控ssl证书的过期时间·监控hadoop·安装配置agent2