首页 > 其他分享 >elasticsearch迁移

elasticsearch迁移

时间:2023-06-12 11:14:41浏览次数:27  
标签:-- 08 elasticsearch 2023 迁移 elasticdump logstash

#第一种办法:elasticdump
#先升级elasticdump 参考https://www.dianjilingqu.com/634305.html

1.下载node.js的安装包
http://wget https://nodejs.org/dist/v10.13.0/node-v10.13.0-linux-x64.tar.gz

2.解压安装包
tar xf node-v10.13.0-linux-x64.tar.gz
mv node-v10.13.0-linux-x64 /usr/local
修改文件夹名称
mv /usr/local/node-v12.18.3-linux-x64 /usr/local/nodejs
设置环境变量

echo export NODEJS_HOME=/usr/local/nodejs
echo export PATH=$PATH:$NODEJS_HOME/bin
echo export NODEJS_PATH=$NODEJS_HOME/lib/node_modules
使生效
source /etc/profile
创建软链接(也可以不创建)

ln -s /usr/local/nodejs/bin/node /usr/local/bin/node
ln -s /usr/local/nodejs/bin/npm /usr/local/bin/npm
验证是否安装成功

npm -v
node -v
通过npm 安装 elasticdump

npm install elasticdump -g (-g全局可用)
进入
cd /usr/local/nodejs/lib/node_modules/elasticdump/bin

可以看到两个命令
elasticdump -> ../lib/node_modules/elasticdump/bin/elasticdump
multielasticdump -> ../lib/node_modules/elasticdump/bin/multielasticdump

#导出
elasticdump   --input=http://'admin:passwd'@172.16.0.118:9200/flyby_hotel_v7    --output=./xiecheng-mapping.json  --type=settings      --ignore-errors

elasticdump   --input=http://'admin:passwd'@172.16.0.118:9200/flyby_hotel_v7    --output=./xiecheng-mapping.json  --type=mapping     --ignore-errors

elasticdump   --input=http://'admin:passwd'@172.16.0.118:9200/flyby_hotel_v7    --output=./xiecheng-mapping.json  --type=data      --ignore-errors



#导入

elasticdump   --input=./xiecheng-settings.json    --output=http://'admin:passwd'@172.16.0.118:9200/flyby_hotel_v7   --type=settings      --ignore-errors

elasticdump   --input=./xiecheng-mapping.json    --output=http://'admin:passwd'@172.16.0.118:9200/flyby_hotel_v7   --type=mapping      --ignore-errors

elasticdump   --input=./xiecheng-mapping.json    --output=http://'admin:passwd'@172.16.0.118:9200/flyby_hotel_v7   --type=data      --ignore-errors


#第二种方法:logstash(推荐)
[root@ES-TEST-A4 ~]# wget https://artifacts.elastic.co/downloads/logstash/logstash-6.8.5.tar.gz
[root@ES-TEST-A4 ~]# tar xf logstash-6.8.5.tar.gz 
[root@ES-TEST-A4 ~]# cd logstash-6.8.5
#修改Logstash的堆内存使用。
Logstash默认的堆内存为1 GB,您需要根据ECS规格配置合适的内存大小,加快集群数据的迁移效率。
进入Logstash的安装目录下,修改Logstash配置文件config/jvm.options,增加-Xms8g和-Xmx8g。
[root@ES-TEST-A4 logstash-6.8.5]# cd config/

#全量迁移
[root@ES-TEST-A4 config]# cat a.conf 
input{
    elasticsearch{
        # 源端ES地址。
        hosts =>  ["http://localhost:9200"]
        # 安全集群配置登录用户名密码。
        user => "elastic"
        password => "passwd"
        # 需要迁移的索引列表,多个索引以英文以逗号(,)分隔。
        index => "flyby_hotel_v*"  #这里可以使用正则。匹配多个索引
        # 以下三项保持默认即可,包含线程数和迁移数据大小和Logstash JVM配置相关。
        docinfo=>true
        slices => 5
        size => 5000
    }
}

