Elasticsearch 支持处于实验阶段!
Zabbix 支持通过 Elasticsearch 而不是数据库来存储历史数据。用户可以在兼容数据库和 Elasticsearch 之间选择历史数据的存储位置。本节中描述的配置流程适用于 Elasticsearch 7.X 版本。如果使用的是 Elasticsearch 的早期或后期版本,某些功能可能无法按预期工作。
1. 如果所有历史数据都存储在 Elasticsearch 中,趋势数据将不进行计算,也不存储在数据库中。没有计算和存储趋势数据,可能需要延长历史数据的存储周期。
2. 当使用 Elasticsearch 时,范围查询从数据库检索值将受到数据存储周期的时间戳限制。
为确保所涉及的所有元素之间的正确通信,请确保服务器配置文件和前端配置文件参数正确。
Zabbix 服务器配置文件模板,其中包含要更新的参数:
### 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 服务端配置文件示例的参数值:
此配置强制 Zabbix Server 在相应的数据库中存储数字类型的历史值,并在Elasticsearch中存储文本历史数据。
Elasticsearch 支持以下 item 类型:
支持的 item 类型说明:
Item 类型 | 数据库表 | Elasticsearch 类型 |
Numeric (unsigned) | history_uint | uint |
Numeric (float) | history | dbl |
Character | history_str | str |
Log | history_log | log |
Text | history_text | text |
Zabbix 前端配置文件 (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 前端配置文件示例的参数值 :
此配置强制在Elasticsearch种存储 Text
, Character
及 Log
的历史值. 还需要在conf/zabbix.conf.php
中使用全局变量 $HISTORY,以确保一切正常 (有关如何执行此操作,请参阅conf/zabbix.conf.php.example
):
使一切正常工作的最后两个步骤是安装Elasticsearch 本身以及创建映射流程。
要安装Elasticsearch,请参考Elasticsearch安装 指南。
映射是Elasticsearch中的数据结构(类似于数据库中的 表)。所有历史数据类型的映射可在此处找到:database/elasticsearch/elasticsearch.map
。
创建映射是强制性的。如果未根据 说明创建映射,某些功能将无法正常工作。
为了创建text
类型的映射,向 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,请参考要求以获取额外 信息。
管家 不会从Elasticsearch中删除任何数据。
本节介绍使用管道和引入节点所需的其他步骤。 首先,必须为索引创建模板。 以下示例为创建 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"
}
}
}
}'
要创建其他模板,用户应更改URL(最后一部分是模板的名称),更改"index_patterns"
字段以匹配索引名称并设置有效的映射,这可以在database/elasticsearch/elasticsearch.map
获取。 以下命令可用于为文本索引创建模板,例如:
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 为自动创建的索引设置有效的映射所必需做的。然后需要创建pipeline定义。pipeline是在将数据放入索引之前对数据的某种预处理。以下命令可用于为 uint 索引创建pipeline:
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")以设置特定的索引轮换周期。要创建其他pipelines,用户应更改 URL(最后一部分是pipelines的名称)并更改"index_name_prefix"字段以匹配索引名称 另见 Elasticsearch documentation. 此外,在Zabbix服务器新的配置参数中,还应启用将历史数据存储在多个基于日期的索引中:
### Option: HistoryStorageDateIndex
# Enable preprocessing of history values in history storage to store values in different indices based on date.
# 0 - disable
# 1 - enable
#
# Mandatory: no
# Default:
# HistoryStorageDateIndex=0
以下步骤可能有助于您解决 Elasticsearch 配置中遇到的问题:
http://localhost:9200/uint
)。LogSlowQueries
来检查 Elasticsearch 数据库中的慢查询。如果您在安装后仍然遇到问题,请创建一个错误报告,其中包含此列表中的所有信息(映射、错误日志、配置、版本等)。