elasticsearch备份

2023-05-16

es集群主机分布
10.4.7.11 node1
10.4.7.12 node2
10.4.7.21 node3
10.4.7.22 nfs

1.在主机10.4.7.22部署nfs
[root@localhost ~]# yum install -y nfs-utils
[root@localhost ~]# systemctl enable rpcbind.service
[root@localhost ~]# systemctl enable nfs-server.service
[root@localhost ~]# systemctl start rpcbind.service
[root@localhost ~]# systemctl start nfs-server.service

#配置那些客户端可以访问
[root@localhost ~]# cat /etc/exports
/data/db/elasticsearch/backup 10.4.7.0/24(rw,sync,all_squash)

#创建nfs共享目录
[root@localhost ~]# mkdir -p /data/db/elasticsearch/backup
[root@localhost ~]# chmod -R 777 /data/db/elasticsearch/backup

#nfs生效
[root@localhost ~]# exportfs -r

#查看是否生效
[root@localhost ~]# exportfs -s

2.es集群的每个节点都要安装客户端
[root@localhost ~]# yum -y install showmount

#开启服务:
[root@localhost ~]# systemctl enable rpcbind.service
[root@localhost ~]# systemctl start rpcbind.service

#查看nfs挂载信息
[root@localhost ~]# showmount -e 10.4.7.22

#创建挂载目录
[root@localhost ~]# mkdir -p /data/es-backups/
[root@localhost ~]# chown -R es.es /data/es-backups/
[root@localhost ~]# chmod -R 777 /data/es-backups/
[root@localhost ~]# mount -t nfs 10.4.7.22:/data/db/elasticsearch/backup /data/es-backups/

#查看是否挂载成功,有需要要添加 /etc/fstab,因为这里挂载是临时的。重启服务器就失效
[root@localhost ~]# df -hT  

#es的配置文件elasticsearch.yml需要添加下面内容,重启es服务
[root@localhost ~]# vi elasticsearch.yml
path.repo: ["/data/es-backups/"]

#重启es服务
[root@localhost ~]# ps aux|grep elasticsearch | grep -v 'grep elasticsearch'|awk '{print $2}'|xargs kill -9 2> /dev/null
[root@localhost ~]# su -c '/app/elasticsearch/bin/elasticsearch -d' es

3.创建快照仓库,可以在任何es节点操作,这里就在10.4.7.11节点操作,返回一个“{"acknowledged":true}” ,表示创建成功
[root@localhost ~]# curl -u elastic:Elastic123 -H "Content-Type: application/json" -XPUT http://10.4.7.11:9200/_snapshot/backup -d'
{
"type": "fs",
"settings": {
"location": "/data/es-backups/2022-01-21",
"compress": true,
"max_snapshot_bytes_per_sec" : "500mb",   #如果不想限制就去掉
"max_restore_bytes_per_sec" : "500mb"    #如果不想限制就去掉
}
}'


备注说明:
1.可在es任一节点操作
2.backup: 指定仓库名称为backup  ,生成的备份文件存放路径为/data/es-backups/2022-01-21
3.max_snapshot_bytes_per_sec,max_restore_bytes_per_sec 限定备份和恢复的数据字节内容大小为50mb,
为了防止磁盘IO过高。数值越大,备份恢复速度越快。50mb为推荐值,IO性能高的机器可不限制

#查看backup仓库是否创建成功
[root@localhost ~]# curl -u elastic:Elastic123 http://10.4.7.11:9200/_cat/repositories?
backup fs

#如果要删除backup这个快照仓库
[root@localhost ~]# curl -u elastic:Elastic123 -XDELETE http://10.4.7.11:9200/_snapshot/backup

#自动会在/data/es-backups/目录下创建一个2022-01-21的目录,下面这个时候是没有任何文件的
[root@localhost ~]# ls -ld /data/es-backups/2022-01-21/
drwxr-xr-x 2 nfsnobody nfsnobody 6 Jan 20 22:40 /data/es-backups/2022-01-21/

