Hbase复制(Replication )

Hbase复制使用手册

1 Hbase复制简介

通过hbase的replication功能实现集群间的相互复制.

2 环境

这里hbase版本为hbase-0.98.6-cdh5.3.3

3 配置

各个集群里配置hbase-site.xml里的复制功能:

<property>

<name>hbase.replication</name>

<value>true</value>

</property>

完整配置文件附录:

<configuration>

<property>

    <name>hbase.master</name>

    <value>shenl:6000</value>

</property>

<property>

    <name>hbase.master.maxclockskew</name>

    <value>180000</value>

</property>

<property>

    <name>hbase.rootdir</name>

    <value>hdfs://shenl:8020/hbase</value>

</property>

<property>

    <name>hbase.cluster.distributed</name>

    <value>true</value>

</property>

<property>

    <name>hbase.zookeeper.quorum</name>

    <value>shenl</value>

</property>

<property>

    <name>hbase.zookeeper.property.dataDir</name>

    <value>/root/zookeeper/data</value>

</property>

<property>

    <name>dfs.replication</name>

    <value>1</value>

</property>

<property>

<name>hbase.replication</name>

<value>true</value>

</property>

</configuration>


 

4 使用

3.1 场景1:主节点同名表同步到各从节点

1 主节点里创建student表,指定有score和course两个列族

create 'student', 'score', 'course'

put 'student', 'xiapi001','score:english', '10'

put 'student', 'xiapi002','score:chinese', '20'

put 'student','xiapi002','course:chinese', '001'

scan 'scores'

2打开主节点里表student的复制特性

disable 'student'

alter 'student', {NAME => 'score',REPLICATION_SCOPE => '1'},{NAME => 'course', REPLICATION_SCOPE => '1'}

enable 'student'

3主节点里添加要复制的从节点的peer

add_peer '10','192.168.56.103:2181:/hbase'

set_peer_tableCFs '10','student'

 

4从节点里新增跟主节点一样的表

create 'student', 'score', 'course'

5主节点里新增数据到从节点里观察数据是否同步

1)  主节点里新增数据

 

2)  从节点里查看数据

 

:1 这里数据同步是从replication功能打开之后,之前的数据需要手工同步.

2同步时可以指定列族,如仅同步student的score列族:

从节点里:

 

6同理添加peer,重复动作 34 5,即可实现场景1.

add_peer '11','192.168.56.104:2181:/hbase'

set_peer_tableCFs '10','student'

3.2场景2:主节点不同表同步到不同集群相应表

实现方式类似3.1,通过set_peer_tableCFs设置

set_peer_tableCFs '4', "slave1:grade; scores:grade"

set_peer_tableCFs '5', "slave2:grade; scores:grade"

list_peers

3.3场景3:各主节点表同步到同从集群相应表

实现方式:

主集群1里增加peer,主集群2里增加peer,同时通过set_peer_tableCFs设置需要同步的表即可.

#主hbase1 peers:

 

#主hbase2 peers :

add_peer '6','192.168.56.103:2181:/hbase'

set_peer_tableCFs '5', " master2:grade"

 

3.4复制命令详解

Group name: replication

命令

官网解释

中文意思

add_peer

adds a replication relationship between two clusters

为两个集群添加复制管理

disable_peer

Disable a replication relationship

禁用复制关系

enable_peer

Enable a previously-disabled replication relationship

启用复制关系

list_peers

list all replication relationships known by this cluster

显示当前集群的复制关系

remove_peer

Disable and remove a replication relationship

禁用并删除复制关系

list_replicated_tables

List all the tables and column families replicated from this cluster

显示一个hbase集群下处于复制状态的表

set_peer_tableCFs

Set the replicable table-cf config for the specified peer

设置peer下的表、列族复制关系

show_peer_tableCFs

Show replicable table-cf config for the specified peer.

显示peer下表、列族复制关系

5 问题总结

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

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

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ShenLiang2025

您的鼓励是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值