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官方的文檔(我的仍是比較喜歡用上面的這種腳本的方案)。

相關文章
相關標籤/搜索