zabbix elasticsearch 安装

本博客为官网文档的翻译:

原文:https://www.zabbix.com/documentation/current/manual/appendix/install/elastic_search_setup

(一)

    Elasticsearch的支持是试验性的,本节中考虑的设置过程适用于以下Elasticsearch版本:5.0.x–6.1.x。如果使用早期或后期的Elasticsearch版本,一些功能可能不如预期的那样工作。

    Zabbix最近开始支持通过Elasticsearch而不是数据库存储历史数据。现在用户可以在兼容的数据库和Elasticsearch之间选择历史数据的存储位置。

1 配置:

  为了确保所涉及的所有元素之间的正确通信,请确保正确配置了服务器配置文件和前端配置文件参数

(1)Zabbix服务器端和前端

  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服务器配置文件:历史数据存储的URL以及历史数据存储的类型。

HistoryStorageURL=http://test.elasticsearch.lan:9200
HistoryStorageTypes=str,log,text

  此配置强制Zabbix Server将数字类型的历史值存储在相应的数据库中,并将文本历史数据存储在Elasticsearch中。

 Elasticsearch支持一下的item(项目)类型。

uint,dbl,str,log,text

支持项目(item)类型说明:

Item value typeDatabase tableElasticsearch type
Numeric (unsigned)history_uintuint
Numeric (float)historydbl
Characterhistory_strstr
Loghistory_loglog
Texthistory_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前端配置文件示例参数值,与上面的服务端对应:

$HISTORY['url']   = 'http://test.elasticsearch.lan:9200';
$HISTORY['types'] = ['str', 'text', 'log'];

此配置强制在Elasticsearch中存储文本、字符和日志历史值。

还要求在conf/zabbix.conf.php中将$HISTORY全局化,以确保所有工作正常(有关如何执行此操作,请参阅conf/zabbix.conf.php.example)

// Zabbix GUI configuration file.
global $DB, $HISTORY;

(二)安装Elasticsearch和创建映射。

最后两个步骤是安装Elasticsearch本身和创建映射过程。

若要安装弹性搜索,请参阅

Elasticsearch 安装教程:https://www.elastic.co/guide/en/elasticsearch/reference/current/setup.html

这里需要选择合适的版本。

注意:映射是Elasticsearch中的数据结构(类似于数据库中的表)。这里提供了所有历史数据类型的映射:database/.elasticsearch/.elasticsearch.map。

创建映射是强制性的。如果不根据指令创建映射,某些功能将会被破坏。

若要创建文本(text)类型映射,请向弹性搜索发送以下请求:

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" : {
      "values" : {
         "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,请参阅下面的网址页面获取更多信息。

各种类型的需求:https://www.zabbix.com/documentation/current/manual/installation/requirements#server

Housekeeper 不会删除任何来自弹性搜索的数据。

1. 首先,您必须为索引创建模板。下面的示例显示了创建unit模板的请求。

curl -X PUT \
 http://your-elasticsearch.here:9200/_template/uint_template \
 -H 'content-type:application/json' \
 -d '{
   "template": "uint*",
   "index_patterns": ["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"
            }
         }
      }
   }
}'

  为了创建其他模板,用户应该更改URL(最后一部分是模板的名称),更改“.”和“index_.”字段以匹配索引名称并设置可以从数据库/elasticsearch/elasticsearch.map获取的有效映射。例如,可以使用以下命令为文本索引创建模板

curl -X PUT \
 http://your-elasticsearch.here:9200/_template/text_template \
 -H 'content-type:application/json' \
 -d '{
   "template": "text*",
   "index_patterns": ["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"
            }
         }
      }
   }
}'

这需要允许Elasticsearch为自动创建的索引设置有效的映射。然后,需要创建管道定义。管道是在将数据放入索引之前对数据进行某种预处理。下面的命令可用于为unit索引创建管道:

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.”)来设置特定的索引循环周期。要创建其他管道,用户应该更改URL(最后一部分是管道的名称)并更改“index_name_prefix”字段以匹配索引名称。

可参考Elasticsearch文档: https://www.elastic.co/guide/en/elasticsearch/reference/master/date-index-name-processor.html

此外,在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设置的问题:

检查映射是否正确(GET请求到所需的索引URL,如http://localhost:9200/uint)。

检查碎片(shards )是否处于失效状态(应重新启动弹性搜索)。

检查Elasticsearch的配置。配置应允许从Zabbix前端主机和Zabbix服务器主机进行访问。

检查Elasticsearch日志。

如果您在安装过程中仍然遇到问题,那么请使用此列表中的所有信息(映射、错误日志、配置、版本等)创建一个bug报告。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值