Zabbix4.x 历史数据存储到Elasticsearch7.x

浪尽此生 提交于 2019-12-11 13:33:24

一、简介

Zabbix 3.4.6 版本开始支持历史数据存储到 Elasticsearch, 早就想测试这个功能,最近有个需求需保存 zabbix 的历史数据上达十亿条,因此决定测试这功能的实用性,事实证明确实效果挺好。从今以后 zabbix 也支持大量的历史数据。

二、安装 ELK(这里不再讲解,不懂的可以参考:https://www.cnblogs.com/liugp/p/11789933.html

三、添加 Elasticsearch mapping

Elasticsearch 支持 Zabbix 的监控项类型:uint,dbl,str,log,text,对应如下:

Zabbix 监控项数据类型 对应 Zabbix 表 对应 Elasticsearch 类型
Numeric(unsigned)(无符号整型) history_uint uint
Numeric(float)(浮点型) history dbl
Character(字符) history_str str
Log(日志) history_log log
Text history_text text

创建五中类型数据索引

PUT /uint
{
    "settings":{
        "number_of_replicas":1,
        "number_of_shards":5
    },
    "mappings":{
        "properties":{
            "itemid":{
                "type":"long"
            },
            "clock":{
                "format":"epoch_second",
                "type":"date"
            },
            "value":{
                "type":"long"
            }
        }
    }
}


PUT /dbl
{
    "settings":{
        "number_of_replicas":1,
        "number_of_shards":5
    },
    "mappings":{
        "properties":{
            "itemid":{
                "type":"long"
            },
            "clock":{
                "format":"epoch_second",
                "type":"date"
            },
            "value":{
                "type":"double"
            }
        }
    }
}

PUT /log
{
    "settings":{
        "number_of_replicas":1,
        "number_of_shards":5
    },
    "mappings":{
        "properties":{
            "itemid":{
                "type":"long"
            },
            "clock":{
                "format":"epoch_second",
                "type":"date"
            },
            "value":{
                "fields":{
                    "analyzed":{
                        "index":true,
                        "type":"text",
                        "analyzer":"standard"
                    }
                },
                "index":false,
                "type":"text"
            }
        }
    }
}

PUT /text
{
    "settings":{
        "number_of_replicas":1,
        "number_of_shards":5
    },
    "mappings":{
        "properties":{
            "itemid":{
                "type":"long"
            },
            "clock":{
                "format":"epoch_second",
                "type":"date"
            },
            "value":{
                "fields":{
                    "analyzed":{
                        "index":true,
                        "type":"text",
                        "analyzer":"standard"
                    }
                },
                "index":false,
                "type":"text"
            }
        }
    }
}

PUT /str
{
    "settings":{
        "number_of_replicas":1,
        "number_of_shards":5
    },
    "mappings":{
        "properties":{
            "itemid":{
                "type":"long"
            },
            "clock":{
                "format":"epoch_second",
                "type":"date"
            },
            "value":{
                "fields":{
                    "analyzed":{
                        "index":true,
                        "type":"text",
                        "analyzer":"standard"
                    }
                },
                "index":false,
                "type":"text"
            }
        }
    }
}

四、配置zabbix服务器

Zabbix 安装过程忽略

配置 zabbix_server.conf 文件

/etc/zabbix/zabbix_server.conf 文件下添加 elasticsearch 配置,指定历时数据使用 elasticsearch。

# vim /etc/zabbix/zabbix_server.conf

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

配置zabbix.conf.php文件

/etc/zabbix/web/zabbix.conf.php文件下添加elasticsearch配置

# vim /etc/zabbix/zabbix_server.conf

// Elasticsearch url (can be string if same url is used for all types).
$HISTORY['url'] = 'http://192.168.182.132:9200';
// Value types stored in Elasticsearch.
$HISTORY['types'] = ['uint', 'text', 'log', 'str', 'dbl'];

多台 elasticsearch 集群可按以下格式配置

$HISTORY['url'] = [ 'uint' => 'http://192.168.182.132:9200 ', 'text' => 'http://192.168.182.133:9200', 'log' => 'http://192.168.182.134:9200'];
$HISTORY['types'] = ['uint', 'text','log'];

五、验证数据

启动 zabbix 后,使用 kibana 查看 es 集群是否有相关索引,方法这里就忽略。

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!