天天看點

zabbix曆史資料存儲到elasticsearch第1章 環境說明:第2章 zabbix服務端配置第3章 ES上操作第4章 在zabbix-web頁面上檢視資料擷取是否正常

Zabbix曆史資料存儲到ES

第1章 環境說明:

[[email protected] ~]# cat /etc/redhat-release

CentOS Linux release 7.4.1708 (Core)

[[email protected] ~]# systemctl status firewalld.service

●firewalld.service - firewalld - dynamic firewall daemon

   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)

   Active: inactive (dead)

     Docs: man:firewalld(1)

[[email protected] ~]# getenforce

Disabled

Zabbix版本

[[email protected] ~]# rpm -qa|grep zabbix

zabbix-release-4.0-1.el7.noarch

ES版本,官方說明支援的ES版本為5.0-6.1之間,之前安裝的6.2最後會不成功

[[email protected] elasticsearch]# curl http://127.0.0.1:9200

{

  "name" : "2nrv98N",

  "cluster_name" : "elasticsearch",

  "cluster_uuid" : "oyVYItFuTIuEMgagxaOzgg",

  "version" : {

    "number" : "5.6.6",

    "build_hash" : "7d99d36",

    "build_date" : "2018-01-09T23:55:47.880Z",

    "build_snapshot" : false,

    "lucene_version" : "6.6.1"

  },

  "tagline" : "You Know, for Search"

}

第2章 zabbix服務端配置

2.1修改zabbix-server配置檔案,用于将zabbix-server資料庫中的數值類型和文本類型的曆史資料存儲到ES中

[[email protected] zabbix]# cat zabbix_server.conf

HistoryStorageURL=http://your-elasticsearch.here:9200

HistoryStorageTypes=str,log,text

2.2修改zabbix前端配置檔案,用于将文本,字元,日志類型的曆史資料存儲到ES

[[email protected] zabbix]# cat web/zabbix.conf.php

<?php

// Zabbix GUI configuration file.

global $DB, $HISTORY;

$DB['TYPE']     = 'MYSQL';

$DB['SERVER']   = '127.0.0.1';

$DB['PORT']     = '3306';

$DB['DATABASE'] = 'zabbix';

$DB['USER']     = 'zabbix';

$DB['PASSWORD'] = 'admin111';

// Schema name. Used for IBM DB2 and PostgreSQL.

$DB['SCHEMA'] = '';

$ZBX_SERVER      = 'localhost';

$ZBX_SERVER_PORT = '10051';

$ZBX_SERVER_NAME = 'zabbix';

$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;

$HISTORY['url'] = 'http://your-elasticsearch.here:9200';

$HISTORY['types'] = ['log', 'text', 'str'];

2.3重新開機zabbix-server

systemctl restart zabbix-server.service

2.4重新開機httpd

systemctl stop httpd.service

第3章 ES上操作

Ø  ES上面建立映射,相當于在mysql中建立資料庫的操作

3.1建立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"

            }

         }

      }

   }

}'

3.2配置曆史資料存儲多個基于時間的索引,建立uint模版

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"

            }

         }

      }

   }

}'

3.3為文本索引建立模版

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"

            }

         }

      }

   }

}'

3.4允許ES為自動建立的索引設定有效的映射,建立pipline定義(pipline能對資料進行多種預處理操作

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"

      }

    }

  ]

}'

第4章 在zabbix-web頁面上檢視資料擷取是否正常

4.1剛修改完的話需要等下才能有資料展示

還可以到資料庫中檢視history開頭的幾張表是否還有資料寫入

轉載于:https://blog.51cto.com/13520772/2329274