Zabbix4.x 历史数据存储到Elasticsearch7.x
一、简介
Zabbix 3.4.6 版本开始支持历史数据存储到 Elasticsearch, 早就想测试这个功能,最近有个需求需保存 zabbix 的历史数据上达十亿条,因此决定测试这功能的实用性,事实证明确实效果挺好。从今以后 zabbix 也支持大量的历史数据。
二、安装 ELK(这里不再讲解,不懂的可以参考:https://www.cnblogs.com/liugp/p/11789933.html)
三、添加 Elasticsearch mapping
Elasticsearch 支持 Zabbix 的监控项类型:uint,dbl,str,log,text,对应如下:
Zabbix 监控项数据类型 | 对应 Zabbix 表 | 对应 Elasticsearch 类型 |
Numeric(unsigned)(无符号整型) | history_uint | uint |
Numeric(float)(浮点型) | history | dbl |
Character(字符) | history_str | str |
Log(日志) | history_log | log |
Text | history_text | text |
ES7.x创建五中类型数据索引

PUT /uint { "settings":{ "number_of_replicas":1, "number_of_shards":5 }, "mappings":{ "properties":{ "itemid":{ "type":"long" }, "clock":{ "format":"epoch_second", "type":"date" }, "value":{ "type":"long" } } } } PUT /dbl { "settings":{ "number_of_replicas":1, "number_of_shards":5 }, "mappings":{ "properties":{ "itemid":{ "type":"long" }, "clock":{ "format":"epoch_second", "type":"date" }, "value":{ "type":"double" } } } } PUT /log { "settings":{ "number_of_replicas":1, "number_of_shards":5 }, "mappings":{ "properties":{ "itemid":{ "type":"long" }, "clock":{ "format":"epoch_second", "type":"date" }, "value":{ "fields":{ "analyzed":{ "index":true, "type":"text", "analyzer":"standard" } }, "index":false, "type":"text" } } } } PUT /text { "settings":{ "number_of_replicas":1, "number_of_shards":5 }, "mappings":{ "properties":{ "itemid":{ "type":"long" }, "clock":{ "format":"epoch_second", "type":"date" }, "value":{ "fields":{ "analyzed":{ "index":true, "type":"text", "analyzer":"standard" } }, "index":false, "type":"text" } } } } PUT /str { "settings":{ "number_of_replicas":1, "number_of_shards":5 }, "mappings":{ "properties":{ "itemid":{ "type":"long" }, "clock":{ "format":"epoch_second", "type":"date" }, "value":{ "fields":{ "analyzed":{ "index":true, "type":"text", "analyzer":"standard" } }, "index":false, "type":"text" } } } }
注意:通过上面创建的索引,zabbix-server无法添加数据,因为ES7移除了type类型导致的,但是可以让zabbix自动创建
ES6.x创建五中类型数据索引

PUT /uint { "settings":{ "index":{ "number_of_replicas":1, "number_of_shards":5 } }, "mappings":{ "values":{ "properties":{ "itemid":{ "type":"long" }, "clock":{ "format":"epoch_second", "type":"date" }, "value":{ "type":"long" } } } } } PUT /dbl { "settings":{ "index":{ "number_of_replicas":1, "number_of_shards":5 } }, "mappings":{ "values":{ "properties":{ "itemid":{ "type":"long" }, "clock":{ "format":"epoch_second", "type":"date" }, "value":{ "type":"double" } } } } } PUT /log { "settings":{ "index":{ "number_of_replicas":1, "number_of_shards":5 } }, "mappings":{ "values":{ "properties":{ "itemid":{ "type":"long" }, "clock":{ "format":"epoch_second", "type":"date" }, "value":{ "fields":{ "analyzed":{ "index":true, "type":"text", "analyzer":"standard" } }, "index":false, "type":"text" } } } } } PUT /text { "settings":{ "index":{ "number_of_replicas":1, "number_of_shards":5 } }, "mappings":{ "values":{ "properties":{ "itemid":{ "type":"long" }, "clock":{ "format":"epoch_second", "type":"date" }, "value":{ "fields":{ "analyzed":{ "index":true, "type":"text", "analyzer":"standard" } }, "index":false, "type":"text" } } } } } PUT /str { "settings":{ "index":{ "number_of_replicas":1, "number_of_shards":5 } }, "mappings":{ "values":{ "properties":{ "itemid":{ "type":"long" }, "clock":{ "format":"epoch_second", "type":"date" }, "value":{ "fields":{ "analyzed":{ "index":true, "type":"text", "analyzer":"standard" } }, "index":false, "type":"text" } } } } }
es6.x curl创建方式
curl -H "Content-Type:application/json" -XPUT http://192.168.182.132:9200/uint -d ' { "settings" : { "index" : { "number_of_replicas" : 1, "number_of_shards" : 5 } }, "mappings" : { "values" : { "properties" : { "itemid" : { "type" : "long" }, "clock" : { "format" : "epoch_second", "type" : "date" }, "value" : { "type" : "long" } } } } } ' curl -H "Content-Type:application/json" -XPUT http://192.168.182.132:9200/dbl -d ' { "settings" : { "index" : { "number_of_replicas" : 1, "number_of_shards" : 5 } }, "mappings" : { "values" : { "properties" : { "itemid" : { "type" : "long" }, "clock" : { "format" : "epoch_second", "type" : "date" }, "value" : { "type" : "double" } } } } } ' curl -H "Content-Type:application/json" -XPUT http://192.168.182.132:9200/log -d ' { "settings" : { "index" : { "number_of_replicas" : 1, "number_of_shards" : 5 } }, "mappings" : { "values" : { "properties" : { "itemid" : { "type" : "long" }, "clock" : { "format" : "epoch_second", "type" : "date" }, "value" : { "fields" : { "analyzed" : { "index" : true, "type" : "text", "analyzer" : "standard" } }, "index" : false, "type" : "text" } } } } } ' curl -H "Content-Type:application/json" -XPUT http://192.168.182.132:9200/text -d ' { "settings" : { "index" : { "number_of_replicas" : 1, "number_of_shards" : 5 } }, "mappings" : { "values" : { "properties" : { "itemid" : { "type" : "long" }, "clock" : { "format" : "epoch_second", "type" : "date" }, "value" : { "fields" : { "analyzed" : { "index" : true, "type" : "text", "analyzer" : "standard" } }, "index" : false, "type" : "text" } } } } } ' curl -H "Content-Type:application/json" -XPUT http://192.168.182.132:9200/str -d ' { "settings" : { "index" : { "number_of_replicas" : 1, "number_of_shards" : 5 } }, "mappings" : { "values" : { "properties" : { "itemid" : { "type" : "long" }, "clock" : { "format" : "epoch_second", "type" : "date" }, "value" : { "fields" : { "analyzed" : { "index" : true, "type" : "text", "analyzer" : "standard" } }, "index" : false, "type" : "text" } } } } } '
注意:zabbix的大坑,如果是es7,es7上有数据,但是图形会显示无数据,这个后期有待解决。如果有哪位大神已经解决了,可以在评论区回复我,Thank you!!!!。
四、配置zabbix服务器
Zabbix 安装过程忽略
配置 zabbix_server.conf 文件
在 /etc/zabbix/zabbix_server.conf 文件下添加 elasticsearch 配置,指定历时数据使用 elasticsearch。
# vim /etc/zabbix/zabbix_server.conf
HistoryStorageURL=http://192.168.182.132:9200 HistoryStorageTypes=uint,dbl,str,log,text
配置zabbix.conf.php文件
在/home/wwwroot/default/zabbix/conf/zabbix.conf.php文件下添加elasticsearch配置
# vim /home/wwwroot/default/zabbix/conf/zabbix.conf.php
// Elasticsearch url (can be string if same url is used for all types). $HISTORY['url'] = 'http://192.168.182.132:9200'; // Value types stored in Elasticsearch. $HISTORY['types'] = ['uint', 'text', 'log', 'str', 'dbl'];
多台 elasticsearch 集群可按以下格式配置
$HISTORY['url'] = [ 'uint' => 'http://192.168.182.132:9200 ', 'text' => 'http://192.168.182.133:9200', 'log' => 'http://192.168.182.134:9200']; $HISTORY['types'] = ['uint', 'text','log'];
五、验证数据
启动 zabbix 后,使用 kibana 查看 es 集群是否有相关索引,方法这里就忽略。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· C++代码改造为UTF-8编码问题的总结
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· 【.NET】调用本地 Deepseek 模型
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
· 上周热点回顾(2.17-2.23)
· 如何使用 Uni-app 实现视频聊天(源码,支持安卓、iOS)