filter {
  # 去掉一些Logstash自己加的字段。
  mutate {
    remove_field => ["@timestamp", "@version"]
  }
}

output{
    elasticsearch{
        # 目标端ES地址,可在阿里云Elasticsearch实例的基本信息页面获取。
        hosts => ["123.60.137.89:9200"]
        # 安全集群配置登录用户名密码。
        user => "elastic"
        password => "passwd"
        # 目标端索引名称,以下配置表示索引与源端保持一致。
        index => "%{[@metadata][_index]}"
        # 目标端索引type,以下配置表示索引类型与源端保持一致。
        document_type => "%{[@metadata][_type]}"
        # 目标端数据的id,如果不需要保留原id,可以删除以下这行,删除后性能会更好。
        document_id => "%{[@metadata][_id]}"
        ilm_enabled => false
        manage_template => false
    }
}


#数据同步
[root@ES-TEST-A4 config]# cat a.conf 
input{
    elasticsearch{
        # 源端ES地址。
        hosts =>  ["http://localhost:9200"]
        # 安全集群配置登录用户名密码。
        user => "xxxxxx"
        password => "xxxxxx"
        # 需要迁移的索引列表,多个索引使用英文逗号(,)分隔。
        index => "kibana_sample_data_logs"
        # 按时间范围查询增量数据,以下配置表示查询最近5分钟的数据。
        query => '{"query":{"range":{"@timestamp":{"gte":"now-5m","lte":"now/m"}}}}'
        # 定时任务,以下配置表示每分钟执行一次。
        schedule => "* * * * *"
        scroll => "5m"
        docinfo=>true
        size => 5000
    }
}

filter {
  # 去掉一些Logstash自己加的字段.
  mutate {
    remove_field => ["@timestamp", "@version"]
  }
}


output{
    elasticsearch{
        # 目标端ES地址,可在阿里云Elasticsearch实例的基本信息页面获取。
        hosts => ["http://es-cn-zvp2m4bko0009****.elasticsearch.aliyuncs.com:9200"]
        # 安全集群配置登录用户名密码.
        user => "elastic"
        password => "xxxxxx"
        # 目标端索引名称,以下配置表示索引与源端保持一致。
        index => "%{[@metadata][_index]}"
        # 目标端索引type,以下配置表示索引类型与源端保持一致。
        document_type => "%{[@metadata][_type]}"
        # 目标端数据的id,如果不需要保留原id,可以删除以下这行,删除后性能会更好。
        document_id => "%{[@metadata][_id]}"
        ilm_enabled => false
        manage_template => false
    }
}


#执行
[root@ES-TEST-A4 config]# cd ../
[root@ES-TEST-A4 config]# nohup ./bin/logstash -f ./config/a.conf >/dev/null 2>&1 &

