news 2026/3/6 6:22:44

zabbix

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
zabbix

文章目录

  • zabbix
    • zabbix介绍
      • 当前支持版本
      • 生命周期
      • Zabbix概述
      • zabbix架构
    • 搭建LNMP架构
      • 安装nginx
        • 先测试nginx环境
      • 安装mariad
        • 配置yum源
        • 连接数据库测试
      • 安装php
        • 配置nginx支持php
        • 配置php
      • 测试
        • 测试php首页
        • 测试连接数据库
    • zabbix-server
      • **导入数据库**
      • 安装软件包
      • 修改zabbix-server配置文件
    • 被监控端
      • 安装agent
    • zabbix管理
      • 监控主机
      • 邮件服务
      • 告警服务

zabbix

zabbix介绍

zabbix官网:Zabbix:企业级开源监控解决方案

部署手册:下载Zabbix

产品手册:产品手册

以下企业都在用:

当前支持版本

生命周期

Zabbix概述

Zabbix 由 Alexei Vladishev 创建,目前由 Zabbix SIA 积极开发和维护。Zabbix 是一款企业级开源分布式监控解决方案。

Zabbix 是一款用于监控网络众多参数、服务器/虚拟机/应用程序/服务/数据库/网站/云平台等健康状态和完整性的软件。 Zabbix 提供灵活的告警机制,允许用户为几乎任何事件配置基于邮件的告警,从而实现对服务器问题的快速响应。基于存储数据, Zabbix 提供出色的报表和数据可视化功能,使其成为容量规划的理想选择。

Zabbix 同时支持轮询和捕获两种方式。所有 Zabbix 报表、统计信息及配置参数均可通过基于 Web 的前端界面访问。该 Web 前端确保您可以从任何位置评估网络状态和服务器健康状况。经过适当配置,Zabbix 可在 IT基础设施监控中发挥重要作用,无论是对拥有少量服务器的小型组织,还是对拥有众多服务器的大型企业都同样适用。

Zabbix 完全免费。 Zabbix 基于 GNU 通用公共许可证 version 第 2 版编写和分发,这意味着其源代码可自由分发并面向公众开放。

zabbix架构

Zabbix由多个主要软件组件构成。各组件职责概述如下。

服务器

Zabbixserver是核心组件,agents向其报告可用性、完整性信息及统计指标。服务器作为中央存储库,保存所有配置数据、统计数据和运行数据。数据库存储所有配置信息以及Zabbix收集的数据均存储在数据库中。

Web界面

为了从任何地方和任何平台轻松访问Zabbix,系统提供了基于Web的界面。该界面是Zabbix server的一部分,通常(但不一定)运行在与服务器相同的物理机器上。

Proxy

Zabbix proxy可以代表Zabbix server 收集性能和可用性数据。proxy是Zabbix 部署中的可选组件,但它能有效分担单个Zabbix server的负载。

Agent

Zabbixagents被部署在监控目标上,用于主动监控本地资源和应用程序,并将收集到的数据报告给Zabbix服务器。自Zabbix4.4起,有两种类型的agents可用:Zabbix agent(轻量级,支持多种平台,使用C语言编写)和Zabbix agent2 (高度灵活,易于通过插件扩展,使用Go 语言编写)。

数据流

此外,退一步审视Zabbix内部整体数据流非常重要。为了create一个收集数据的监控项,你必须先create一个主机。转到Zabbix体系的另一端,你必须先有一个监控项才能create触发器。你必须有一个触发器才能create动作。因此,如果你想收到服务器XCPU负载过高的警报,你必须先为服务器Xcreate一个主机条目,接着创建一个监控其CPU的监控项,然后设置一个在CPU过高时激活的触发器,最后配置一个发送邮件给你的动作。虽然这看起来步骤很多,但通过使用模板功能其实并不复杂。然而,正是这种设计使得create非常灵活的配置成为可能。

搭建LNMP架构

Zabbix基于LNMP架构部署

zabbix-server通过Centos-7-template模板克隆产生

mysql001通过mysql01克隆产生

