以下是CentOS下HBase数据迁移的常见步骤及对应工具,可根据场景选择合适方案:
hbase backup create命令备份源表数据。方式1:HBase Shell工具(适合小数据量)
hbase shell
create 'export_table', 'cf' # 目标表需提前创建
export 'source_table', 'export_table' # 导出数据到HDFS临时目录
hdfs dfs -get /hbase/export_table /target/hbase/
import 'export_table'
scan 'export_table'。方式2:HBase Export/Import工具(适合中等数据量)
hbase org.apache.hadoop.hbase.mapreduce.Export 'source_table' '/export/path'
hbase org.apache.hadoop.hbase.mapreduce.Import 'target_table' '/export/path'
```。
方式3:HBase Replication(适合实时同步)
hbase shell
add_peer 'peer1', 'zk1:2181:/hbase' # 添加目标集群Peer
alter 'source_table', {NAME => 'cf', REPLICATION_SCOPE => '1'} # 开启表级复制
start_replication 'peer1' # 启动复制
status 'replication'。方式4:BulkLoad(适合大规模数据快速导入)
hbase org.apache.hadoop.hbase.mapreduce.Export 'source_table' '/export/path'
hbase org.apache.hadoop.hbase.mapreduce.HFileOutputFormat2 \
-Dhbase.table.name=target_table '/export/path' '/hfiles/path'
hbase org.apache.hadoop.hbase.mapreduce.LoadIncrementalHFiles \
'/hfiles/path' 'target_table'
```。
hbase snapshot)保障。hbase.regionserver.handler.count)。| 工具 | 适用场景 | 优点 | 缺点 |
|---|---|---|---|
| HBase Shell | 小数据量、简单结构表 | 操作简单,无需额外工具 | 效率低,不适合大规模数据 |
| Export/Import | 中等数据量、需灵活控制 | 支持增量导出,兼容性强 | 需手动处理HDFS文件 |
| Replication | 实时同步、主备集群 | 低延迟,自动同步增量数据 | 配置复杂,需网络直连 |
| BulkLoad | 超大规模数据、快速入库 | 高效并行,不占用Region资源 | 需先生成HFile,无法实时同步 |
参考来源: