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 type Database table Elasticsearch type
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前端配置文件示例參數值,與上面的服務端對應:

$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報告。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章