#10.4.7.22的nfs主机上自然也多了一个2022-01-21的目录
[root@localhost ~]# ls -ld /data/db/elasticsearch/backup/2022-01-21/


4.创建快照备份
#针对全索引快照备份,返回一个 "accepted" : true"
[root@localhost ~]# curl -u elastic:Elastic123 -XPUT http://10.4.7.11:9200/_snapshot/backup/snapshot_all_indices?pretty

备注说明:
1.指定备份到快照仓库backup里,即备份目录为:/data/es-backups/2022-01-21/
2.快照名称为: snapshot_all_indices

#backup这个快照仓库备份到/data/es-backups/2022-01-21/目录里就有全索引快照备份的内容了
[root@localhost ~]# ll /data/es-backups/2022-01-21/ 
total 24
-rw-r--r-- 1 nfsnobody nfsnobody   450 Jan 20 22:55 index-0
-rw-r--r-- 1 nfsnobody nfsnobody     8 Jan 20 22:55 index.latest
drwxr-xr-x 3 nfsnobody nfsnobody    36 Jan 20 22:55 indices
-rw-r--r-- 1 nfsnobody nfsnobody 10175 Jan 20 22:55 meta-zpvPOoxnSveYdDoK8vez-Q.dat
-rw-r--r-- 1 nfsnobody nfsnobody   260 Jan 20 22:55 snap-zpvPOoxnSveYdDoK8vez-Q.dat

#创建一个索引 user_event_20220110的索引库,后面在head插件上操作更加方便。默认是一个分片,一个副本。
[root@localhost ~]# curl -u elastic:Elastic123 -XPUT http://10.4.7.11:9200/user_event_20220110 

#在创建一个索引库fengge-2022,指定分片跟副本数量

[root@localhost ~]# curl -u elastic:Elastic123 -H "Content-Type: application/json" -XPUT http://10.4.7.11:9200/fengge-2022 -d '
{
   "settings": {
    "index": {
        "number_of_shards": 2,
        "number_of_replicas": 2
         }
    }
}'

#查看创建的索引库信息
[root@localhost ~]# curl -u elastic:Elastic123  -XGET http://10.4.7.11:9200/fengge-2022?pretty
{
  "fengge-2022" : {
    "aliases" : { },
    "mappings" : { },
    "settings" : {
      "index" : {
        "creation_date" : "1642752684916",
        "number_of_shards" : "2",    #两个分片
        "number_of_replicas" : "2",  #两个副本
        "uuid" : "5lff7GXrQBulvK21A_0Ayw",
        "version" : {
          "created" : "7090399"
        },
        "provided_name" : "fengge-2022"
      }
    }
  }
}

#这个user_event_20220110索引添加一个文档,类型叫做 “blog” ,类型随便定义,只是一个标识符而已, 文档ID 是 “123” 或者不指定就是自增,那么这个索引请求就像这样
[root@localhost ~]# curl -u elastic:Elastic123 -H "Content-Type: application/json"  -XPUT http://10.4.7.11:9200/user_event_20220110/blog/123 -d '
{
    "title": {
          "My first blog entry": {
                 "name": "fengge"}
            },
    "text": "Just trying this out",
    "date": "2014/01/01"
}'

#在head可以查看

5.针对指定某个单独索引快照备份(为了区分不同索引备份目录,建议仓库用索引名称命名)
a.先针对索引创建仓库,返回一个"{"acknowledged":true}" 表示创建成功。
[root@localhost ~]# curl -u elastic:Elastic123 -H "Content-Type: application/json"  -XPUT http://10.4.7.11:9200/_snapshot/user_event_20220110 -d'
{
"type": "fs",
"settings": {
"location": "/data/es-backups/user_event_20220110",
"compress": true,
"max_snapshot_bytes_per_sec" : "500mb",
"max_restore_bytes_per_sec" : "500mb"
}
}'

