Elasticsearch 冷热分离

       为了不浪费服务器资源(每台机器上均配置有SSD和大存储,且内存配置较高),提高ES读写性能,我们尝试进行了ES集群冷热分离的配置。

测试环境

       两台机器,均配置有SSD和SATA盘。每台机器上运行两个ES实例,其中一个实例配置data目录为SSD

  1. 解压安装(两台机器)
    mkdir -p /data/mdware
    cd /data/mdware
    tar -zxf elasticsearch-2.2.1.tar.gz
    ln -s /data/mdware/elasticsearch-2.2.1 /data/mdware/es
    cd /data/mdware/es/conf
    mkdir instance1
    mkdir instance2
    cp elasticsearch.yml instance1
    mv elasticsearch.yml instance2
    cp logging.yml instance1
    mv logging.yml instance2
  2. 配置(四个配置文件,注意区别)
action.auto_create_index : -protocol*,+*
cluster.name: knowops
#分别取名为kone1.2.3.4
node.name: "kone1"
# kone2配置为 /ssd/kone2data(/ssd   SSD挂载目录)
path.data: /data/mdware/elasticsearch-2.2.1/kone1data
path.logs: /data/mdware/elasticsearch-2.2.1/kone1log
bootstrap.mlockall: true
# IP
network.host: 192.168.211.129
node.max_local_storage_nodes: 2
http.cors.enabled : true
http.cors.allow-origin : "*"
index.number_of_replicas: 0
discovery.zen.ping.unicast.hosts: ["192.168.211.129:9300","192.168.211.130:9300"]
  1. 启动
    cd /data/mdware/es
    ulimit -n 655360(打开文件数最低要求为65536)
    export ES_HEAP_SIZE=16g(我的配置为1/8内存)
    bin/elasticsearch -Des.insecure.allow.root=true -Des.path.conf=config/instance1 -d --node.tag=hot(SSD配置为hot节点)
    export ES_HEAP_SIZE=16g(1/8内存)
    bin/elasticsearch -Des.insecure.allow.root=true -Des.path.conf=config/instance2 -d --node.tag=stale

  2. 模板配置
    vi database.template.json

{
        "template":"ni-database-*",
        "settings":{
                "index.number_of_replicas":"0",
                 "index.routing.allocation.require.tag" : "hot"   //配置写入hot节点
        },
        "mappings":{
                "_default_":{
                        "_all":{
                                "enabled":false,
                                "norms":{
                                        "enabled":false
                                }

                        },
                        "dynamic_templates":[
                                {
                                        "template1":{
                                                "mapping":{
                                                        "doc_values":true,
                                                        "ignore_above":1024,
                                                        "index":"not_analyzed",
                                                        "type":"{dynamic_type}"
                                                },
                                                "match":"*"
                                        }

                                }
                        ],
                        "properties":{
                            "timeStart":{
                                    "type":"date"
                            }
                        }
                }
        }
}
    curl -XPUT 192.168.211.130:9200/_template/ni-database-template -d @database.template.json
  1. 定时任务
    我们的索引是按天生成的,所以每天00:30定时任务移动数据到stale节点
#/bin/bash
time=`date -d last-day "+%Y.%m.%d"`
curl -XPUT http://localhost:9200/*-${time}/_settings?pretty -d'
{
  "index.routing.allocation.require.tag": "stale"
}'
  1. 集群效果(kopf插件)

转:https://www.jianshu.com/p/f13a6dbb84ed
 

猜你喜欢

转载自blog.csdn.net/aa5305123/article/details/84401743