写在开篇
不论zabbix的后端数据库是oracle还是mysql,当zabbix监控的量级达到了肯定水平后,那么对数据库的性能是一个十分严厉的挑战。特地是对历史数据的查问,将会变得十分十分的慢,别通知我能够建索引优化,当量级达到肯定的水平的时候,索引真的没啥成果了。如果再不持续寻找适合的解决方案,那么就肯定会引发数据库层面的问题,最终导致服务不可用。当监控数据越来越大的时候,存储有余的时候,怎么办?那就删历史数据呗,但如果要求至多要保留半年甚至1年以上的历史数据,且又高端存储磁阵紧缺面临扩容难题的时候怎么办?而且又同时面临着单个历史表十分宏大的时候怎么办?分库、分表、分区?做读写拆散?不!一切都是浮云,还有一个更值得举荐的解决方案,那就是利用Zabbix自身对ES反对的机制来将历史数据存储到ES集群。目前,官网尽管示意Zabbix对Elasticsearch的反对仍处于试验阶段,但笔者认为还是值得一试,且在测试阶段未发现有啥不妥。“生产环境”上也革新了几套对接ES的架构,目前运行均一切正常,ES可疾速横向扩大的能力是人尽皆知啊!谁用谁晓得。
上面笔者附上对接ES的官网文档链接:https://www.zabbix.com/docume...,且利用测试环境输入了本篇的“精髓”。心愿能够起到抛砖引玉的成果,欢送宽广盆友能够和笔者一起独特探讨。
架构图
笔者简略画了一下大略的架构图,如下:
环境搭建
因为Oracle、ES、Kibana、Zabbix不是本文的主题,因而这几个组件的装置过程笔者在本文就省略了哈。对于Oracle的装置,笔者在以前的文章中有所讲到,那么ES、Kibana、Zabbix的相干知识点笔者后续也会抽时间输入“精髓”,望宽广敌人们多多关注哦,非常感谢!
在es中创立索引
增加数字(无符号)类型的索引
curl -X PUT \ http://localhost:9200/uint \ -H 'content-type:application/json' \ -d '{"settings": { "index": { "number_of_replicas": 1, "number_of_shards": 5 }},"mappings": { "properties": { "itemid": { "type": "long" }, "clock": { "format": "epoch_second", "type": "date" }, "value": { "type": "long" } }}}'
增加数字(浮点型)类型的索引
curl -X PUT \ http://localhost:9200/dbl \ -H 'content-type:application/json' \ -d '{"settings": { "index": { "number_of_replicas": 1, "number_of_shards": 5 }},"mappings": { "properties": { "itemid": { "type": "long" }, "clock": { "format": "epoch_second", "type": "date" }, "value": { "type": "double" } }}}'
增加字符类型的索引
curl -X PUT \ http://localhost:9200/str \ -H 'content-type:application/json' \ -d '{"settings": { "index": { "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" } }}}'
增加日志类型的索引
curl -X PUT \ http://localhost:9200/log \ -H 'content-type:application/json' \ -d '{"settings": { "index": { "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" } }}}'
增加文本类型的索引
curl -X PUT \ http://localhost:9200/text \ -H 'content-type:application/json' \ -d '{"settings": { "index": { "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
1. zabbix server对接es
vi /opt/aspire/product/zabbixsvr5/etc/zabbix_server.conf
HistoryStorageURL=local.es.svr:9200HistoryStorageTypes=uint,dbl,str,log,text
2. zabbix web前端对接es
vi /opt/aspire/product/nginx/html/conf/zabbix.conf.php
<?php// Zabbix GUI configuration file.global $DB, $HISTORY;$HISTORY['url'] = 'http://local.es.svr:9200';$HISTORY['types'] = ['uint', 'text', 'log', 'str', 'dbl'];
3. 重启zabbix server和php-fpm即可
# 杀死和拉起zabbix serverps -aux | grep zabbix_server | grep -v grep | awk '{print $2}' | xargs kill -9/opt/aspire/product/zabbixsvr5/sbin/zabbix_server -c /opt/aspire/product/zabbixsvr5/etc/zabbix_server.conf# 杀死和拉起php-fpmpkill php-fpm/opt/aspire/product/php7/sbin/php-fpm
对接实现后的验证
1. zabbix查看最新上报的数据
上图可看出上报监控数据失常
2. 在zabbix数据库(oracle)中查问相干历史表是否有数据
笔者通过plsql登录了oracle 19c进行select count操作
通过上图可看到,history、history_log、history_str、history_text、history_uint 这5张表都没有数据写入了
3. 登录kibana查看
上图可看到,历史数据都写入到对应的索引了。
写在最初
此计划是Zabbix官网内置反对的机制,也是比拟举荐的解决方案,其实Zabbix从4.2版本就开始反对时序数据库TimescaleDB了,但目前时序数据库不反对Zabbix proxy。如果后端的Oracle或MySQL换成TimescaleDB,再联合ES,是不是变得能够反对更大规模的监控?这是一个值得去测试的解决方案。笔者回头找工夫搭建一下,并做压测。好了!工夫无限,今晚就此搁笔,感激宽广盆友的关注,望多多点赞、珍藏、转发,谢谢!