首页
  • 监控

    • grafana
    • prometheus
  • 学习笔记

    • 《核心系统命令实战》
    • 《MySQL 是怎样运行的:从根儿上理解 MySQL》
    • 《Ansible权威指南》
  • 博客搭建
  • git
  • python
  • 友情链接
  • 文档编写规范
  • 我用过的电脑
  • 喷涂相关
  • 每日一溜
关于
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

小刘说

砥砺前行
首页
  • 监控

    • grafana
    • prometheus
  • 学习笔记

    • 《核心系统命令实战》
    • 《MySQL 是怎样运行的:从根儿上理解 MySQL》
    • 《Ansible权威指南》
  • 博客搭建
  • git
  • python
  • 友情链接
  • 文档编写规范
  • 我用过的电脑
  • 喷涂相关
  • 每日一溜
关于
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • zabbix

  • docker

  • kubernetes

  • harbor

  • mysql

  • nexus

  • jenkins

  • elasticsearch

    • elasticsearch升级
    • elasticdump使用
      • npm安装
        • 非root用户安装
        • root用户安装
      • elasticdump安装
        • 在线安装
        • 离线安装
      • elasticdump使用
        • 拷贝分词,映射,数据
        • elasticsearch 用户名密码认证
        • 备份到文件
  • 学习笔记

  • apache2.2升级2.4
  • heredoc(cat EOF)
  • Rocky linux 9 初始化
  • 运维
  • elasticsearch
小刘
2022-09-20
目录

elasticdump使用

# elasticdump使用

官方github地址 (opens new window)

# npm安装

安装包下载:nodejs 中文网 (opens new window)

# 非root用户安装

下载 nodejs,解压,并删除压缩包:

wget https://npmmirror.com/mirrors/node/v16.17.0/node-v16.17.0-linux-x64.tar.xz
tar xvf node-v16.17.0-linux-x64.tar.xz && rm -rf node-v16.17.0-linux-x64.tar.xz
1
2

创建新文件夹,用来存放nodejs:

mkdir -p ~/tools
1

把刚才解压出来的文件夹,移动到tools文件夹下并重命名为nodejs:

mv node-v16.17.0-linux-x64 tools/nodejs
1

配置环境变量:

cat <<'EOF' >> ~/.bashrc
export PATH="${PATH}:${HOME}/tools/nodejs/bin" 
EOF
1
2
3

使修改立即生效:

source ~/.bashrc
1

验证版本:

npm --version
node -V
1
2

# root用户安装

yum -y install npm
1

# elasticdump安装

# 在线安装

npm install elasticdump -g
1

# 离线安装

有时候线上环境主机无法访问互联网,这个时候就需要离线安装。

在可联网机器上下载 npm-pack-all :

npm install npm-pack-all -g
1

在可联网机器上打包离线安装包,查看 npm 本地目录位置在哪:

npm config ls | grep prefix
1

; npm local prefix = /home/test/tools 进入 elasticdump 本地目录下的 lib/node_modules/elasticdump/ 目录下,执行 npm-pack-all ,会生成 .tgz 文件:

cd /home/test/tools/lib/node_modules/elasticdump/
npm-pack-all
1
2

把 .tgz 拷贝到离线安装的机器,执行:

npm install elasticdump-xxx.tgz -g
1

# elasticdump使用

注:普通的导入导出是100条数据一次,如果是大批量数据的话就很耗时间。--limit 是一个限制大小的参数,可以根据需求来进行调整其大小。

--limit
                    How many objects to move in batch per operation
                    limit is approximate for file streams
                    (default: 100)
1
2
3
4

# 拷贝分词,映射,数据

#拷贝analyzer分词
elasticdump \
  --input=http://production.es.com:9200/my_index \
  --output=http://staging.es.com:9200/my_index \
  --type=analyzer
#拷贝mapping映射
elasticdump \
  --input=http://production.es.com:9200/my_index \
  --output=http://staging.es.com:9200/my_index \
  --type=mapping
#拷贝data数据
elasticdump \
  --input=http://production.es.com:9200/my_index \
  --output=http://staging.es.com:9200/my_index \
  --type=data
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

# elasticsearch 用户名密码认证

有些符号在URL中是不能直接传递的,如果要在URL中传递这些特殊符号 (opens new window),那么就要使用他们的编码了。编码的格式为:%加字符的ASCII码,即一个百分号%,后面跟对应字符的ASCII(16进制)码值。例如 空格的编码值是"%20"。

elasticsearch 配置用户名密码时,如果密码有特殊字符,需要针对进行编码,URL在线编码解码 (opens new window),也可以采取 --httpAuthFile=xxx 的格式进行加载用户名密码:

--httpAuthFile
                    When using http auth provide credentials in ini file in form
                    `user=<username>
                    password=<password>`
1
2
3
4

另外一种方式是 --input 参数和 --output 参数的的 url 中添加账号密码,如果密码有特殊字符,同样需要针对密码进行编码:

elasticdump \
  --input=http://prod-username:prod-passowrd@production.es.com:9200/my_index \
  --output=http://stage-username:stage-password@staging.es.com:9200/my_index \
  --type=data
1
2
3
4

# 备份到文件

针对两个es集群网络不通的情况,可以先备份到文件:

# 备份索引数据到文件里:
elasticdump \
  --input=http://production.es.com:9200/my_index \
  --output=/data/my_index_mapping.json \
  --type=mapping
elasticdump \
  --input=http://production.es.com:9200/my_index \
  --output=/data/my_index.json \
  --type=data

# 备份到标准输出,且进行压缩(这里有一个需要注意的地方,我查询索引信息有6.4G,用下面的方式备份后得到一个789M的压缩文件,这个压缩文件解压后有19G):
elasticdump \
  --input=http://production.es.com:9200/my_index \
  --output=$ \
  | gzip > my_index.json.gz

# 把一个查询结果备份到文件中
elasticdump \
  --input=http://production.es.com:9200/my_index \
  --output=query.json \
  --searchBody '{"query":{"term":{"username": "admin"}}}'
# 将备份文件的数据导入ES
elasticdump \
  --input=./data.json \
  --output=http://es.com:9200
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
上次更新: 2024/05/11, 03:55:33

← elasticsearch升级 《核心系统命令实战》→

最近更新
01
kubernetes控制器-Service
08-18
02
kubernetes控制器-Deployment
08-08
03
kubernetes调度基础
07-27
更多文章>
Theme by Vdoing | Copyright © 2023-2024 本站支持IPv6访问 本站支持SSL安全访问
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式