es数据的冷热分离实验

注意:演示用的2节点es,有些参数配置不太合理,生产环境还须要更严格的参数设定(例如必须开启密码验证)。node


系统版本:CentOS7sql


节点规划:json

热数据节点:  192.168.2.4bootstrap

温数据节点:  192.168.2.190bash

PS:这里就没分 hot warm cold 这种三级存储,咱们通常使用 hot warm 2种便可。app


咱们这里使用 tar.gz 通用二进制文件curl


useradd eselasticsearch


# cat /etc/security/limits.d/elasticsearch.conf ide

es - nofile 65535
es - noproc 65535
es - memlock unlimited



cd /usr/local/elasticsearch-7.4.2/ui

mkdir data logs 

chown es.es  /usr/local/elasticsearch-7.4.2/ -R


su - es

cd /usr/local/elasticsearch-7.4.2/


热数据节点:  192.168.2.4 的配置以下:

cat config/elasticsearch.yml 

cluster.name: my-application

node.name: node-1
node.attr.rack: r1

node.attr.temperature: hot

path.data: ./data/
path.logs: ./logs

node.master: true
node.data: true
node.ingest: true

bootstrap.memory_lock: true

network.host: 0.0.0.0
http.port: 9200

cluster.initial_master_nodes: 
  - 192.168.2.4:9300
  - 192.168.2.190:9300
  
discovery.seed_hosts:
  - 192.168.2.4
  - 192.168.2.190
  
gateway.recover_after_nodes: 1
#action.destructive_requires_name: true
############# xpack 的配置项 ####################
#xpack.security.enabled: true
#xpack.security.transport.ssl.enabled: true
xpack.security.audit.enabled: true
xpack.security.audit.logfile.events.include: access_denied, access_granted, anonymous_access_denied, authentication_failed,connection_denied, tampered_request, run_as_denied, run_as_granted
xpack.security.audit.logfile.emit_node_host_address: true
xpack.security.audit.logfile.emit_node_host_name: true
xpack.sql.enabled: true
xpack.ilm.enabled: true


温数据节点:  192.168.2.190

cat config/elasticsearch.yml 

cluster.name: my-application

node.name: es11
node.attr.rack: r1

node.attr.temperature: warm

path.data: ./data/
path.logs: ./logs

node.master: true
node.data: true
node.ingest: true

bootstrap.memory_lock: true

network.host: 0.0.0.0
http.port: 9200

cluster.initial_master_nodes: 
  - 192.168.2.4:9300
  - 192.168.2.190:9300
  
discovery.seed_hosts:
  - 192.168.2.4
  - 192.168.2.190
gateway.recover_after_nodes: 1

#action.destructive_requires_name: true

############# xpack 的配置项 ####################
#xpack.security.enabled: true
#xpack.security.transport.ssl.enabled: true
xpack.security.audit.enabled: true
xpack.security.audit.logfile.events.include: access_denied, access_granted, anonymous_access_denied, authentication_failed,connection_denied, tampered_request, run_as_denied, run_as_granted
xpack.security.audit.logfile.emit_node_host_address: true
xpack.security.audit.logfile.emit_node_host_name: true
xpack.sql.enabled: true
xpack.ilm.enabled: true


启动脚本: 

# cat start.sh 

# es 依赖高版本的jdk 须要先export下
export JAVA_HOME=./jdk/
nohup ./bin/elasticsearch >/dev/null 2>&1 &



中止脚本:

# cat stop.sh 

kill $(jps| grep Elasticsearch | awk '{print $1}')



建立索引,并将数据搬迁到hot节点:

curl -H 'Content-Type: application/json' -X PUT http://localhost:9200/index-2019.10.19?pretty
curl -H 'Content-Type: application/json' -X PUT http://localhost:9200/index-2019.10.19/_settings -d '
{
  "index.routing.allocation.require.temperature": "hot"
}'


image.png



若是要将 index-2019.10.19 的数据搬迁到温节点,咱们使用下面的这个命令就行

curl -H 'Content-Type: application/json' -X PUT http://localhost:9200/index-2019.10.19/_settings -d '
{
  "index.routing.allocation.require.temperature": "warm"
}'



流程跑通后,咱们能够写个脚本,做用有2个:

一、提早建立后一天的索引,并确保将其落到hot节点

二、将7天前的索引,打标签,存放到es的warm节点(大容量HDD磁盘):

#!/bin/bash

# 建立新的索引,语句相似下面5行,须要根据本身状况修改(建议使用for循环建立index)
# curl -H 'Content-Type: application/json' -X PUT http://localhost:9200/index-2019.10.19?pretty
# curl -H 'Content-Type: application/json' -X PUT http://localhost:9200/index-2019.10.19/_settings -d '
# {
#   "index.routing.allocation.require.temperature": "hot"
# }'

day=$(date +"%Y.%m.%d" -d -7day)

curl -H 'Content-Type: application/json'  -X PUT http://192.168.2.4:9200/*-${day}/_settings -d '
{
  "index.routing.allocation.require.temperature": "warm"
}'


另外, 在es7里面 提供 index-lifecycle-management 这个功能, 咱们在kibana 界面里面就能够进行配置。 具体能够查阅es官方的文档(我的仍是比较喜欢用上面的这种脚本的方案)。

相关文章
相关标签/搜索