Elasticsearch支持尚处于实验阶段!
Zabbix支持通过Elasticsearch替代数据库存储历史数据。用户可在兼容数据库与Elasticsearch之间选择历史数据的存储位置。本节描述的配置流程适用于Elasticsearch version 7.X版本。若使用更早或更新的version版本,部分功能可能无法按预期工作。
若所有历史数据均存储于Elasticsearch, 则趋势数据将不会被计算或存储于数据库中。由于未计算和存储趋势数据,可能需要延长历史数据的存储周期。
为确保所有相关组件间的正常通信,请确保服务器配置file和前端配置file参数均已正确配置。
Zabbix server配置file草案及待更新参数:
### Option: HistoryStorageURL # History storage HTTP[S] URL. # # Mandatory: no # Default: # HistoryStorageURL= ### Option: HistoryStorageTypes # Comma separated list of value types to be sent to the history storage. # # Mandatory: no # Default: # HistoryStorageTypes=uint,dbl,str,log,text用于填充Zabbix server配置file的示例参数值:
此配置强制Zabbix server将数值类型的历史数据存储在对应数据库中,而文本历史数据存储在Elasticsearch中。
Elasticsearch支持以下监控项类型:
支持的监控项类型说明:
| 监控项值类型 | 数据库表 | Elasticsearch类型 |
| 数值型(无符号) | history_uint | uint |
| 数值型(float) | history | dbl |
| 字符型 | history_str | str |
| 日志型 | history_log | log |
| 文本型 | history_text | text |
Zabbix前端配置file(conf/zabbix.conf.php)草案及待更新参数:
// Elasticsearch url (can be string if same url is used for all types). $HISTORY['url'] = [ 'uint' => 'http://localhost:9200', 'text' => 'http://localhost:9200' ]; // Value types stored in Elasticsearch. $HISTORY['types'] = ['uint', 'text'];用于填充Zabbix前端配置file的示例参数值:
此配置强制将Text、Character和Log历史值存储在Elasticsearch中。
还需要在conf/zabbix.conf.php中将$HISTORY设为全局变量以确保一切正常工作(具体方法参见conf/zabbix.conf.php.example):
// Zabbix GUI配置file. global $DB, $HISTORY;
实现功能运作的最后两个步骤是安装Elasticsearch本身以及创建映射过程。
要安装Elasticsearch,请参考Elasticsearch installation guide。
映射是Elasticsearch中的一种数据结构(类似于数据库中的表)。所有历史数据类型的映射可在此处获取:database/elasticsearch/elasticsearch.map。
创建映射是强制性的。如果未按照说明创建映射,某些功能将无法正常工作。
要为text类型create映射,请向Elasticsearch发送以下请求:
curl -X PUT \ http://your-elasticsearch.here: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" } } } }'对于Character和Log历史值映射的创建,需要执行类似的请求,并相应修正类型。
要使用Elasticsearch,请参阅serverproxy获取更多信息。
管家服务 不会从Elasticsearch中删除任何数据。
本节描述了使用管道和摄取节点所需的额外步骤。
首先,您必须为indicescreate模板。
以下示例展示了创建uint模板的请求:
curl -X PUT \ http://your-elasticsearch.here:9200/_template/uint_template \ -H 'content-type:application/json' \ -d '{ "index_patterns": [ "uint*" ], "settings": { "index": { "number_of_replicas": 1, "number_of_shards": 5 } }, "mappings": { "properties": { "itemid": { "type": "long" }, "clock": { "format": "epoch_second", "type": "date" }, "value": { "type": "long" } } } }'要create其他模板,用户应更改URL(最后部分是模板名称),将"index_patterns"字段更改为匹配索引名称,并设置可从database/elasticsearch/elasticsearch.map获取的有效映射。
例如,以下命令可用于create文本索引的模板:
curl -X PUT \ http://your-elasticsearch.here:9200/_template/text_template \ -H 'content-type:application/json' \ -d '{ "index_patterns": [ "text*" ], "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" } } } }'这是为了让Elasticsearch能够为自动创建的indices设置有效映射。然后需要create管道定义。管道是在将数据放入indices之前对数据进行某种预处理。以下命令可用于createuint索引的管道:
curl -X PUT \ http://your-elasticsearch.here:9200/_ingest/pipeline/uint-pipeline \ -H 'content-type:application/json' \ -d '{ "description": "daily uint index naming", "processors": [ { "date_index_name": { "field": "clock", "date_formats": [ "UNIX" ], "index_name_prefix": "uint-", "date_rounding": "d" } } ] }'用户可以更改舍入参数("date_rounding")以设置特定的索引轮换周期。要create其他管道,用户应更改URL(最后部分是管道名称),并将"index_name_prefix"字段更改为匹配索引名称。
另请参阅Elasticsearch documentation。
此外,在Zabbix server配置的新参数中还应启用将历史数据存储在多个基于日期的indices中:
# 启用历史存储中历史值的预处理,以将值存储在不同基于日期的indices中。 # 0 - 禁用 # 1 - 启用 # # 必填:否 # 默认值: # HistoryStorageDateIndex=0以下步骤可能帮助您排查Elasticsearch设置问题:
http://localhost:9200/uint).如果安装问题仍然存在,请create包含此列表中所有信息(映射、错误日志、配置、version等)的错误报告.