004.索引备份和跨节点搜索

2020-04-16  本文已影响0人  饿虎嗷呜

** EXAM OBJECTIVE: CLUSTER ADMINISTRATION **
GOAL: Backup and cross-cluster search
REQUIRED SETUP: /
Let’s create a one-node cluster and index some data in it.
Download the exam version of Elasticsearch
Deploy the cluster eoc-06-original-cluster, with one node named
node-1
Start the cluster
Create the index hamlet and add some documents by running the
following _bulk command

答案如下:

PUT hamlet/_bulk
{"index":{"_index":"hamlet","_id":0}}
{"line_number":"1","speaker":"BERNARDO","text_entry":"Whos there?"}
{"index":{"_index":"hamlet","_id":1}}
{"line_number":"2","speaker":"FRANCISCO","text_entry":"Nay, answer me: stand, and unfold yourself."}
{"index":{"_index":"hamlet","_id":2}}
{"line_number":"3","speaker":"BERNARDO","text_entry":"Long live the king!"}
{"index":{"_index":"hamlet","_id":3}}
{"line_number":"4","speaker":"FRANCISCO","text_entry":"Bernardo?"}
{"index":{"_index":"hamlet","_id":4}}
{"line_number":"5","speaker":"BERNARDO","text_entry":"He."}

Configure node-1 to support a shared file system repository for
backups located in
(i) "[home_folder]/repo" and
(ii) "[home_folder]/elastic/repo" - e.g., "glc/elastic/repo"
Create the hamlet_backup shared file system repository in
"[home_folder]/elastic/repo"
Create a snapshot of the hamlet index, so that the snapshot
(i) is named hamlet_snapshot_1,
(ii) is stored into hamlet_backup
Delete the index hamlet
Restore the index hamlet using hamlet_snapshot_1

PUT _snapshot/hamlet_backup
{
  "type": "fs",
  "settings": {
    "location": "/home/els_usr/elk/elasticsearch-7.4.2/cluster1_repo/"
  }
}


PUT _snapshot/hamlet_backup/hamlet_snapshot_1
{
  "indices": "hamlet"
}

GET _snapshot/hamlet_backup/hamlet_snapshot_1

DELETE hamlet

POST _snapshot/hamlet_backup/hamlet_snapshot_1/_restore

Deploy a second cluster eoc-06-adaptation-cluster, with one node
named node-2
Start the cluster
Create the index hamlet-pirate on node-2 and add documents
using the _bulk command

PUT hamlet-pirate/_bulk
{"index":{"_index":"hamlet-pirate","_id":5}}
{"line_number":"6","speaker":"FRANCISCO","text_entry":"Ahoy Matey! Ye come most carefully upon yer hour."}
{"index":{"_index":"hamlet-pirate","_id":6}}
{"line_number":"7","speaker":"BERNARDO","text_entry":"Aye! Tis now struck twelve; get ye to bed, Francisco."}
{"index":{"_index":"hamlet-pirate","_id":7}}
{"line_number":"8","speaker":"FRANCISCO","text_entry":"For this relief much thanks, son of a biscuit eater"}
{"index":{"_index":"hamlet-pirate","_id":8}}
{"line_number":"9","speaker":"BERNARDO","text_entry":"Arrrrrrrrh!"}

Enable cross cluster search on eoc-06-adaptation-cluster, so
that
(i) the name of the remote cluster is original,
(ii) the seed is node-1, which is listening on the default
transport port,
(iii) the cross cluster configuration persists across multiple
restarts
Run the cross-cluster query below to check your setup

注意要打开节点的防火墙,让9300端口的流量通过。

PUT _cluster/settings
{
  "persistent": {
    "cluster": {
      "remote": {
        "original": {
          "seeds": ["172.17.1.43:9300"]
        }
      }
    }
  }
}

GET /original:hamlet,hamlet-pirate/_search
{
  "query": {
    "match": {
       "speaker": "BERNARDO"
    }
  }
}

其实主要时间花在折腾两个分离的节点了。由于原来的节点配了安全认证,跨节点弄还比较麻烦。后面有时间折腾一下。现有文档都是没有考虑认证的事情。

上一篇 下一篇

猜你喜欢

热点阅读