在CentOS上进行HBase数据迁移,可根据场景选择以下方法,操作前需确保源、目标集群正常运行并完成数据备份:
hbase shell export 'source_table' '/hdfs/export/path' # 导出表数据到HDFS hbase shell import 'target_table' '/hdfs/export/path' # 从HDFS导入数据到目标表 hbase org.apache.hadoop.hbase.mapreduce.Export 'source_table' '/hdfs/export/path' hbase org.apache.hadoop.hbase.mapreduce.HFileOutputFormat2 \ -Dmapreduce.job.output.key.class=org.apache.hadoop.hbase.KeyValue \ -Dmapreduce.job.output.format=org.apache.hadoop.hbase.mapreduce.TableOutputFormat \ '/hdfs/export/path' '/hdfs/hfile/path' hbase org.apache.hadoop.hbase.mapreduce.LoadIncrementalHFiles '/hdfs/hfile/path' 'target_table' hbase-site.xml,添加复制参数:<property><name>hbase.replication</name><value>true</value></property> <property><name>hbase.replication.source.zookeeper.quorum</name><value>source-zookeeper-ip:port</value></property> <property><name>hbase.replication</name><value>true</value></property> <property><name>hbase.replication.target.zookeeper.quorum</name><value>target-zookeeper-ip:port</value></property> hbase shell add_peer 'peer1', 'source-zookeeper-ip:2181:/hbase' start_replication 'peer1' hadoop distcp hdfs://source-cluster:8020/hbase/data/default/source_table hdfs://target-cluster:8020/hbase/data/default/ flush命令确保数据落盘。scan命令校验数据,清理临时文件。根据数据规模和实时性需求选择合适方案,优先使用官方工具(如Replication或Bulk Load)以保证兼容性和效率。