admin管理员组

文章数量:1550528

一、环境信息

1.1、操作系统

centos7

1.2、Elasticsearch版本

7.13.4

1.3、主机清单

集群节点名称内网IPKibana
cfg-cluster-1node-01192.168.30.13http://localhost:5602
node-02192.168.30.14
node-03192.168.30.15

1.4、需求

集群快照存储路径: /elastic/backup

仓库名:my_backup

快照名:snapshot_1

快照含索引: snapshot_index_1snapshot_index_2

二、配置

2.1.配置文件elasticsearch.yml(所有节点都要配置),并重启集群

path.repo: "/elastic/backup"

2.2.配置集群共享目录 “/elastic/backup”

参照另一篇 Centos7 NFS共享目录(单机版)

2.3.按官方文档进行操作

2.3.1 注册快照仓库

PUT /_snapshot/my_backup
{
  "type": "fs",
  "settings": {
    "location": "/elastic/backup"
  }
}

location配置的路径 ,必须和集群 elasticsearh.yml 中配置path.repo保持一致

2.3.2 创建快照

创建测试索引数据

PUT snapshot_index_1/_doc/1
{
  "title":"index_1"
}
PUT snapshot_index_2/_doc/1
{
  "title":"index_2"
}

创建快照

PUT /_snapshot/my_backup/snapshot_1?wait_for_completion=true
{
  "indices": "snapshot_index_1,snapshot_index_2",
  "ignore_unavailable": true,
  "include_global_state": false
}

2.3.3 挂载可搜索快照(option)

POST /_snapshot/my_backup/snapshot_1/_mount?wait_for_completion=true
{
  "index": "snapshot_index_1", 
  "renamed_index": "renamed_snapshot_index_1", 
  "index_settings": { 
    "index.number_of_replicas": 0
  },
  "ignore_index_settings": [ "index.refresh_interval" ] 
}

验证

# 通过可搜索快照挂载 索引名查询,可查到索引数据
GET renamed_snapshot_index_1/_search

结果 仅body体

{
  "_index" : "renamed_snapshot_index_1",
  "_type" : "_doc",
  "_id" : "1",
  "_score" : 1.0,
  "_source" : {
    "title" : "index_1"
  }
}

2.3.4 还原快照

POST /_snapshot/my_backup/snapshot_1/_restore
{
  "indices": "snapshot_index_1,snapshot_index_2",
  "ignore_unavailable": true,
  "include_aliases": false
}

2.3.5 删除快照

DELETE /_snapshot/my_backup/snapshot_1

三、常见问题解答

3.1、集群启动报错

uncaught exception in thread [main]
java.lang.IllegalStateException: Unable to access 'path.repo' (/elastic/backup)
Likely root cause: java.nio.file.AccessDeniedException: /elastic
	at sun.nio.fs.UnixException.translateToIOException(UnixException.java:84)
	at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
	at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
	at sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:384)
	at java.nio.file.Files.createDirectory(Files.java:674)
	at java.nio.file.Files.createAndCheckIsDirectory(Files.java:781)
	at java.nio.file.Files.createDirectories(Files.java:767)
	at org.elasticsearch.bootstrap.Security.ensureDirectoryExists(Security.java:299)
	at org.elasticsearch.bootstrap.FilePermissionUtils.addDirectoryPath(FilePermissionUtils.java:59)
	at org.elasticsearch.bootstrap.Security.addFilePermissions(Security.java:223)
	at org.elasticsearch.bootstrap.Security.createPermissions(Security.java:154)
	at org.elasticsearch.bootstrap.Security.configure(Security.java:104)
	at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:212)
	at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:397)
	at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159)
	at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150)
	at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:75)
	at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:116)
	at org.elasticsearch.cli.Command.main(Command.java:79)
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:115)
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:81)
For complete error details, refer to the log at /usr/local/elasticsearch-7.13.4/logs/cfg-cluster-1.log

原因:
yml配置了 path.repo,但是服务器上该目录不存在 /elastic/backup

解决:
创建目录并赋权 :

 mkdir -p  /elastic/backup
 chmod 777 -R /elastic

3.2、注册snapshot仓库报错

This might indicate that the store [/elastic/backup] is not shared between this node and the master node or that permissions on the store don't allow reading files written by the master node]; 

原因:
elastic用户没权限访问master的存储: /elastic/backup,即该目录没做集群共享,从节点无法访问主节点的 /elastic/backup 目录

解决:
参照上文 二、配置 > 2.配置集群共享目录 即: Centos7 NFS共享目录(单机版)

3.3、还原快照报错

{
  "error" : {
    "root_cause" : [
      {
        "type" : "snapshot_restore_exception",
        "reason" : "[my_backup:snapshot_1/w-dkxwRWRky8SBceJpomnw] cannot restore index [snapshot_index_1] because an open index with same name already exists in the cluster. Either close or delete the existing index or restore the index under a different name by providing a rename pattern and replacement name"
      }
    ],
    "type" : "snapshot_restore_exception",
    "reason" : "[my_backup:snapshot_1/w-dkxwRWRky8SBceJpomnw] cannot restore index [snapshot_index_1] because an open index with same name already exists in the cluster. Either close or delete the existing index or restore the index under a different name by providing a rename pattern and replacement name"
  },
  "status" : 500
}

原因: 集群中已存在和要还原索引同名的索引

解决:

  1. 删除已存在同名索引在还原

  2. 还原索引时重命名,例如 snapshot_index_1 还原成 snapshot_index_1

    POST /_snapshot/my_backup/snapshot_1/_restore
    {
      "indices": "snapshot_index_1",
      "ignore_unavailable": true,
      "include_global_state": false,              
      "rename_pattern": "snapshot_index_(.+)",
      "rename_replacement": "restored_index_$1",
      "include_aliases": false
    }
    

    验证:

    # 查询新索引
    GET snapshot_restored_index_1/_search
    
    # 结果 仅body体
    {
        "_index" : "snapshot_restored_index_1",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
        	"title" : "index_1"
        }
    }
    

3.4、license不支持

{
  "error" : {
    "root_cause" : [
      {
        "type" : "security_exception",
        "reason" : "current license is non-compliant for [searchable-snapshots]",
        "license.expired.feature" : "searchable-snapshots"
      }
    ],
    "type" : "security_exception",
    "reason" : "current license is non-compliant for [searchable-snapshots]",
    "license.expired.feature" : "searchable-snapshots"
  },
  "status" : 403
}

原因:
可搜索快照/跨集群复制 都是收费功能,需要开启kibana试用功能

见官网: https://www.elastic.co/cn/pricing/

解决:
kibana中,点击 左上角 三横 的菜单,滑到最下面面,Stack Management -> 最左下角菜单 License management -> 正文中 Start a 30-day trial,点击 Start trial开启试用

删除 data 目录后会重置,所以每次删除data后都需要重新开启试用

3.5、版本不匹配

此项官方文档有说明版本兼容性问题,未做验证

见官网:https://www.elastic.co/guide/en/elasticsearch/reference/7.13/snapshot-restore.html#snapshot-restore-version-compatibility

四、参考文档

elasticsearch官方文档:
https://www.elastic.co/guide/en/elasticsearch/reference/7.13/snapshot-restore.html

本文标签: 快照入门教程Elasticsearchsnapshot