一、静态迁移方案

HBase集群数据迁移方案_apache

HBase集群数据迁移方案_hadoop_02

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
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、拷贝完成,不需要重启机器,在new cluster中就可以看到该表。

2、稳定性还需要考虑。

3.Export and Import方案

步骤:

(1)在old cluster上执行:

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

(2)在new cluster上执行:

./hbase org.apache.hadoop.hbase.mapreduce.Import test hdfs://new cluster ip:9000/xxx
package org.apache.hadoop.hbase.mapreduce;
/**
* Import data written by {@link Export}.
*/
public class Import {
...
}

说明:

1、一定要写绝对路径,不能写相对路径。

2、在import前,需要将表事先在new cluster中创建好。

三、手动方式

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

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

2、目标HBase导入

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

3、修复​​.META.​​表

[root@hadoop1 temp]# hbase hbck -fixMeta

查看该表的meta数据:
hbase(main):001:0> scan 'hbase:meta'

4、重新分配数据到各RegionServer

[root@hadoop1 temp]# hbase hbck -fixAssignments

优势:

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