我有一个自托管的 Elasticsearch 6.2 集群(2 个主节点,每个主节点约 200Gb 数据)。
我计划迁移到 AWS Elasticsearch 服务但无法通过 ssh 进入。
将所有索引从旧 ES 集群移动到云集群的最快方法是什么?
在自托管 ES 上,我可以将索引文件夹复制到新的 ES,就这样。
答案1
使用转储和恢复 Elasticsearch 数据的工具,例如 Elasticdump(https://www.npmjs.com/package/elasticdump)。
您可以轻松地bash
将所有索引从一个实例转移到另一个实例,如下所示:
old_instance="http://old_address:9200" new_instance="http://new_address:9200" es_indexes=$(curl -s "${old_instance}/_cat/indices" | awk'{打印$3}') 对于 $es_indexes 中的索引;执行 elasticdump \ --输入=“${old_instance}/${index}” \ --输出="${new_instance}/${index}" \ --类型=映射 elasticdump \ --输入=“${old_instance}/${index}” \ --输出="${new_instance}/${index}" \ --类型=数据 完毕
答案2
我暂时为此创建了一个 shell 脚本 -
Github-https://github.com/vivekyad4v/aws-elasticsearch-domain-migration/blob/master/migrate.sh
#!/bin/bash
#### Make sure you have Docker engine installed on the host ####
###### TODO - Support parameters ######
export AWS_ACCESS_KEY_ID=xxxxxxxxxx
export AWS_SECRET_ACCESS_KEY=xxxxxxxxx
export AWS_DEFAULT_REGION=ap-south-1
export AWS_DEFAULT_OUTPUT=json
export S3_BUCKET_NAME=my-es-migration-bucket
export DATE=$(date +%d-%b-%H_%M)
old_instance="https://vpc-my-es-ykp2tlrxonk23dblqkseidmllu.ap-southeast-1.es.amazonaws.com"
new_instance="https://vpc-my-es-mg5td7bqwp4zuiddwgx2n474sm.ap-south-1.es.amazonaws.com"
delete=(.kibana)
es_indexes=$(curl -s "${old_instance}/_cat/indices" | awk '{ print $3 }')
es_indexes=${es_indexes//$delete/}
es_indexes=$(echo $es_indexes|tr -d '\n')
echo "index to be copied are - $es_indexes"
for index in $es_indexes; do
# Export ES data to S3 (using s3urls)
docker run --rm -ti taskrabbit/elasticsearch-dump \
--s3AccessKeyId "${AWS_ACCESS_KEY_ID}" \
--s3SecretAccessKey "${AWS_SECRET_ACCESS_KEY}" \
--input="${old_instance}/${index}" \
--output "s3://${S3_BUCKET_NAME}/${index}-${DATE}.json"
# Import data from S3 into ES (using s3urls)
docker run --rm -ti taskrabbit/elasticsearch-dump \
--s3AccessKeyId "${AWS_ACCESS_KEY_ID}" \
--s3SecretAccessKey "${AWS_SECRET_ACCESS_KEY}" \
--input "s3://${S3_BUCKET_NAME}/${index}-${DATE}.json" \
--output="${new_instance}/${index}"
new_indexes=$(curl -s "${new_instance}/_cat/indices" | awk '{ print $3 }')
echo $new_indexes
curl -s "${new_instance}/_cat/indices"
done