elasticsearch单机版本数据迁移

文章目录

前言

在使用elasticsearch的时候,难免少不了进行数据迁移,本文介绍两种试用的数据迁移方法,es版本为7.8.1

方式1:直接拷贝

如果elasticsearch版本是一样的,只是切换服务器,可以直接迁移elasticsearch的文件。例如:

elasticsearch的文件一般为

elasticsearch-data/data/nodes/0

执行命令,在目标服务器里面执行该命令。从源服务器拷贝node到目标服务器中,其中192.168.0.99为目标服务器,当前服务器为源服务器

复制代码
scp -r es@192.168.0.99:/data/elk/elasticsearch-7.8.1/data ./

拷贝完需要重启服务器

方式2:使用elasticdump

注意,使用该命令需要安装nodejs,并且版本大于18.0.0

需先安装nodejs

打开浏览器,搜索nodejs https://nodejs.org/en,并且进行下载

目前安装的版本为:v22.22.3

shell 复制代码
# Download and install nvm:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.5/install.sh | bash

# in lieu of restarting the shell
\. "$HOME/.nvm/nvm.sh"

# Download and install Node.js:
nvm install 22

# Verify the Node.js version:
node -v # Should print "v22.22.3".

# Verify npm version:
npm -v # Should print "10.9.8".

再安装elasticdump

shell 复制代码
npm install -g elasticdump

安装好后,执行命令,看看是否安装成功过

shell 复制代码
elasticdump --help
  • 单个索引的迁移
    本案例是将 192.168.0.99:9200 迁移到 192.168.20.197:9200,索引为jzkj_operate_log_202606
shell 复制代码
# 1. 迁移结构(mapping)
elasticsearch-dump \
--input=http://192.168.20.197:9200/jzkj_operate_log_202606 \
--output=http://192.168.0.99:9200/jzkj_operate_log_202606 \
--type=mapping \
--limit=1000 --timeout=60000

# 2. 迁移数据
elasticsearch-dump \
--input=http://192.168.20.197:9200/jzkj_operate_log_202606 \
--output=http://192.168.0.99:9200/jzkj_operate_log_202606 \
--type=data \
--limit=1000 --concurrency=5 --timeout=60000
  • 匹配索引的迁移
    本案例是将 192.168.0.99:9200 迁移到 192.168.20.197:9200,把所有jzkj_operate_log开头的索引全部备份

注意/data/es_backup存在,且有读写权限

shell 复制代码
# 第一步:dump 源 ES 到本地目录,注意/data/es_backup存在,且有读写权限
multielasticdump \
  --direction=dump \
  --input=http://192.168.0.99:9200 \
  --output=/data/es_backup \
  --match='^jzkj_operate_log.*' \
  --limit=1000 \
  --concurrency=5 \
  --timeout=60000
# 第二步:load 本地目录到目标 ES
multielasticdump \
  --direction=load \
  --input=/data/es_backup \
  --output=http://192.168.20.197:9200 \
  --match='^jzkj_operate_log.*' \
  --limit=1000 \
  --concurrency=5 \
  --timeout=60000
相关推荐
Francek Chen1 小时前
【大数据处理与分析】MapReduce:06 MapReduce编程实践
大数据·hadoop·分布式·mapreduce
Elasticsearch1 小时前
你的 search index 已经是一个 agent 记忆系统 : 用于 Claude Code 的持久化 agent memory
elasticsearch
王小王-1231 小时前
基于 Hadoop 的二手房数据分析与可视化平台项目展示
大数据·hadoop·数据分析·大数据房价分析·二手房价格预测·hive房价数据分析
Elasticsearch1 小时前
使用 LangChain Deep Agents 框架与 Elasticsearch 进行系统性研究
elasticsearch
FII工业富联科技服务2 小时前
“可持续灯塔工厂”技术解密:AI+IoT如何落地端到端碳管理闭环
大数据·人工智能·物联网·ai·数据分析·自动化·制造
Leo.yuan2 小时前
数据建模怎么做?一文解析8种经典数据建模方法
大数据·数学建模
master3362 小时前
git仓库通过脚本完成多个远程仓库同步
大数据·git·elasticsearch
果丁智能2 小时前
物联网智能锁落地实践:破解网约房、民宿身份核验与远程权限管控难题
大数据·人工智能·物联网·智能家居