#查看日志
[root@ES-TEST-A4 config]# cd ../logs
[root@ES-TEST-A4 logs]# tail -f logstash-plain.log 
[2023-04-23T18:16:03,762][INFO ][logstash.pipeline        ] Pipeline started successfully {:pipeline_id=>"main", :thread=>"#<Thread:0x7ba0801f run>"}
[2023-04-23T18:16:03,824][INFO ][logstash.inputs.elasticsearch] Slice starting {:slice_id=>0, :slices=>5}
[2023-04-23T18:16:03,824][INFO ][logstash.inputs.elasticsearch] Slice starting {:slice_id=>2, :slices=>5}
[2023-04-23T18:16:03,825][INFO ][logstash.inputs.elasticsearch] Slice starting {:slice_id=>3, :slices=>5}
[2023-04-23T18:16:03,832][INFO ][logstash.inputs.elasticsearch] Slice starting {:slice_id=>4, :slices=>5}
[2023-04-23T18:16:03,843][INFO ][logstash.inputs.elasticsearch] Slice starting {:slice_id=>1, :slices=>5}
[2023-04-23T18:16:03,872][INFO ][logstash.agent           ] Pipelines running {:count=>1, :running_pipelines=>[:main], :non_running_pipelines=>[]}
[2023-04-23T18:16:04,634][INFO ][logstash.agent           ] Successfully started Logstash API endpoint {:port=>9600}
[2023-04-23T18:21:33,009][FATAL][logstash.runner          ] An unexpected error occurred! {:error=>#

#详解
https://help.aliyun.com/document_detail/418418.html#section-gj2-zuc-nrm
https://support.huaweicloud.com/bestpractice-css/css_07_0009.html

#注意
logstash版本最好跟elasticsearch对应。不同版本的logstash版本,conf的字段支不支持也就不一定。根据报错。
[ERROR][logstash.inputs.elasticsearch] Unknown setting 'slices' for elasticsearch
就是不支持slices这个字段。注释或者修改字段重新运行。

如果是全部迁移。不要用*。如果数据出问题。目标es会报错。导致密码失效。需要去掉密码认证。删除所有索引。在开启密码认证。修改密码。才能使用。
如果索引数据很大。建议最好一个一个迁移。如果一次性迁移过多。中途断掉。再次迁移,会造成数据重复。

#第三种方案:先使用elasticdump迁移索引的settings和mapping。然后使用logstash迁移索引的数据。如果直接logstash迁移。可能会因为参数原因导致迁移中断。
[root@elasticsearch-test bin]# elasticdump   --input=http://'admin:passwd'@es-cn-09k1ymh6l001wqa2m.public.elasticsearch.aliyuncs.com:9200/shiji_hotel_detail    --output=http://'admin:passwd'@172.16.0.118:9200/shiji_hotel_detail  --type=settings      --ignore-errors
Thu, 08 Jun 2023 08:28:24 GMT | starting dump
(node:2939) NOTE: We are formalizing our plans to enter AWS SDK for JavaScript (v2) into maintenance mode in 2023.

Please migrate your code to use AWS SDK for JavaScript (v3).
For more information, check the migration guide at https://a.co/7PzMCcy
Thu, 08 Jun 2023 08:28:24 GMT | got 1 objects from source elasticsearch (offset: 0)
Thu, 08 Jun 2023 08:28:24 GMT | sent 1 objects to destination elasticsearch, wrote 1
Thu, 08 Jun 2023 08:28:24 GMT | got 0 objects from source elasticsearch (offset: 1)
Thu, 08 Jun 2023 08:28:24 GMT | Total Writes: 1
Thu, 08 Jun 2023 08:28:24 GMT | dump complete
[root@elasticsearch-test bin]# elasticdump   --input=http://'admin:passwd'@es-cn-09k1ymh6l001wqa2m.public.elasticsearch.aliyuncs.com:9200/shiji_hotel_detail    --output=http://'admin:passwd'@172.16.0.118:9200/shiji_hotel_detail  --type=mapping      --ignore-errors
Thu, 08 Jun 2023 08:28:30 GMT | starting dump
(node:2955) NOTE: We are formalizing our plans to enter AWS SDK for JavaScript (v2) into maintenance mode in 2023.

Please migrate your code to use AWS SDK for JavaScript (v3).
For more information, check the migration guide at https://a.co/7PzMCcy
Thu, 08 Jun 2023 08:28:30 GMT | got 1 objects from source elasticsearch (offset: 0)
Thu, 08 Jun 2023 08:28:30 GMT | got 0 objects from source elasticsearch (offset: 1)
Thu, 08 Jun 2023 08:28:30 GMT | Total Writes: 0
Thu, 08 Jun 2023 08:28:30 GMT | dump complete

标签:--,08,elasticsearch,2023,迁移,elasticdump,logstash
From: https://www.cnblogs.com/anslinux/p/17474444.html

相关文章

  • linux命令行elasticsearch查询工具es2unix
    当想在linux的命令行中查看elasticsearch的状态时,可以用es2unix这个工具,插件地址: https://github.com/elasticsearch/es2unix。它是elasticsearch官方推出的,可以通过命令来查看es的各种状态,安装方法curl-sdownload.elasticsearch.org/es2unix/es>/bin/eschmod+x/bin/es这......
  • postgresql/lightdb批量导入导出数据系列copy/ltuldr/ltldr/lt_bulkload及最佳实践推
    文件位于服务器上,这就限制了使用范围。为此,对于导出,lightdb提供了高性能导出版本ltuldr。对于导入,lightdb在23.1之前提供lt_bulkload,见下文;从23.1开始,支持和oraclesql*loader对应的ltldr。copy可用于快速导入和导出数据,主要用途如下:TheCOPYcommandmovesdatabetweenPostg......
  • wsl2-ubuntu20.04从C盘迁移到F盘
    步骤1)导出到F盘2)从C盘中注销原始的ubuntu系统3)从F盘中重新导入wsl--exportUbuntu-20.04f://wslubuntu2004//ubuntu-20.04.tarwsl-l-vwsl--unregisterUbuntu-20.04wsl--importUbuntu-20.04f://wslubuntu2004f://wslubuntu2004//ubuntu-20.04.tar更多可参考......
  • Linux搭建elasticsearch 7.x 版本
     安装方式传统方式根据平台系统Windows、linux、mac下载安装包以linux为例,进入到想安装的目录位置,下载安装包并解压#进入安装目录cd/home#下载安装包wgethttps://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.17.3-linux-x86_64.tar.gz#解压tar-z......
  • win10 迁移 LTS 子系统 到非系统盘
    脚本下载LxRunOffline:https://github.com/DDoSolitary/LxRunOffline/releases脚本命令.\LxRunOffline.exelist#查看安装的子系统wsl--shutdown#中止所有运行的子系统.\LxRunOffline.exemove-nUbuntu-20.04-dE:\ubuntu20#将名为Ubuntu-20.04的子系统移动......
  • binlog_parse_clickhouse.py(ETL抽数据工具)将MySQL8.0迁移至ClickHouse
    binlog_parse_clickhouse.py(ETL抽数据工具)将MySQL8.0迁移至ClickHouse原理:将解析binlog和执行SQL语句两个过程由两个线程来执行。其中,解析binlog的线程每次解析完一个事件后通过队列将SQL语句传给SQL执行线程,SQL执行线程从队列中取出SQL语句并按顺序依次执行,这样就保......
  • Elasticsearch专题精讲—— REST APIs —— Document APIs —— Reindex API —— 跨
    Reindexfromremote(跨集群索引)https://www.elastic.co/guide/en/elasticsearch/reference/8.8/docs-reindex.html#reindex-from-remoteReindexsupportsreindexingfromaremoteElasticsearchcluster:Reindex支持从远程Elasticsearch集群进行重新索引:curl-XP......
  • ESXI 平台系统在两台DELL R430中快速迁移实现服务器硬件升级实践过程
    ESXI 平台系统在两台DELLR430中快速迁移实现服务器硬件升级实践过程(R430上同系不同型号阵列卡间的数据迁移实践) 背景:现有两台R430服务器,需要把阵列卡为H330的服务器整机替换为H730阵列的服务器(即把H330上的服务器数据内容直接导入H730服务器中使用,H330目前为ESXI6.7虚拟化平台服......
  • Elasticsearch 修改字段类型
    由于ES不能像关系型数据库直接修改类型,所以要借助中间索引来完成1、创建中间索引(字段维护正确的)put:https://localhost/track_bak{"settings":{"index":{"number_of_shards":"3","number_of_replicas":"1&quo......
  • 源码安装redis-migrate-tool(redis迁移工具)部署安装
    源码安装redis-migrate-toolredis-migrate-toolunzipredis-migrate-tool-master.zipcdredis-migrate-tool-masteryum-yinstallautomakelibtoolautoconfbzip2autoreconf-fvi./configuremake./src/redis-migrate-toolrmt.conf配置项修改[source]typ......