主机名IP功能
zabbix-server192.168.108.50/24安装zabbix
mysql001192.168.108.51/24被监控

安装nginx

#创建nginx的yum源[root@zabbix-server ~]# rm -rf /etc/yum.repos.d/*[root@zabbix-server ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.huaweicloud.com/artifactory/os-conf/centos/centos-7.repo--2025-12-1110:20:54-- https://mirrors.huaweicloud.com/artifactory/os-conf/centos/centos-7.repo Resolving mirrors.huaweicloud.com(mirrors.huaweicloud.com)...124.70.61.162,1.92.76.132,120.46.2.67,... Connecting to mirrors.huaweicloud.com(mirrors.huaweicloud.com)|124.70.61.162|:443... connected. HTTP request sent, awaiting response...200Length:1811(1.8K)[application/octet-stream]Saving to: ‘/etc/yum.repos.d/CentOS-Base.repo’100%[===============================================>]1,811--.-K/sin0s2025-12-1110:20:54(878MB/s)- ‘/etc/yum.repos.d/CentOS-Base.repo’ saved[1811/1811][root@zabbix-server ~]# vim /etc/yum.repos.d/nginx.repo[root@zabbix-server ~]# cat /etc/yum.repos.d/nginx.repo[nginx]name=nginxrepobaseurl=http://nginx.org/packages/centos/7/$basearch/enabled=1gpgcheck=0#安装nginx[root@zabbix-server ~]# yum install -y nginx#开启服务[root@zabbix-server ~]# systemctl start nginx[root@zabbix-server ~]# systemctl enable nginxCreated symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.#防火墙添加通过http[root@zabbix-server ~]#[root@zabbix-server ~]# firewall-cmd --add-service=http --zone=publicsuccess[root@zabbix-server ~]# firewall-cmd --add-service=http --zone=public --permanentsuccess[root@zabbix-server ~]# firewall-cmd --reloadsuccess
先测试nginx环境

安装mariad

配置yum源
#配置Mariadb10.5yum源(zabbix6.0必须使用该版本,低版本不支持)[root@zabbix-server ~]# vim /etc/yum.repos.d/mariadb.repo[root@zabbix-server ~]# cat /etc/yum.repos.d/mariadb.repo[mariadb]name=MariaDBbaseurl=https://mirrors.aliyun.com/mariadb/yum/10.6/centos7-amd64/enabled=1gpgcheck=0#下载mariadb[root@zabbix-server ~]# yum install -y mariadb-server mariadb#开启服务[root@zabbix-server ~]# systemctl enable mariadb --nowCreated symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.#设置root密码[root@zabbix-server ~]# mysqlWelcome to the MariaDB monitor. Commands end with;or\g. Your MariaDB connectionidis3Server version:10.6.19-MariaDB MariaDB Server Copyright(c)2000,2018, Oracle, MariaDB Corporation Ab and others. Type'help;'or'\h'forhelp. Type'\c'toclearthe current input statement. MariaDB[(none)]>selecthost,user from mysql.user;+---------------+-------------+|Host|User|+---------------+-------------+|localhost|||localhost|mariadb.sys||localhost|mysql||localhost|root||zabbix-server||+---------------+-------------+5rowsinset(0.001sec)MariaDB[(none)]>delete from mysql.user whereUser='';Query OK,2rows affected(0.001sec)MariaDB[(none)]>selecthost,user from mysql.user;+-----------+-------------+|Host|User|+-----------+-------------+|localhost|mariadb.sys||localhost|mysql||localhost|root|+-----------+-------------+3rowsinset(0.001sec)MariaDB[(none)]>alter user root@localhost identified by'root123';Query OK,0rows affected(0.001sec)MariaDB[(none)]>quit Bye
连接数据库测试
[root@zabbix-server ~]# mysql -uroot -proot123Welcome to the MariaDB monitor. Commands end with;or\g. Your MariaDB connectionidis4Server version:10.6.19-MariaDB MariaDB Server Copyright(c)2000,2018, Oracle, MariaDB Corporation Ab and others. Type'help;'or'\h'forhelp. Type'\c'toclearthe current input statement. MariaDB[(none)]>

