HBase 提供了一种群集复制机制,允许使用源群集的预写日志(WAL)来传播更改,从而使一个群集的状态与另一个群集的状态保持同步。集群复制的一些用例包括:
HBase中的Replication是基于WAL的,其在主集群的每一个RegionServer进程内部起了一个叫作ReplicationSource的线程来负责Replication,同时在备集群的每一个RegionServer内部起了一个ReplicationSink的线程来负责接收Replication数据。ReplicationSource记录须要同步的WAL队列,而后不断读取WAL中的内容,同时能够根据Replication的配置作一些过滤,好比是否要复制这个表的数据等,而后经过replicateWALEntry这个Rpc调用来发送给备集群的RegionServer,备集群的ReplicationSink线程则负责将收到的数据转换为put/delete操做,以batch的形式写入到备集群中。
由于是后台线程异步的读取WAL并复制到备集群,因此这种Replication方式叫作异步Replication,正常状况下备集群收到最新写入数据的延迟在秒级别。
单个 WAL 编辑将经历几个步骤,以便复制到从属群集。
以下步骤具体描述如何配置两个集群之间的Binlog复制功能。
HBase默认此特性是关闭的,需要在源集群上进行设定并重启集群,将hbase.replication参数设定为true
在源集群修改replication.sleep.before.failover配置设置为1,此配置需配置在hbase-site.xml 的 HBase 服务高级配置代码段(安全阀)中添加
在源集群上添加两个集群的复制关系,在hbase shell中执行命令。下面的命令指明了目标集群的Zookeeper地址,以及它在这个Zookeeper上路径
hbase shell > add_peer '1',"zknode1,zknode2,zknode3:2181:/hbase"
有关add_peer的详细用法,请参考HBase官方文档说明https://hbase.apache.org/book.html#_cluster_replication
hbase shell > enable_table_replication 'TABL'
注:如果不想再对表进行复制,可以使用以下命令来禁用表的复制
hbase shell >
disable_table_replication 'TABL'
VerifyReplication MapReduce 作业(包含在 HBase 中)对两个不同集群之间的复制数据进行系统比较。在主群集上运行 VerifyReplication 作业,为其提供用于验证的对等 ID 和表名。您可以通过指定时间范围或特定系列来进一步限制验证。这份工作的简称是verifyrep。要运行作业,请使用如下命令:
hbase org.apache.hadoop.hbase.mapreduce.replication.VerifyReplication -mappers 10 -bandwidth 1024 1 'TRAF_RSRVD_5:TRAFODION._DTM_.TRAFODION_BINLOG'
您可以使用 HBase Shell 命令status 'replication’来监视群集上的复制状态。该命令有三个变体:
示例输出:
hbase(main):009:0> status 'replication'
version 1.2.0-cdh5.16.2
4 live servers
gyw29.esgyn.cn:
SOURCE: PeerID=1, AgeOfLastShippedOp=3973899, SizeOfLogQueue=48, TimeStampsOfLastShippedOp=Mon Jun 27 09:28:46 CST 2022, Replication Lag=3977761
SINK : AgeOfLastAppliedOp=0, TimeStampsOfLastAppliedOp=Mon Jun 27 09:16:59 CST 2022
gyw32.esgyn.cn:
SOURCE: PeerID=1, AgeOfLastShippedOp=3909927, SizeOfLogQueue=55, TimeStampsOfLastShippedOp=Mon Jun 27 09:28:46 CST 2022, Replication Lag=3979522
SINK : AgeOfLastAppliedOp=0, TimeStampsOfLastAppliedOp=Mon Jun 27 09:16:59 CST 2022
gyw30.esgyn.cn:
SOURCE: PeerID=1, AgeOfLastShippedOp=3922388, SizeOfLogQueue=50, TimeStampsOfLastShippedOp=Mon Jun 27 09:28:46 CST 2022, Replication Lag=3979922
SINK : AgeOfLastAppliedOp=0, TimeStampsOfLastAppliedOp=Mon Jun 27 09:16:59 CST 2022
gyw31.esgyn.cn:
SOURCE: PeerID=1, AgeOfLastShippedOp=3954983, SizeOfLogQueue=59, TimeStampsOfLastShippedOp=Mon Jun 27 09:28:47 CST 2022, Replication Lag=3976921
SINK : AgeOfLastAppliedOp=0, TimeStampsOfLastAppliedOp=Mon Jun 27 09:16:59 CST 2022
以使用HBase API来获取更详细的Replication相关的数据,命令如下
curl http://<RegionServer_IP>:60030/jmx?qry=Hadoop:service=HBase,name=RegionServer,sub=Replication
以上命令显示某个指定的RegionServer的Replication信息。
样例输出:
{
"beans" : [ {
"name" : "Hadoop:service=HBase,name=RegionServer,sub=Replication",
"modelerType" : "RegionServer,sub=Replication",
"tag.Context" : "regionserver",
"tag.Hostname" : "gyw29.esgyn.cn",
"source.1.logEditsRead" : 941,
"source.1.logReadInBytes" : 422045,
"source.ageOfLastShippedOp" : 3355072,
"source.1.shippedKBs" : 0,
"source.1.ignoredUncleanlyClosedLogContentsInBytes" : 0,
"source.logReadInBytes" : 1045079,
"source.1.sizeOfLogQueue" : 43,
"source.1-gyw30.esgyn.cn,60020,1656292333740.completedLogs" : 0,
"source.sizeOfLogQueue" : 43,
"sink.ageOfLastAppliedOp" : 0,
"source.1.ageOfLastShippedOp" : 3355072,
"source.1-gyw30.esgyn.cn,60020,1656292333740.logEditsFiltered" : 891,
"source.shippedOps" : 0,
"source.1-gyw30.esgyn.cn,60020,1656292333740.logEditsRead" : 891,
"source.1-gyw30.esgyn.cn,60020,1656292333740.completedRecoverQueues" : 1,
"source.1.closedLogsWithUnknownFileLength" : 0,
"source.1.repeatedLogFileBytes" : 0,
"source.1-gyw30.esgyn.cn,60020,1656292333740.sizeOfLogQueue" : 0,
"source.1-gyw31.esgyn.cn,60020,1656292333815.shippedBatches" : 0,
"source.1-gyw31.esgyn.cn,60020,1656292333815.shippedOps" : 0,
"source.1-gyw31.esgyn.cn,60020,1656292333815.restartedLogReading" : 0,
"source.1-gyw31.esgyn.cn,60020,1656292333815.sizeOfLogQueue" : 0,
"sink.appliedOps" : 0,
"source.1.shippedOps" : 0,
"source.1-gyw30.esgyn.cn,60020,1656292333740.shippedBatches" : 0,
"source.1-gyw31.esgyn.cn,60020,1656292333815.ageOfLastShippedOp" : 0,
"source.1-gyw31.esgyn.cn,60020,1656292333815.shippedKBs" : 0,
"source.1-gyw31.esgyn.cn,60020,1656292333815.uncleanlyClosedLogs" : 0,
"source.1-gyw30.esgyn.cn,60020,1656292333740.ignoredUncleanlyClosedLogContentsInBytes" : 0,
"source.1.logEditsFiltered" : 940,
"source.1-gyw30.esgyn.cn,60020,1656292333740.repeatedLogFileBytes" : 0,
"source.1.shippedBatches" : 0,
"source.1.completedRecoverQueues" : 0,
"source.1.completedLogs" : 0,
"sink.appliedBatches" : 0,
"source.uncleanlyClosedLogs" : 0,
"source.1-gyw30.esgyn.cn,60020,1656292333740.uncleanlyClosedLogs" : 0,
"source.closedLogsWithUnknownFileLength" : 0,
"source.repeatedLogFileBytes" : 0,
"source.shippedKBs" : 0,
"source.1-gyw31.esgyn.cn,60020,1656292333815.logEditsRead" : 890,
"source.1.restartedLogReading" : 0,
"source.1-gyw31.esgyn.cn,60020,1656292333815.repeatedLogFileBytes" : 0,
"source.completedRecoverQueues" : 2,
"source.1-gyw30.esgyn.cn,60020,1656292333740.shippedKBs" : 0,
"source.1-gyw30.esgyn.cn,60020,1656292333740.closedLogsWithUnknownFileLength" : 0,
"source.1-gyw31.esgyn.cn,60020,1656292333815.completedRecoverQueues" : 1,
"source.restartedLogReading" : 0,
"source.ignoredUncleanlyClosedLogContentsInBytes" : 0,
"source.logEditsRead" : 2722,
"source.1-gyw30.esgyn.cn,60020,1656292333740.ageOfLastShippedOp" : 0,
"source.1-gyw31.esgyn.cn,60020,1656292333815.logEditsFiltered" : 890,
"source.1-gyw30.esgyn.cn,60020,1656292333740.shippedOps" : 0,
"source.1.uncleanlyClosedLogs" : 0,
"source.logEditsFiltered" : 2721,
"source.1-gyw31.esgyn.cn,60020,1656292333815.completedLogs" : 0,
"source.1-gyw31.esgyn.cn,60020,1656292333815.logReadInBytes" : 311523,
"source.1-gyw31.esgyn.cn,60020,1656292333815.closedLogsWithUnknownFileLength" : 0,
"source.1-gyw31.esgyn.cn,60020,1656292333815.ignoredUncleanlyClosedLogContentsInBytes" : 0,
"source.completedLogs" : 0,
"source.shippedBatches" : 0,
"source.1-gyw30.esgyn.cn,60020,1656292333740.logReadInBytes" : 311511,
"source.1-gyw30.esgyn.cn,60020,1656292333740.restartedLogReading" : 0
} ]
}