通常情况下,我们使用ELK日志分析平台最常用的数据时间为1周或一个月(因业务场景不同,可能存在差别),时间比较长的数据没有特殊情况可能我们就没有必要再进行查询了,但是因业务需求或者作为凭证,这些日志需要长期保存,就需要用到elasticsearch冷热数据分离架构。
节点名称 | 服务器类型 | 存储数据 |
---|---|---|
ES1 | SSD | hot |
ES2 | SSD | hot |
ES3 | SSD | hot |
ES4 | SATA | cold |
修改ES配置文件
cluster.name: elk_cluster
node.name: ES1
node.attr.rack: r1
node.attr.tag: hot
path.data: /ES/data/
path.logs: /usr/local/elasticsearch-6.4.3/logs
node.master: true
node.data: true
network.host: ES1
http.port: 9200
discovery.zen.ping.unicast.hosts: ["ES1","ES2","ES3","ES4"]
discovery.zen.minimum_master_nodes: 2
discovery.zen.commit_timeout: 100s
discovery.zen.publish_timeout: 100s
discovery.zen.ping_timeout: 100s
discovery.zen.fd.ping_timeout: 100s
discovery.zen.fd.ping_interval: 10s
discovery.zen.fd.ping_retries: 10
action.destructive_requires_name: true
http.cors.allow-origin: "*"
向ES节点中添加标签属性,定义hot标签的分片数据存储至该Node。
设置ES索引模板
curl -XPUT -H "Content-Type: application/json" 'ES1:9200/_template/template_1' -d '{
"order" : 0,
"template" : "logstash-*",
"settings" : {
"index.routing.allocation.include.tag" : "hot" }
}'
定义模板名称为
template_1
、order
:定义优先级,当多个模板同时匹配时order
越大优先级越高、template
:定义需要匹配的索引信息、settings
:设置标签。
curl -XGET -H "Content-Type: application/json" 'ES1:9200/_template/template_1'
查看模板信息。
更新索引标签
curl -XPUT -H "Content-Type: application/json" 'ES1:9200/indexname/_settings' -d '{
"index" : {
"routing" : {
"allocation" : {
"include" : {
"tag" : "cold"
}
}
}
}
}'
将以前索引标签为hot的索引修改为cold,索引及分片信息会自动迁移至ES4即冷数据存储服务器。
更新索引存储副本数
curl -XPUT -H "Content-Type: application/json" 'ES1:9200/indexname/_settings' -d '{
"number_of_replicas": 0
}'
将冷数据副本数修改为0。
因为索引是按照时间进行命名的,所以我们可以根据时间写脚本,定期将数据标签和副本数进行修改,达到了冷热数据分离的效果。