安装php

[root@zabbix-server ~]# yum install -y epel-release[root@zabbix-server ~]# sed -i "s/#baseurl/baseurl/g" /etc/yum.repos.d/epel.repo[root@zabbix-server ~]# sed -i "s/metalink/#metalink/g" /etc/yum.repos.d/epel.repo[root@zabbix-server ~]# sed -i "s@https\?://download.[a-z]*\.\?[a-z]*/pub@https://repo.huaweicloud.com@g" /etc/yum.repos.d/epel.repo[root@zabbix-server ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpmRetrieving https://mirror.webtatic.com/yum/el7/webtatic-release.rpm warning: /var/tmp/rpm-tmp.HIhdb2: Header V4 RSA/SHA1 Signature, key ID 62e74ca5: NOKEY Preparing...################################# [100%]Updating / installing...1:webtatic-release-7-3################################# [100%][root@zabbix-server ~]# 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
#修改php-fpm配置文件,把apache改为nginx[root@zabbix-server ~]# vim /etc/php-fpm.d/www.conf8user=nginx10group=nginx#配置location,在index中添加index.php。以支持index.php的首页[root@zabbix-server ~]# vim /etc/nginx/conf.d/default.conf9indexindex.phpindex.htmlindex.htm;#配置php请求被传送到后端的php-fpm模块,默认情况下php配置块是被注释的,此时去掉注释并修改#把fastcgi_param中的/scripts改为$document_root。root是配置php程序放置的根目录。29location~\.php${ 30 root/usr/share/nginx/html;31 fastcgi_pass 127.0.0.1:9000; 32 fastcgi_index index.php; 33 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 34 include fastcgi_params; 35 }
配置php
#修改PHP配置文件[root@zabbix-server ~]# vim /etc/php.ini#支持php短标签202short_open_tag=On#隐藏php版本359expose_php=Off#以下为zabbix优化配置要求368max_execution_time=300#执行时间378max_input_time=300#接收数据等待时间389memory_limit=128M#每个脚本占用内存656post_max_size=16M#POST数据大小799upload_max_filesize=2M#上传文件大小800always_populate_raw_post_data=-1#原来空的,需要添加877date.timezone=Asia/Shanghai#时区#启动php-fpm服务[root@zabbix-server ~]# systemctl enable php-fpm --nowCreated symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.#重启nginx[root@zabbix-server ~]# systemctl restart nginx

测试

测试php首页
[root@zabbix-server ~]# vim /usr/share/nginx/html/info.php[root@zabbix-server html]# cat info.php<?php phpinfo();?>

测试连接数据库
[root@zabbix-server html]# cat info.php<?php$link=mysqli_connect('127.0.0.1','root','root123');if($link)echo"success";elseecho"fail";?># $link=mysqli_connect('127.0.0.1','root','root123'); 设置变量$link,连接数据库# if ($link) echo "success"; 如果连接上输出success# else echo "fail"; 连接不上输出fail

# 创建zabbix用的数据库及账号 [root@zabbix-server ~]# mysql -uroot -proot123 Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 6 Server version: 10.6.19-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)]> grant all privileges on *.* to 'zabbix'@'%' identified by 'zabbix123';^C MariaDB [(none)]> create database zabbix character set utf8 collate ust8_bin; ERROR 1273 (HY000): Unknown collation: 'ust8_bin' MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin; Query OK, 1 row affected (0.000 sec) MariaDB [(none)]> show databses; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'databses' at line 1 MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | | test | | zabbix | +--------------------+ 6 rows in set (0.000 sec) MariaDB [(none)]> grant all privileges on *.* to 'zabbix'@'%' identified by 'zabbix123'; Query OK, 0 rows affected (0.001 sec) MariaDB [(none)]> grant all privileges on *.* to 'zabbix'@'localhost' identified by 'zabbix123'; Query OK, 0 rows affected (0.001 sec) MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.000 sec) MariaDB [(none)]> quit Bye

