分享

HBase集群数据迁移方案

 陈永正的图书馆 2016-11-25

一、静态迁移方案

1、在Hbase停止的状态下进行数据的迁移。

2、采用Hadoop distcp方式,将以上目录的内容,迁移到另一个集群。
使用add_table.rb进行恢复。

缺点:不太灵活

二、动态迁移方案

-Replication备份方案
-CopyTable方案
-Export and Import方案

1.Replication备份方案

修改hbase-site.xml配置,增加hbase.replication属性,
增加表属性REPLICATION_SCOPE属性。
add_peer增加一个从集群。

2.CopyTable方案

命令:

./hbase org.apache.hadoop.hbase.mapreduce.CopyTable --peer.adr=new cluster ip:2181:/hbase_table
  • 1
  • 1
package org.apache.hadoop.hbase.mapreduce;
/**
 * Tool used to copy a table to another one which can be on a different setup.
 * It is also configurable with a start and time as well as a specification
 * of the region server implementation if different from the local cluster.
 */
public class CopyTable extends Configured implements Tool {
    ...
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

说明:
1、拷贝完成,不需要重启机器,在new cluster中就可以看到该表。
2、稳定性还需要考虑。

3.Export and Import方案

步骤:
(1)在old cluster上执行:

./hbase org.apache.hadoop.hbase.mapreduce.Export test  hdfs://new cluster ip:9000/xxx
  • 1
  • 1
/**
* Export an HBase table.
* Writes content to sequence files up in HDFS.  Use {@link Import} to read it
* back in again.
*/
public class Export {
    ...
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

(2)在new cluster上执行:

./hbase org.apache.hadoop.hbase.mapreduce.Import test hdfs://new cluster ip:9000/xxx
  • 1
  • 1
package org.apache.hadoop.hbase.mapreduce;
/**
 * Import data written by {@link Export}.
 */
public class Import {
    ...
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

说明:
1、一定要写绝对路径,不能写相对路径。
2、在import前,需要将表事先在new cluster中创建好。

三、手动方式

1、从源HBase集群中复制出HBase数据库表到本地目录。

[root@hadoop1 temp]# hadoop fs -get src desc
  • 1
  • 1

2、目标HBase导入

[root@hadoop1 temp]# hadoop fs -put  src desc
  • 1
  • 1

3、修复.META.

[root@hadoop1 temp]# hbase hbck -fixMeta

查看该表的meta数据:
hbase(main):001:0> scan 'hbase:meta'
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

4、重新分配数据到各RegionServer

[root@hadoop1 temp]# hbase hbck -fixAssignments
  • 1
  • 1

优势:
比较灵活,安全(因为不是执行程序的,而是用命令)。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多