b.备份这个user_event_20220110这个索引到user_event_20220110快照仓库里。返回信息里有shards":{"total":1,"failed":0,"successful":1}}},没有error,表示成功。
[root@localhost ~]# curl -u elastic:Elastic123 -H "Content-Type: application/json" -XPUT http://10.4.7.11:9200/_snapshot/user_event_20220110/user_event_20220110?wait_for_completion=true -d '
{
"indices": "user_event_20220110",  #这里可以指定多个需要备份的索引名字,它们之间用逗号间隔。
"ignore_unavailable": "true",
"include_global_state": false
}'

备注说明:
1.创建的仓库名为: user_event_20220110
2.存放的文件目录为: /data/es-backups/user_event_20220110
3.indices:指定索引源为: user_event_20220110
4.增加?wait_for_completion=true参数是为了执行完成返回结果状态


6.恢复快照备份数据到es集群
a.针对全索引快照备份的恢复操作,前提要恢复的索引在es集群是不存在的,否则恢复错误。
[root@localhost ~]# curl -u elastic:Elastic123 -XPOST http://10.4.7.11:9200/_snapshot/backup/snapshot_all_indices/_restore

备注说明:
1.指定要恢复仓库名称:backup
2.指定要恢复快照备份名称:snapshot_all_indices


b.针对某个指定索引的快照备份恢复操作,如果存在这个恢复的索引,需要先关闭这个索引,
否则索引写操作会影响恢复,于是关闭user_event_20220110这个索引
[root@localhost ~]# curl -u elastic:Elastic123 -XPOST http://10.4.7.11:9200/user_event_20220110/_close

针对索引user_event_20220110快照恢复
[root@localhost ~]# curl -u elastic:Elastic123 -XPOST http://10.4.7.11:9200/_snapshot/user_event_20220110/user_event_20220110/_restore

备注说明:
1.指定仓库名称: user_event_20220110
2.指定快照备份名称: user_event_20220110

#恢复索引后,需要打开这个索引,不然这个索引无法进行写数据
[root@localhost ~]#  curl -u elastic:Elastic123 -XPOST http://10.4.7.11:9200/user_event_20220110/_open

c.再备份所有索引中恢复指定的索引来恢复
[root@localhost ~]# curl -u elastic:Elastic123  -H "Content-Type: application/json" -XPOST http://10.4.7.11:9200/_snapshot/backup/snapshot_all_indices/_restore?wait_for_completion=true -d '
{
  "indices": "index_1,index_2", ##index_1就是你想指定恢复索引名字,多个索引用英文逗号间隔。
  "rename_pattern": "index_(.+)",  ##查找所提供的模式能匹配上的正在恢复的索引。
  "rename_replacement": "restored_index_$1"  ##然后把它们重命名成替代的模式。
}'

参数注解:
####上面这个这个会恢复 index_1,index_2 到你及群里,但是重命名成了分别为: restored_index_1 ,restored_index_2
####这里还有两个隐藏参数
####ignore_unavailable设置为true,如果某些索引不可用,恢复过程还是会成功的。
####include_global_state设置为true,存储了集群的state,还会同时恢复一些template。


#####恢复后的显示结果如下#########
{"accepted":true}


7.操作命令
#.查看已存在仓库
[root@localhost ~]# curl -u elastic:Elastic123 -XGET http://10.4.7.11:9200/_cat/repositories?

#查看已存在快照
[root@localhost ~]# curl -u elastic:Elastic123 -XGET http://10.4.7.11:9200/_snapshot?pretty

#删除user_event_20220110快照仓库里user_event_20220110快照
[root@localhost ~]# curl -u elastic:Elastic123 -XDELETE http://10.4.7.11:9200/_snapshots/user_event_20220110/user_event_20220110

#删除快照仓库user_event_20220110
[root@localhost ~]# curl -u elastic:Elastic123 -XDELETE http://10.4.7.11:9200/_snapshots/user_event_20220110

#查看快照仓库里快照备份的信息,里面有
[root@localhost ~]# curl -u elastic:Elastic123 -XGET http://10.4.7.11:9200/_snapshot/user_event_20220110/user_event_20220110/_status?pretty