collate的作用

对于mysql中那些字符类型的列,如VARCHAR,CHAR,TEXT类型的列,都需要有一个COLLATE类型来告知mysql如何对该列进行排序和比较。COLLATE会影响到ORDER BY语句的顺序,会影响到WHERE条件中大于小于号筛选出来的结果,会影响DISTINCTGROUP BYHAVING语句的查询结果。另外,mysql建索引的时候,如果索引列是字符类型,也会影响索引创建,只不过这种影响我们感知不到。凡是涉及到字符类型比较或排序的地方,都会和COLLATE有关。

测试连接zaabix数据库

[root@zabbix-server ~]# vim /usr/share/nginx/html/info.php[root@zabbix-server ~]# cat /usr/share/nginx/html/info.php<?php$link=mysqli_connect('127.0.0.1','zabbix','zabbix123');if($link)echo"zabbix数据库连接成功";elseecho"zabbix数据库连接失败";?>

测试

zabbix-server

导入数据库

#解压[root@zabbix-server ~]# lsanaconda-ks.cfg initial-setup-ks.cfg Public Desktop Music Templates Documents nginx-release-centos-7-0.el7.ngx.noarch.rpm Videos Downloads Pictures zabbix-6.0.6.tar.gz[root@zabbix-server ~]# tar zxvf zabbix-6.0.6.tar.gz#导入数据库#将该目录的数据库导入zabbix数据库[root@zabbix-server ~]# cd /root/zabbix-6.0.6/database/mysql/[root@zabbix-server mysql]# lsdata.sql history_pk_prepare.sql Makefile.am schema.sql double.sql images.sql Makefile.in[root@zabbix-server mysql]# mysql -uroot -proot123 zabbix < schema.sql[root@zabbix-server mysql]# mysql -uroot -proot123 zabbix < images.sql[root@zabbix-server mysql]# mysql -uroot -proot123 zabbix < data.sql[root@zabbix-server mysql]# mysql -uroot -proot123 zabbix < double.sql[root@zabbix-server mysql]# mysql -uroot -proot123 zabbix < history_pk_prepare.sql#进入zabbix数据库查看[root@zabbix-server mysql]# mysql -uroot -proot123Welcome to the MariaDB monitor. Commands end with;or\g. Your MariaDB connectionidis16Server version:10.6.19-MariaDB MariaDB Server Copyright(c)2000,2018, Oracle, MariaDB Corporation Ab and others. Type'help;'or'\h'forhelp. Type'\c'toclearthe current input statement. MariaDB[(none)]>use zabbix;Reading table informationforcompletion of table andcolumnnames You can turn off this feature to get a quicker startup with -A Database changed 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|+----------------------------+`178rows`inset(0.001sec)#是178条MariaDB[zabbix]>quit Bye

安装软件包

#安装zabbix环境包[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# 创建zabbix用户[root@zabbix-server mysql]# useradd -s /sbin/nologin -M zabbix#使得编译器在编译 C 代码时使用 GNU C99 标准[root@zabbix-server mysql]# export CFLAGS="-std=gnu99"#执行configure脚本[root@zabbix-server mysql]# cd[root@zabbix-server ~]# cd zabbix-6.0.6/[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#安装[root@zabbix-server ~]# make install#检查版本[root@zabbix-server ~]# zabbix_server --versionzabbix_server(Zabbix)6.0.6 Revision 3f7597e3ea327June2022, compilation time: Dec11202514:01:17 Copyright(C)2022Zabbix SIA License GPLv2+: GNU GPL version2or later<http://gnu.org/licenses/gpl.html>. This isfreesoftware: you arefreeto 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 Projectforuseinthe OpenSSL Toolkit(http://www.openssl.org/). Compiled with OpenSSL1.0.2k-fips26Jan2017Running with OpenSSL1.0.2k-fips26Jan2017

修改zabbix-server配置文件

