zabbix3.4.14歷史數據寫入es

zabbix在3.4.5版本後開始支持將歷史數據寫入es;其實就是將zabbix 5張歷史表的數據寫入es的5個索引,字段仍是同樣的;前端

mysql表和es索引的對應關係以下:mysql

配置其實很簡單,如下是我按照順序寫一遍web

 1,配置zabbix server配置文件sql

打開配置文件,3.4.5版本後的zabbix多了配置es的兩個參數,添加上;json

HistoryStorageURL=http://es_address:9200
HistoryStorageTypes=uint,dbl,str,log,text

2, 配置zabbix前端文件centos

 添加bash

$HISTORY['url'] = 'http://es_ip:9200';
$HISTORY['types'] = ['str', 'text', 'log', 'uint', 'dbl'];app

前面修改成 curl

global $DB , $HISTORY;ui

示例以下

3 , 建立es索引

共建立uint,dbk,str,log,text5個索引

curl -X PUT \
 http://1。1.1.1:9200/uint \
 -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" : {
               "type" : "long"
            }
         }
      }
   }
}'


curl -X PUT \
 http://1。1.1.1:9200/dbl \
 -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" : {
               "type" : "double"
            }
         }
      }
   }
}'

curl -X PUT \
 http://1.1.1.1:9200/log \
 -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"
            }
         }
      }
   }
}'


curl -X PUT \
 http://1.1.1.1: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"
            }
         }
      }
   }
}'

curl -X PUT \
 http://1。1.1.1:9200/str \
 -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"
            }
         }
      }
   }
}'

 

5 , 去kibana上建立索引

登陸到kibana,建立如上兩個索引,時間過濾字段這個地方寫clock,kibana會提示的

6,此時重啓zabbix server,zabbix web(httpd)

7, 稍等去kibana上和zabbix web上看新的數據是否正常

 

 8,期間踩了兩個坑

1,我是從zabbix 3.0升級過來的,操做系統是centos 6.7,升級後改完配置啓動報錯

cannot initialize history storage: cURL library support >= 7.28.0 is required for Elasticsearch history backend

 curl -V看了下,版本是7.19比較低,要升級,而後yum,rpm,編譯安裝都試了,curl版本看着也升級上來了,可是啓動server仍是報錯,網上說從新編譯安裝zabbix server便可,不過我是yum安裝的,嘗試從新yum安裝了一次,仍是報錯。

只好從新搭建了一臺centos7.x,其系統自帶的curl版本是7.29,知足要求,而後安裝相同版本的zabbix server,把配置都倒過去。啓動,ok。

2,若是第3步在歷史數據已經開始寫入後再建立索引的話;也就是先配置好zabbix,啓動後,數據會開始寫入es,這時候再按照上述方法建立索引,就會報錯,索引已經存在了,必須先stop zabbix,把這5個索引手動刪了,再按照第三步執行才行

3,若是不按照3步建立索引的話,再es上寫入的數據中的clock是Unix時間,kibana不會像上面圖中那樣展現,zabbix web也不會有數據顯示

4, 補充下,歷史數據寫入es的話,除了5個history表再也不寫入新數據,兩個trends表也再也不寫入新數據。 

相關文章
相關標籤/搜索