一.前提主从集群之间能互相通讯;

5.hbase表新增数据同步之add_peer-LMLPHP

二.在cluster1上(源集群): 

1.查看集群已开启的peers

hbase(main):011:0> list_peers

PEER_ID CLUSTER_KEY STATE TABLE_CFS
10 slave.01.bigdata.prod.wgq,slave.02.bigdata.prod.wgq,slave.03.bigdata.prod.wgq:2181:/hbase ENABLED USER_INFO:ncallrecords
1 row(s) in 0.0100 seconds

2.使用新建表test做测试,建表,然后在从集群也建立一张一样的test表:

hbase(main):015:0> create "test","A"
0 row(s) in 2.2720 seconds

3.disable该表:

hbase(main):022:0> disable 'test'
0 row(s) in 2.2550 seconds

4.开启复制功能,默认为不开启:

hbase(main):023:0> alter 'test',{NAME=>'A',REPLICATION_SCOPE => '1'}

5.开启该表:

hbase(main):026:0> enable 'test'
0 row(s) in 1.2630 seconds

6.针对该表建立add_peer功能:

hbase(main):028:0> add_peer '11','slave.01.bigdata.prod.wgq,slave.02.bigdata.prod.wgq,slave.03.bigdata.prod.wgq:2181:/hbase'
0 row(s) in 0.0180 seconds

7.再看查看已开启的peers,可以看到新加的:

hbase(main):029:0> list_peers
PEER_ID CLUSTER_KEY STATE TABLE_CFS
11 slave.01.bigdata.prod.wgq,slave.02.bigdata.prod.wgq,slave.03.bigdata.prod.wgq:2181:/hbase ENABLED
10 slave.01.bigdata.prod.wgq,slave.02.bigdata.prod.wgq,slave.03.bigdata.prod.wgq:2181:/hbase ENABLED USER_INFO:ncallrecords
2 row(s) in 0.0120 seconds

8.开启针对test表同步复制:

hbase(main):030:0> set_peer_tableCFs '11','test'
0 row(s) in 0.0040 seconds

9.再list_peers:

hbase(main):031:0> list_peers
PEER_ID CLUSTER_KEY STATE TABLE_CFS
11 slave.01.bigdata.prod.wgq,slave.02.bigdata.prod.wgq,slave.03.bigdata.prod.wgq:2181:/hbase ENABLED test
10 slave.01.bigdata.prod.wgq,slave.02.bigdata.prod.wgq,slave.03.bigdata.prod.wgq:2181:/hbase ENABLED USER_INFO:ncallrecords
2 row(s) in 0.0050 seconds

10.往主集群hbase数据库test表中put新数据,验证从集群是否有新数据:

hbase(main):034:0> put "test","2222222","A:name","chenliangliang"
0 row(s) in 0.0720 seconds

hbase(main):035:0> put "test","2222222","A:age","30"
0 row(s) in 0.0060 seconds

----------------------------------------------------------------------------------------------------

hbase(main):036:0> scan "test"
ROW COLUMN+CELL
1111111 column=A:age, timestamp=1524021317653, value=30
1111111 column=A:name, timestamp=1524021305313, value=gongxiucheng
2222222 column=A:age, timestamp=1524021628181, value=30
2222222 column=A:name, timestamp=1524021616864, value=chenliangliang
2 row(s) in 0.0070 seconds

-------------------------------------------------------------------------------------------------------

其中rowKey为1111111的这条是开启数据同步之前put的;

-------------------------------------------------------------------------------------------------------

然后到从集群scan  test表,假如有rowKey为2222222的这条数据,则同步成功:

---------------------------------------------------------------------------------------------------------

hbase(main):010:0> scan "test"
ROW COLUMN+CELL
2222222 column=A:age, timestamp=1524021628181, value=30
2222222 column=A:name, timestamp=1524021616864, value=chenliangliang
1 row(s) in 0.0350 seconds

三.总结:

1 验证是需要先核对下hbase的版本,不同版本的复制命令不同;

2 同步是针对配置后复制的新数据,旧数据需要手动迁移;

  

05-26 02:28