[root@zabbix-server ~]# vim /etc/zabbix/zabbix_server.conf38LogFile=/var/log/zabbix_server.log123DBPassword=zabbix123#创建日志文件并修改属组和属主[root@zabbix-server ~]# touch /var/log/zabbix_server.log[root@zabbix-server ~]# chown zabbix.zabbix /var/log/zabbix_server.log#创建并添加systemctl服务管理zabbix-server[root@zabbix-server ~]# vim /usr/lib/systemd/system/zabbix-server.service[root@zabbix-server ~]# cat /usr/lib/systemd/system/zabbix-server.service#添加下面这段话,直接复制[Unit]Description=Zabbix Server with MySQL DBAfter=syslog.target network.target mysqld.service[Service]Type=simpleExecStart=/usr/local/sbin/zabbix_server -fUser=zabbix[Install]WantedBy=multi-user.target#启动zabbix[root@zabbix-server ~]# systemctl start zabbix-server.service[root@zabbix-server ~]# netstat -ntap |grep 10051tcp000.0.0.0:100510.0.0.0:* LISTEN65150/zabbix_server

前端页面复制到站点

[root@zabbix-server ~]# cp -r /root/zabbix-6.0.6/ui/* /usr/share/nginx/html/#提供网站前面[root@zabbix-server ~]# chown -R nginx:nginx /usr/share/nginx/html/

http://192.168.108.50

默认登陆用户名:Admin

默认登陆密码:zabbix

被监控端

安装agent

通过前面mysql章节的mysql01克隆mysql001

[root@mysql001 ~]# systemctl status firewalld.service● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded(/usr/lib/systemd/system/firewalld.service;disabled;vendor preset: enabled)Active: inactive(dead)Docs: man:firewalld(1)[root@mysql001 ~]# systemctl stop firewalld.service[root@mysql001 ~]# setenforce 0setenforce: SELinux is disabled[root@mysql001 ~]# rm -rf /etc/yum.repos.d/*.repo[root@mysql001 ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.huaweicloud.com/artifactory/os-conf/centos/centos-7.repo--2025-12-1114:55:24-- https://mirrors.huaweicloud.com/artifactory/os-conf/centos/centos-7.repo Resolving mirrors.huaweicloud.com(mirrors.huaweicloud.com)...123.249.118.101,124.70.61.162,1.92.76.132,... Connecting to mirrors.huaweicloud.com(mirrors.huaweicloud.com)|123.249.118.101|:443... connected. HTTP request sent, awaiting response...200Length:1811(1.8K)[application/octet-stream]Saving to: ‘/etc/yum.repos.d/CentOS-Base.repo’100%[===============================================>]1,811--.-K/sin0s2025-12-1114:55:26(190MB/s)- ‘/etc/yum.repos.d/CentOS-Base.repo’ saved[1811/1811]#更新CA[root@mysql001 ~]# yum update ca-certificates -y#安装软件包[root@mysql001 ~]# rpm -ivh https://repo.zabbix.com/zabbix/6.0/rhel/7/x86_64/zabbix-release-6.0-4.el7.noarch.rpmRetrieving https://repo.zabbix.com/zabbix/6.0/rhel/7/x86_64/zabbix-release-6.0-4.el7.noarch.rpm warning: /var/tmp/rpm-tmp.sAb6Z7: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY Preparing...################################# [100%]Updating / installing...1:zabbix-release-6.0-4.el7################################# [100%][root@mysql001 ~]# yum install zabbix-agent2 -y#启动服务[root@mysql001 ~]# systemctl enable zabbix-agent2.service --nowCreated symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent2.service to /usr/lib/systemd/system/zabbix-agent2.service.#修改配置文件[root@mysql001 ~]# vim /etc/zabbix/zabbix_agent2.conf13PidFile=/var/run/zabbix/zabbix_agent2.pid32LogFile=/var/log/zabbix/zabbix_agent2.log43LogFileSize=082Server=192.168.108.50#指向监控服务器135ServerActive=192.168.108.50#指向监控服务器146Hostname=mysql001#名称283Include=/etc/zabbix/zabbix_agent2.d/*.conf#重启服务(先不重启看看配置生效不)[root@mysql001 zabbix_agent2.d]# systemctl restart zabbix-agent2.service

