elasticsearch 2.X 数据迁移

需求:从 A 集群迁移到 B 集群,或者某台机器。

实现:理论上,如果是 A 集群和 B 集群机器数量一致,直接 data 目录下对应着 copy 就能解决问题。如果 A 集群和 B 集群机器数量不一致,或者 es 版本不一致,建议使用 es 官方推荐的 snapshot 方式。

注意点:

es 只支持迁移版本大于等于原机器的 es 版本号。

A 集群需要做 nfs 服务,或者 hdfs 等文件分享系统。如果 nfs 共享出现权限问题,注意查看 server 机器的 hosts 文件。是否有指定机器名,一般去掉就能解决。

文件分享系统安装好以后,需要保证 es 的启动用户在 A 集群中 uid 和 gid 一致。可以使用 usermod 和 groupmod 命令。

共享文件挂载:

mount -t nfs 10.253.115.220:/users/elasticsearch/storage/esdata /users/elasticsearch/storage/esdata -o proto=tcp -o nolock

具体命令:

 每台机器需要设置 path.repo

curl -XPUT http://10.253.115.306:9201/_cluster/settings -d'
{
    "transient" : {
    "cluster.routing.allocation.enable" : "none"
    }
}'

重启 es 集群的每台机器

curl -XPUT http://10.253.115.306:9201/_cluster/settings -d'
{
    "transient" : {
    "cluster.routing.allocation.enable" : "all"
    }
}'
curl -XGET http://10.253.115.206:9201/_cat/health

创建快照仓库 

curl -XPUT http://10.253.114.220:9201/_snapshot/client_statistics -d'
{
    "type": "fs", 
    "settings": {
    "location": "/users/elasticsearch/storage/esdata",
    "compress": true,
    "max_snapshot_bytes_per_sec" : "50mb", 
    "max_restore_bytes_per_sec" : "50mb"
    }
}'

创建快照 

curl -XPUT http://10.253.114.220:9201/_snapshot/client_statistics/all-2018-11-20-1?wait_for_completion=true -d'
{
   "indices": "xxxx",
   "ignore_unavailable": "false",
   "include_global_state": false 
}'

CP 存储的快照到目标目标集群的文件夹,如果是集群就需要创建共享目录,如果是单机直接本地文件就可以。

在目标机器,创建快照仓库

curl -XPUT http://12.102.2.28:9201/_snapshot/client_statistics -d'
{
    "type": "fs", 
    "settings": {
    "location": "/users/manager/esdata",
    "compress": true,
    "max_snapshot_bytes_per_sec" : "50mb", 
    "max_restore_bytes_per_sec" : "50mb"
    }
}'

恢复索引 

curl -XPOST http://12.102.2.28:9201/_snapshot/client_statistics/all-2018-11-20-1/_restore -d '
{
    
  "indices": "viewpoint2",
  "include_global_state": false
}'

查看恢复状态 

curl -XGET http://12.102.2.28:9201/_snapshot/client_statistics/all-2018-11-20/_status?pretty

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值