#如果在恢复某个索引的时候,你想查看恢复进度
[root@localhost ~]#  curl -u elastic:Elastic123 -XGET http://10.4.7.11:9200/user_event_20220110/_recovery?pretty


 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

elasticsearch备份 的相关文章

  • Elasticsearch 中的分析器有什么用?

    我在理解弹性搜索分析器时遇到一些问题 它的用途是什么以及如何使用它 From 本文 https www elastic co blog found text analysis part 1 有来自源文本的分词器和分词过滤器 我是否无法理解来
  • Elasticsearch 对字符串排序未返回预期结果

    当对包含多个单词的字符串字段进行排序时 Elasticsearch 会拆分字符串值并使用最小值或最大值作为排序值 即 当对值为 老虎之眼 的字段进行升序排序时 排序值为 Eye 当按降序排序时 排序值为 Tiger 假设我的索引中有 老虎之
  • 分割多重多边形

    我可以直接取出零件并把它们取出来作为它们自己的功能吗 或者这会涉及更复杂的东西吗 我正在尝试将其中一张地图拆分为较小的部分以对它们进行索引 https github com simonepri geo maps https github c
  • 分面搜索的后过滤器和全局聚合之间有什么区别?

    搜索界面中的一个常见问题是您想要返回结果的选择 但可能想返回有关所有文档的信息 例如 我想查看所有红色衬衫 但想知道什么 其他颜色可供选择 这有时被称为 多面结果 或者 多面导航 这Elasticsearch 参考中的示例 https ww
  • 为什么我在elasticsearch中需要“store”:“yes”?

    我真的不明白为什么核心类型链接 http www elasticsearch org guide reference mapping core types 它在属性描述中说 例如 对于数字 store 设置为 yes 将实际字段存储在索引中
  • 在elasticsearch结果中显示不匹配的单词

    我想显示返回文档的多单词查询不匹配哪些单词 是否有查询类型或参数来实现此目的 通常 此类不匹配的单词会以删除线字体显示给用户 我得到答案后的示例查询 POST posts search query bool should match nam
  • Logstash删除类型并保留_type

    我有一个logstash 客户端和服务器 客户端将带有logstash的udp输出的日志文件发送到服务器 服务器也运行logstash来获取这些日志 在服务器上 我有一个 json 过滤器 它会在实际日志的字段中提取 json 格式的消息
  • 从中间部分匹配完成建议elasticsearch

    我有一个名为搜索建议具有以下 search suggest type completion analyzer simple payloads true preserve separators false preserve position
  • 局部敏感哈希 - Elasticsearch

    有没有允许在 Elasticsearch 上使用 LSH 的插件 如果是的话 您能否指出该位置并告诉我如何使用它 谢谢 编辑 我发现ES使用了MinHash插件 我怎样才能用这个来比较文件呢 查找重复项的最佳设置是什么 有一个Elastic
  • 从 App Engine 连接到 Kubernetes 引擎

    我们希望使用应用程序引擎灵活的流程来更新位于 Google Kubernetes Engine 上的 ElasticSearch 索引 我们需要通过 http s 地址连接到 ElasticSearch 推荐的方法是什么 我们不想将集群暴露
  • C# Elasticsearch NEST 无法转换 lambda 表达式

    我遇到了与此处描述的完全相同的问题 但未得到解答 ElasticSearch NEST 搜索 https stackoverflow com questions 24615676 elasticsearch nest search I us
  • 将 ElasticSearch SearchResponse 对象转换为 JsonObject

    我想将elasticsearch搜索结果转换为Json对象 我还没有找到任何直接转换的正确方法 SearchResponse response client prepareSearch index setExplain true execu
  • ElasticSearch - 仅获取与搜索响应中所有顶级字段匹配的嵌套对象

    假设我有以下文档 id 1 name xyz users name abc surname def name xyz surname wef name defg surname pqr 我只想获取与搜索响应中的所有顶级字段匹配的嵌套对象 我
  • 无法使用 java 8 在 Windows 10 上安装 elasticsearch 5.1.1

    我正在尝试在安装了 java 8 111 的 Windows 10 笔记本电脑上安装 ElasticSearch 5 1 1 当我尝试安装 Elastic search 时触发错误 C Users 用户名 Downloads elastic
  • search_after 在弹性搜索中如何工作?

    我一直在尝试在我们的应用程序中使用 Elasticsearch 但分页限制为 10k 对我们来说实际上是一个问题 并且由于必须超时问题 滚动 API 也不是推荐的选择 我发现 Elasticsearch 有一个叫做 search after
  • 从 node.js 创建对 AWS ES 实例的有效签名请求

    我试图找到一个示例 说明如何连接到 Node js 中的 AWS ES 实例 然后通过一个简单的请求访问 ES 集群 我正在尝试使用elasticsearch节点包 https www npmjs com package elasticse
  • 尝试在 ElasticSearch 中查询和聚合,但聚合不起作用 - elasticsearch.js 客户端

    我尝试查询我的数据集有两个目的 匹配一个术语 可转售 true 按价格对结果进行排序 最低到最高 数据集 文档是 data resellable true startingPrice 0 id 4emEe r x5DRCc5 buyNowP
  • NEST 1.0:请参阅 Fiddler 上的请求

    我刚刚更新到 NEST 1 0 我在远程服务器 不是本地主机 上有 Elastic Search 通常我在使用 Fiddler 发送和接收请求时没有任何问题 更新后 bammm 没有检测到任何请求 但我的应用程序发出这些请求没有任何问题 你
  • Elasticsearch 在 Mac 上存储数据的位置

    类似的问题this one https stackoverflow com questions 24694201 where are data files of elasticsearch on a standard debian inst
  • Elastic Search 启动错误 - “\Common 此时出现意外。”

    我已经下载并解压了elasticsearch 当我运行批处理文件 elasticsearch bat 时 出现以下错误 Common was unexpected at this time Solved 通过编辑 bat 文件的第 46 行