zabbix管理

http://192.168.108.50

监控主机

zabbix首页登录后

邮件服务

记下

在zabbix-server服务器上安装邮箱服务

[root@zabbix-server ~]# yum install -y mailxLoaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile Package mailx-12.5-19.el7.x86_64 already installed and latest version Nothing todo

配置邮箱服务

[root@zabbix-server ~]# vim /etc/mail.rc[root@zabbix-server ~]# tail -n 10 /etc/mail.rc----文件末尾新增---setfrom=3186973288@qq.comsetsmtp=smtps://smtp.qq.com:465setsmtp-auth-user=3186973288@qq.comsetsmtp-auth-password=#qq授权码setsmtp-auth=login#set smtp-use-starttls 这里是不需要配置的,很多地方没说明,配置了反而会验证失败,所以我注释掉;setssl-verify=ignoresetnss-config-dir=/root/.certs#制定的存放QQ邮箱SSL证书的位置。setnss-config-dir=/etc/pki/nssdb/[root@zabbix-server ~]# chmod -R 755 /etc/pki/nssdb/

因为需要QQ邮箱的SSL证书,所以我们还需要手动的获取QQ邮箱的证书保存到本地指定的目录里以备调用和验证,具体命令如下:

[root@zabbix-server ~]# mkdir -p /root/.certs/[root@zabbix-server ~]# echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGINCERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/qq.crtdepth=2C=US, O=DigiCert Inc, OU=www.digicert.com, CN=DigiCert Global Root G2 verify return:1depth=1C=US, O="DigiCert, Inc.", CN=DigiCert Secure Site OV G2 TLS CN RSA4096 SHA2562022CA1 verify return:1depth=0C=CN, ST=Guangdong Province, L=Shenzhen, O=Shenzhen Tencent Computer Systems Company Limited, CN=*.mail.qq.com verify return:1 DONE[root@zabbix-server ~]# certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crtcertutil: could not decode certificate: SEC_ERROR_INVALID_ARGS: security library: invalid arguments.[root@zabbix-server ~]# certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crtcertutil: could not decode certificate: SEC_ERROR_INVALID_ARGS: security library: invalid arguments.[root@zabbix-server ~]# certutil -L -d /root/.certsCertificate Nickname Trust Attributes SSL,S/MIME,JAR/XPI

为了防止出现前文所说的发送邮件警告提示,还需要进入邮箱SSL证书存放目录 /root/.certs 里执行如下命令:

[root@zabbix-server ~]# cd /root/.certs/[root@zabbix-server .certs]# certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i qq.crtNotice: Trust flag u issetautomaticallyifthe private key is present. certutil: could not decode certificate: SEC_ERROR_INVALID_ARGS: security library: invalid arguments.

这是为了信任证书的标记操作。

至此,已经完成了mailx结合QQ邮箱发送系统邮件的部署了,通过命令行发送测试邮件试试吧:

# 执行命令后,进入交互式编辑,输入正文后按 Ctrl+D 结束并发送\[root@zabbix-server .certs]# mailx -s "test" 3186973288@qq.comhhh123DEOT[root@zabbix-server .certs]# Error in certificate: Peer's certificate issuer is not recognized.smtp-server:"/root/dead.letter"0/0...message not sent.

前往QQ邮箱查收测试邮件

创建脚本目录,并重启zabbix服务

[root@zabbix-server .certs]# vim /etc/zabbix/zabbix_server.conf548AlertScriptsPath=/usr/lib/zabbix/alertscripts[root@zabbix-server .certs]# mkdir -p /usr/lib/zabbix/alertscripts[root@zabbix-server .certs]# chown -R zabbix:zabbix /usr/lib/zabbix/alertscripts[root@zabbix-server .certs]# systemctl restart zabbix-server.service

编写邮件发送脚本

