• 记录一次NFS快照es集群索引备份


    环境搭建:

    ES NFS IP
    es(主) nfs(客户端) 192.168.72.158
    es(从) nfs(服务端) 192.168.72.152
    es(从) nfs(客户端) 192.168.72.153

    关闭防火墙:systemctl stop firewalld
    永久关闭防火墙:systemctl disable firewalld
    关闭selinux:sentenforce 0
    永久关闭selinux

    搭建、启动es集群

    安装nfs(三台都装)

    安装包
    链接: https://pan.baidu.com/s/17p1fl7FM9jMEo-yfe_U0KA 密码: ddgq

    cd /nfs
    rpm -ivh --nodeps --force *.rpm
    

    启动nfs:

    systemctl start rpcbind.service
    systemctl start nfs-server.service
    

    开机自启nfs:

    systemctl enable rpcbind.service
    systemctl enable nfs-server.service
    

    创建共享目录

    以下指令在NFS服务端操作

    mkdir -p /data/es/backup
    chown -R elasticsearch.elasticsearch /data/es/backup
    chmod 777 /data/es/backup
    

    修改配置文件

    vim /etc/exports
    追加以下内容
    /data/es/backup /data/es/backup *(rw,sync,no_root_squash,no_subtree_check)
    

    立刻生效

    exportfs -a ##立刻生效
    exportfs -r ##重新挂载
    exportfs -v ##显示共享目录
    export -u:表示卸载某一个目录 
    

    以下指令在NFS客户端操作
    客户端可以创建任意目录,目的是用nfs将服务端共享目录挂载到客户端本地,实现文件同步共享。下面客户端以创建/home/tgram为例

    mkdir /home/tgram 
    chown -R elasticsearch.elasticsearch /home/tgram
    chmod 777 /home/tgram
    

    挂载共享目录(客户端操作)

    mount -t nfs 192.168.1.190:/data/es/backup /home/tgram/
    

    修改es配置文件,重启es集群(三台都操作)

    在elasticsearchc.yml中加入一行
    path.repo:    /home/tgram  此处是客户端创建共享目录的路径
    
    ./elasticsearch &
    

    创建备份仓库

    curl -H "Content-Type: application/json" -XPUT 'http://192.168.72.152:9200/_snapshot/EsBackup_zip' -d '{
    > "type": "fs",
    > "settings": {
    > "location": "/home/tgram/compress_snapshot",
    > "compress": true
    > }
    > }'
    [2021-01-04T15:36:45,126][INFO ][o.e.r.RepositoriesService] [node01.tgram.com] put repository [EsBackup_zip]
    {"acknowledged":true}
    

    查看刚创建的仓库

    [root@localhost home]# curl -XGET 'http://192.168.72.152:9200/_snapshot?pretty'
    {
      "EsBackup_zip" : {
        "type" : "fs",
        "settings" : {
          "compress" : "true",
          "location" : "/home/tgram/compress_snapshot"
        }
      }
    }
    

    备份指定索引数据

    (假设要备份全部索引数据, 则可以:)

    [root@localhost home]# curl -H "Content-Type: application/json" -XPUT 'http://192.168.72.152:9200/_snapshot/EsBackup_zip/snapshot_all'
    [2021-01-04T15:54:14,046][INFO ][o.e.s.SnapshotsService   ] [node01.tgram.com] snapshot [EsBackup_zip:snapshot_all/8nMl1krVQvaI1VkYLg7fKw] started
    {"accepted":true}[root@localhost home]# [2021-01-04T15:54:14,125][INFO ][o.e.s.SnapshotsService   ] [node01.tgram.com] snapshot [EsBackup_zip:snapshot_all/8nMl1krVQvaI1VkYLg7fKw] completed with state [SUCCESS]
    

    恢复整个快照索引

    [root@localhost compress_snapshot]# curl -H "Content-Type: application/json" -XPOST 'http://192.168.72.158:9200/_snapshot/EsBackup_zip/snapshot_all/_restore'
    {"snapshot":{"snapshot":"snapshot_all","indices":[],"shards":{"total":0,"failed":0,"successful":0}}}
    

    查看恢复状态

    [root@localhost compress_snapshot]# curl -H "Content-Type: application/json" -XGET  'http://192.168.72.158:9200/_snapshot/EsBackup_zip/snapshot_all/_status'
    {"snapshots":[{"snapshot":"snapshot_all","repository":"EsBackup_zip","uuid":"8nMl1krVQvaI1VkYLg7fKw","state":"SUCCESS","include_global_state":true,"shards_stats":{"initializing":0,"started":0,"finalizing":0,"done":0,"failed":0,"total":0},"stats":{"incremental":{"file_count":0,"size_in_bytes":0},"total":{"file_count":0,"size_in_bytes":0},"start_time_i
    ``` 
    
    ##查看索引、删除索引
    
    ```shell
    [root@localhost compress_snapshot]# curl -H "Content-Type: application/json" -XGET 'http://192.168.72.158:9200/_cat/indices?v'
    health status index       uuid                   pri rep docs.count docs.deleted store.size pri.store.size
    green  open   commodity   4sUZXNX0SvO3ZbpwlILQ3A   5   1          0            0      2.5kb          1.2kb
    green  open   label_11009 0oX0nZU_RK-iflF6filOeg   5   1          1            0      7.7kb          3.8kb
    
    [root@localhost compress_snapshot]# curl -H "Content-Type: application/json" -XDELETE 'http://192.168.72.158:9200/commodity'
    [2021-01-04T19:20:43,236][INFO ][o.e.c.m.MetaDataDeleteIndexService] [node01.tgram.com] [commodity/4sUZXNX0SvO3ZbpwlILQ3A] deleting index
    {"acknowledged":true}
    
    [root@localhost compress_snapshot]# curl -H "Content-Type: application/json" -XDELETE 'http://192.168.72.158:9200/label_11009'
    [2021-01-04T19:21:00,756][INFO ][o.e.c.m.MetaDataDeleteIndexService] [node01.tgram.com] [label_11009/0oX0nZU_RK-iflF6filOeg] deleting index
    {"acknowledged":true}
    

    再次查看发现所以已删除

    [root@localhost compress_snapshot]# curl -H "Content-Type: application/json" -XGET 'http://192.168.72.158:9200/_cat/indices?v'
    health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
    

    恢复单个索引

    [root@localhost compress_snapshot]# curl -H "Content-Type: application/json" -XPOST 'http://192.168.72.158:9200/_snapshot/EsBackup_zip/snapshot2_all/_restore' -d '{ 
    > "indices": "label_11009",
    > "rename_replacement": "label_22009"
    > }'
    >
    


    本文共设计两个索引commodity、label_11009
    两个快照snapshot_all、snapshot2_all
    一个仓库 compress_snapshot

    snapshot2_all 快照名称
    commodity 原有索引名称
    label_11009 原有索引名称
    label_22009 恢复单个索引要替换的名称

    参考:
    https://blog.moguang.me/2017/10/31/bigdata/es-backup-restore-md/#5-恢复备份索引

  • 相关阅读:
    MyBatis常见面试题以及解读
    如何防止sql注入攻击
    宝塔Linux面板基础命令
    Centos7配置静态ip
    宝塔Linux面板安装
    idea中安装阿里巴巴的代码规范插件
    idea中快速将类中的属性转为Json字符串的插件
    创建线程的四种方式
    sleep()方法与wait()方法的区别
    解决线程安全的几种方式
  • 原文地址:https://www.cnblogs.com/homjun/p/14262875.html
Copyright © 2020-2023  润新知