• Hbase层
  • hadoop层

hbase层

copyTable 方式

集群间进行数据拷贝

使用说明

  1. Usage: CopyTable [general options] [--starttime=X] [--endtime=Y] [--new.name=NEW] [--peer.adr=ADR] <tablename>
  2. Options:
  3. rs.class hbase.regionserver.class of the peer cluster
  4. specify if different from current cluster
  5. rs.impl hbase.regionserver.impl of the peer cluster
  6. startrow the start row
  7. stoprow the stop row
  8. starttime beginning of the time range (unixtime in millis)
  9. without endtime means from starttime to forever
  10. endtime end of the time range. Ignored if no starttime specified.
  11. versions number of cell versions to copy
  12. new.name new table's name
  13. peer.adr Address of the peer cluster given in the format
  14. hbase.zookeeer.quorum:hbase.zookeeper.client.port:zookeeper.znode.parent
  15. families comma-separated list of families to copy
  16. To copy from cf1 to cf2, give sourceCfName:destCfName.
  17. To keep the same name, just give "cfName"
  18. all.cells also copy delete markers and deleted cells
  19. Args:
  20. tablename Name of the table to copy
  21. Examples:
  22. To copy 'TestTable' to a cluster that uses replication for a 1 hour window:
  23. $ bin/hbase org.apache.hadoop.hbase.mapreduce.CopyTable --starttime=1265875194289 --endtime=1265878794289 --peer.adr=server1,server2,server3:2181:/hbase --families=myOldCf:myNewCf,cf2,cf3 TestTable
  24. For performance consider the following general options:
  25. -Dhbase.client.scanner.caching=100
  26. -Dmapred.map.tasks.speculative.execution=false

方式1

  1. create 'table_test',{NAME=>"i"} #目的集群上先创建一个与原表结构相同的表
  2. hbase
  3. org.apache.hadoop.hbase.mapreduce.CopyTable
  4. --peer.adr=zk-addr1,zk-addr2,zk-addr3:2181:/hbase
  5. table_test
  6. 例如:
  7. hbase org.apache.hadoop.hbase.mapreduce.CopyTable --peer.adr=192.168.1.253:2181:/hbase test1
  8. (--peer.adr后面跟目标的zookeeper服务)

方式2:支持时间区间、row区间,改变表名称,改变列簇名称,指定是否copy删除数据等功能,例如:

  1. hbase org.apache.hadoop.hbase.mapreduce.CopyTable
  2. --starttime=1265875194289 // 起始时间
  3. --endtime=1265878794289 // 结束时间
  4. --peer.adr= dstClusterZK:2181:/hbase // zookeeper
  5. --families=myOldCf:myNewCf,cf2,cf3 // 列族
  6. TestTable // 目标表
  7. 增加性能可以添加一下选项:
  8. // 设置scanner的缓存大小,如果设置更大的缓存值,需要更大的内存空间
  9. -Dhbase.client.scanner.caching=100
  10. // 为了预防数据写入两次,将该选项设置false
  11. -Dmapreduce.map.speculative=false

通用的例子

  1. $ bin/hbase org.apache.hadoop.hbase.mapreduce.CopyTable
  2. --starttime=1265875194289
  3. --endtime=1265878794289
  4. --peer.adr=server1,server2,server3:2181:/hbase
  5. --families=myOldCf:myNewCf,cf2,cf3
  6. TestTable

将hbase上某个数据表导出到本地

  1. hbase org.apache.hadoop.hbase.mapreduce.Export emp file:///Users/a6/Applications/experiment_data/hbase_data/bak

性能优化方向

  1. 按照时间范围,进行数据拷贝

总结

  1. DistCp: 文件层的数据同步,也是我们常用的
  2. CopyTable: 这个涉及对原表数据Scan,然后直接Put到目标表,效率较低
  3. Export/Import: 类似CopyTable, Scan出数据放到文件,再把文件传输到目标集群作Import
  4. Snapshot: 比较常用 应用灵活,采用快照技术,效率比较高
  5. 具体应用时,要结合自身表的特性,考虑数据规模、数据读写方式、实时数据&离线数据等方面,再选择使用哪种。