[root@zabbix-server .certs]# vim /usr/lib/zabbix/alertscripts/mailx.sh[root@zabbix-server .certs]# cat /usr/lib/zabbix/alertscripts/mailx.sh#!/bin/bash#send mailmessages=`echo$3|tr'\r\n''\n'`subject=`echo$2|tr'\r\n''\n'`echo"${messages}"|mail -s"${subject}"$1>>/tmp/mailx.log2>&1

权限设置

[root@zabbix-server .certs]# touch /tmp/mailx.log[root@zabbix-server .certs]# chown -R zabbix.zabbix /tmp/mailx.log[root@zabbix-server .certs]# cd[root@zabbix-server ~]# chmod +x /usr/lib/zabbix/alertscripts/mailx.sh

测试脚本发送邮件

[root@zabbix-server ~]# cd /usr/lib/zabbix/alertscripts/[root@zabbix-server alertscripts]# ./mailx.sh 3186973288@qq.com "hello mailx.sh" "This is test"

已收到邮件

告警服务

管理->报警媒介类型>创建媒体类型

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/3/5 1:26:18

【VSCode量子作业监控面板揭秘】:掌握未来开发的黑科技工具

第一章&#xff1a;VSCode量子作业监控面板揭秘VSCode 作为现代开发者的核心工具&#xff0c;其扩展能力在量子计算领域也展现出强大潜力。通过集成量子开发套件&#xff08;如 QDK&#xff09;&#xff0c;开发者可在编辑器内实时监控量子作业的执行状态&#xff0c;实现从代码…

作者头像 李华
网站建设 2026/2/27 12:03:04

SCHNEIDER BSH0702P01F2A 模块

SCHNEIDER BSH0702P01F2A 是施耐德电气&#xff08;Schneider Electric&#xff09;生产的一款工业自动化产品&#xff0c;属于其模块化 I/O 系统的一部分。该产品通常用于工业控制系统中&#xff0c;提供信号采集、处理和传输功能。主要特性型号&#xff1a;BSH0702P01F2A品牌…

作者头像 李华
网站建设 2026/2/28 6:12:30

2、Cocos2D游戏开发入门指南

Cocos2D游戏开发入门指南 1. 了解Cocos2D 在深入游戏开发的有趣世界之前&#xff0c;我们需要花些时间了解Cocos2D是什么&#xff0c;它如何帮助我们开发游戏&#xff0c;以及为什么要选择它。以下是我们将回顾的要点&#xff1a; - 什么是游戏引擎&#xff0c;以及为什么要使…

作者头像 李华
网站建设 2026/3/4 17:57:09

1位数码管模拟值实验萌新速成大法

文章目录 1.前言2.欣赏成果3.安装对应软件网址arduino.cc/en/software 4.学习软件的使用安装结束&#xff0c;我们进入首页**选择我们对应的开发板Arduino UNO**选择之后就会将UNO开发板作为默认**&#xff08;UNO开发板适合初学者简单易上手&#xff09;**并将开发板连接到电脑…

作者头像 李华
网站建设 2026/3/3 17:15:29

突破自动驾驶感知瓶颈:HunyuanWorld-Mirror引领3D环境建模新范式

在自动驾驶技术飞速发展的今天&#xff0c;环境感知的精准性与实时性始终是制约系统安全性的核心挑战。如何让智能驾驶系统像人类驾驶员一样&#xff0c;通过多源信息融合构建出动态、立体的周边环境认知&#xff1f;HunyuanWorld-Mirror开源项目给出了创新性答案。这款由腾讯混…

作者头像 李华
网站建设 2026/3/3 18:40:39

LeetCode 427:Construct Quad Tree 题解与两种思路对比

LeetCode 427 要求&#xff1a;给定一个只包含 0 和 1 的 nn 矩阵 grid&#xff0c;用四叉树来表示这个矩阵&#xff0c;并返回四叉树的根节点。 四叉树中每个内部节点恰好有 4 个子节点&#xff08;左上、右上、左下、右下&#xff09;&#xff0c;每个节点包含两个关键属性&a…

作者头像 李华