Zabbix对接Elasticsearch(ES)数据库(未成功)

0.需求分析

不管zabbix的后端数据库是oracle还是mysql,当zabbix监控的量级达到了一定程度后,那么对数据库的性能是一个非常严峻的挑战。特别是对历史数据的查询,将会变得非常非常的慢,别告诉我可以建索引优化,当量级达到一定的程度的时候,索引真的没啥效果了。如果再不继续寻找合适的解决方案,那么就一定会引发数据库层面的问题,最终导致服务不可用。当监控数据越来越大的时候,存储不足的时候,怎么办?那就删历史数据呗,但如果要求至少要保存半年甚至1年以上的历史数据,且又高端存储磁阵紧缺面临扩容难题的时候怎么办?而且又同时面临着单个历史表非常庞大的时候怎么办?分库、分表、分区?做读写分离?不!一切都是浮云,还有一个更值得推荐的解决方案,那就是利用Zabbix本身对ES支持的机制来将历史数据存储到ES集群。目前,官方虽然表示Zabbix对Elasticsearch的支持仍处于试验阶段,但笔者认为还是值得一试,且在测试阶段未发现有啥不妥。"生产环境"上也改造了几套对接ES的架构,目前运行均一切正常,ES可快速横向扩展的能力是人尽皆知啊!谁用谁知道。

1.架构图

2.环境搭建

这里只演示zabbix server对接ES的过程,其他集群将省略。

zabbix server :192.168.99.180

ES集群node1:192.168.99.111:9200

3.配置zabbix:

配置插件以便它可以连接到你的Elasticsearch实例。打开Zabbix服务器的配置文件zabbix_server.conf并添加以下行:

bash 复制代码
vim /etc/zabbix/zabbix_server.conf
bash 复制代码
HistoryStorageURL=http://192.168.99.111:9200
HistoryStorageTypes=uint,dbl,str,log,text

配置es前端页面

bash 复制代码
vim /etc/zabbix/web/zabbix.conf.php

添加

php 复制代码
global $DB,$HISTORY;
...... 
// Elasticsearch url (can be string if same url is used for all types).
 
$HISTORY['url'] = 'http://192.168.99.111:9200';
 
// Value types stored in Elasticsearch.
 
$HISTORY['types'] = ['uint', 'text', 'log', 'str', 'dbl'];

4.配置Elasticsearch模板:

设置sysctl.conf

bash 复制代码
vim /etc/sysctl.conf

vm.max_map_count=655360

sysctl -p
 

设置limits.conf

bash 复制代码
#vim /etc/security/limits.conf

elasticsearch soft memlock unlimited
 
elasticsearch hard memlock unlimited
 
elasticsearch soft nofile 65536
 
elasticsearch hard nofile 131072
 
elasticsearch soft nproc 65536
 
elasticsearch hard nproc 65536
 
/etc/elasticsearch/jvm.option

禁用swap

bash 复制代码
#vi /etc/fstab

#/dev/mapper/cryptswap1 none swap sw 0 0 注释

添加Elasticsearch mapping

Zabbix监控项数据类型

bash 复制代码
curl -H "Content-Type:application/json" -XPUT http://192.168.99.111: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.99.111: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.99.111: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.99.111: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.99.111: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" } } } } } '

5. 重启Zabbix服务器:

最后,重启Zabbix服务器以使更改生效。

bash 复制代码
 systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm

多台elasticsearch集群可按以下格式配置

php 复制代码
$HISTORY['url'] = [ 'uint' => 'http://192.168.1.230:9200 ', 'text' => 'http://192.168.1.234:9200 '

'log' => 'http://192.168.1.235:9200 ' ];

$HISTORY['types'] = ['uint', 'text','log'];
相关推荐
小疯仔16 分钟前
navicat导出数据库的表结构
数据库
TOSUN同星17 分钟前
干货分享 | TSMaster DBC编辑器操作指南:功能详解+实战示例
数据库·oracle·编辑器·汽车·软件工程
huihui4501 小时前
一天一道Sql题(day01)
数据库
~尼卡~1 小时前
软考(软件设计师)数据库原理:事务管理,备份恢复,并发控制
数据库·软件设计师-软考
八九燕来2 小时前
Django双下划线查询
数据库·django·sqlite
眠りたいです2 小时前
Mysql常用内置函数,复合查询及内外连接
linux·数据库·c++·mysql
paopaokaka_luck3 小时前
智能推荐社交分享小程序(websocket即时通讯、协同过滤算法、时间衰减因子模型、热度得分算法)
数据库·vue.js·spring boot·后端·websocket·小程序
He.ZaoCha3 小时前
函数-1-字符串函数
数据库·sql·mysql
二当家的素材网3 小时前
Centos和麒麟系统如何每天晚上2点10分定时备份达梦数据库
linux·数据库·centos
白仑色3 小时前
Oracle 存储过程、函数与触发器
数据库·oracle·数据库开发·存储过程·plsql编程