随机推荐

  • CMake中include_directories的使用

    CMake中include directories命令用于在构建 build 中添加包含目录 其格式如下 include directories AFTER BEFORE SYSTEM dir1 dir2 将给定的目录添加到编译器 comp
  • CMake中target_link_libraries的使用

    CMake中的target link libraries命令用于指定链接给定目标和 或其依赖项时要使用的库或标志 来自链接库目标的使用要求将被传播 propagated 目标依赖项的使用要求会影响其自身源代码的编译 其格式如下 xff1a
  • CMake中install的使用

    CMake中的install命令用于指定安装时要运行的规则 xff0c 其格式如下 xff1a install TARGETS targets EXPORT lt export name gt RUNTIME DEPENDENCIES ar
  • 相机的内参和外参介绍

    注 xff1a 以下相机内参与外参介绍除来自网络整理外全部来自于 视觉SLAM十四讲从理论到实践 第2版 中的第5讲 xff1a 相机与图像 xff0c 为了方便查看 xff0c 我将每节合并到了一幅图像中 相机与摄像机区别 xff1a 相
  • Linux下常用的C/C++开源Socket库

    1 Linux Socket Programming In C 43 43 http tldp org LDP LG issue74 tougher html 2 ACE http www cs wustl edu schmidt ACE
  • C++11中unique_ptr的使用

    在C 43 43 中 xff0c 动态内存的管理是通过一对运算符来完成的 xff1a new xff0c 在动态内存中为对象分配空间并返回一个指向该对象的指针 xff0c 可以选择对对象进行初始化 xff1b delete xff0c 接受
  • 2021年校招软件测试工程师经典面试题,月薪15K你需要掌握哪些知识点?

    软件测试工程师 xff0c 和开发工程师相比起来 xff0c 前期可能不会涉及太深奥的内容 xff0c 但是涉及的面还是比较广的 面试实习生或者一年左右的岗位 xff0c 问的也主要是一些基础性的问题比较多 涉及的知识主要有MySQL数据库
  • 矩阵特征分解介绍及雅克比(Jacobi)方法实现特征值和特征向量的求解(C++/OpenCV/Eigen)

    对角矩阵 diagonal matrix xff1a 只在主对角线上含有非零元素 xff0c 其它位置都是零 xff0c 对角线上的元素可以为0或其它值 形式上 xff0c 矩阵D是对角矩阵 xff0c 当且仅当对于所有的i j Di j
  • HTTP解析库http-parser简介及使用

    http parser是一个用C编写的HTTP消息解析器 xff0c 可以解析请求和响应 xff0c 被设计用于高性能HTTP应用程序 它不会进行任何系统调用及内存分配 xff0c 它不会缓冲数据 xff0c 它可以被随时中断 根据你的体系
  • k8s之multus cni

    通常情况下在k8s中 xff0c 一个pod只有一个接口 xff0c 用于集群网络中pod和pod通信 xff0c 而multus定义了一种crd Kubernetes Network Custom Resource Definition
  • 【机器学习】浅析机器学习各大算法的适用场景

    最近在参加一个分类算法竞赛 xff0c 也正好整理各个分类机器学习算法的简单介绍 xff0c 应用场景和优缺点 资源来自网上和自己个人理解 一 逻辑回归模型 1 理解逻辑回归模型 xff08 LR xff09 逻辑回归是一种分类算法 xff
  • 【机器学习】异常检测算法之(KNN)-K Nearest Neighbors

    sklearn库里的KNN并没有直接用于异常检测 xff0c 但是包含了距离计算的函数 xff0c 所以我们应用PyOD中KNN库进行异常检测 xff0c 里面基本上也是调用sklearn的函数进行计算 xff0c 并进行了一些加工 一 图
  • 异常检测从入门到应用

    作者 xff1a 成森 64 知乎 来源 xff1a https zhuanlan zhihu com p 116235115 异常检测 Anomaly Detection 作为机器学习的一个重要分支 xff0c 实际应用领域广泛 xff0
  • Jetson Nano配置踩坑全记录

    Jetson Nano配置踩坑全记录 Jetson Nano相关参数 xff1a JetPack 4 6 xff0c cuda 10 2 xff0c SD卡内存 xff1a 512G 一 Jetson Nano系统镜像烧录 在Nvidia官
  • kubeadm的rbac

    什么是 Kubernetes RBAC 基于角色的访问控制 xff08 Role Based Access Control 即 34 RBAC 34 xff09 xff1a 使用 rbac authorization k8s io API
  • kubeadm部署dashboard-2.0.0版本

    kubeadm部署dashboard 2 0 0版本 创建dashboard的secret的私钥 root 64 yunwei CA openssl genrsa out od com key 2048 创建dashboard的secret
  • redis5.0的主从跟哨兵

    redis的主从跟哨兵 安装redis 5 0 12 下载地址 xff1a https download redis io releases 1 下载安装redis root 64 master01 cd opt root 64 maste
  • ROS运行gazebo提示“process has die”问题-已解决

    ROS运行gazebo提示 process has die 问题 已解决 解决方案概述升级gazebo方法 解决方案概述 无数次出现这个问题 xff0c 看了好多教程 xff0c 有的是把这个命令添加到 bashrc文件中 xff1a ex
  • Elasticsearch7.9集群部署,head插件,canal同步mysql数据到es,亲自测试,无坑

    Elasticsearch集群部署 1 服务器规划 10 4 7 11 node1 10 4 7 12 node2 10 4 7 13 node3 1 集群相关 一个运行中的 Elasticsearch 实例称为一个节点 xff0c 而集群
  • elasticsearch备份

    es集群主机分布 10 4 7 11 node1 10 4 7 12 node2 10 4 7 21 node3 10 4 7 22 nfs 1 在主机10 4 7 22部署nfs root 64 localhost yum install