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表也再也不写入新数据。 

相关文章
相关标签/搜索