Chinaunix首页 | 论坛 | 博客
  • 博客访问: 341339
  • 博文数量: 52
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 577
  • 用 户 组: 普通用户
  • 注册时间: 2013-04-27 14:21
个人简介

知道自己该干嘛,知道自己能干嘛

文章分类

全部博文(52)

文章存档

2019年(1)

2018年(8)

2017年(2)

2016年(11)

2015年(3)

2014年(10)

2013年(17)

我的朋友

分类: 系统运维

2018-03-26 11:18:24


      现在我们已经有了几台es集群,是SSD盘的,又需要加入几台大硬盘的服务器,所以就制定了,最近三天的索引在SSD存储,三天前的日志索引储存在SATA硬盘上,所以就需要对索引进行分配时候的过滤,也就是我们常说的索引的冷热分离,具体操作方法如下:

            

  1. step 1.  node节点添加attribute
  2.          在es中配置添加,es node  attribute "small" 或者 "big", 来区别节点的存储介质。
  3.                 
  4.          # Add custom attributes to the node:
  5.          #
  6.          node.attr.size: small     // 然后重启es服务
  7.          attribute: size这个属性的字符串是可以自定义的,这里方便为了区别,所以定义为 "small" or "big"

  8. step 2.  配置生成索引的模板template,添加索引路由分配指令:

  9.                 {
                           "template" : "*",
                                    "settings" : {
                                             "index" : {
                                                    "refresh_interval" : "5s",
                                                    "routing.allocation.include.size": "small"
                    }

  10.           主要是这条指令, "routing.allocation.include.size": "small", 在建立索引时,就分配至small属性的节点上

  11.           指令分配索引的三种逻辑关系:
  12.           index.routing.allocation.include.{attribute}
              Assign the index to a node whose {attribute} has at least one of the comma-separated values.

  13.           index.routing.allocation.require.{attribute}
              Assign the index to a node whose {attribute} has all of the comma-separated values.

  14.           index.routing.allocation.exclude.{attribute}
              Assign the index to a node whose {attribute} has none of the comma-separated values.

  15. step 3.   生成一条索引,在head中查看索引分配状态

  16.           查看节点属性: 
  17.                 
  18.               
  19.                  
  20.                 
  21.          日志刷新,按照我们的设置,新索引应该建立在 38.18的节点上,为了方便测试我们将副本设置为0

  22.                 
         可以看出我们设置的索引路由生效了,新建立的索引已经建立在指定node上


setp 4.  crontab任务,设置三天前数据分配到big节点上

         [root@date elasticsearch]# cat es_migrate_host_data.sh 
         #!/bin/bash

         #time=$(date -d "3 days ago" +%Y.%m.%d)
         time=2018.03.26   // 为了查看效果我们时间设置为试验当天

         curl -u admin:caiXXXXX -XPUT *-${time}/_settings?pretty -d'
         {
            "index.routing.allocation.include.size": "big"
         }'
 
         执行脚本查看结果:
         [root@date elasticsearch]# bash es_migrate_host_data.sh 
         {
              "acknowledged" : true
         }

         再从head中查看,索引分布状态

         
           
            可以看出,脚本执行后索引被分配到了big属性的node节点,完成了动静分离的需求.



参考资料:

       
     
  1.  
     

阅读(4414) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~