1. HBase Replication简介:
HBase Replication 主要是将一个HBase集群中的数据复制到目标HBase集群。在HBase中,集群复制是指使用源集群的write-ahead log (WAL)传播更改,使一个集群状态与另一个集群状态保持同步。HBase Replication可以作用在column family级别。
在启用HBase repilcation 前,需要在目标集群上创建需要同步的table及column family. HBase repilcation可以跨cdh5和cdh6版本运行!
2. HBase Replication 说明:
21. 复制的HLog条目的时间戳保持不变。如果发生冲突(两个条目与行键、列族、列限定符和时间戳相同),则只读取稍后到达的条目write。
2.2. 增量列值(ICVs)在复制时被视为简单的put。如果复制的每一端都是活动的(新数据来自两个源,然后它们彼此复制),这可能是不可取的,因为创建了覆盖彼此的相同计数器。(See https://issues.apache.org/jira/browse/HBase-2804.)
2.3 确保源集群和目标集群是时间同步的。
2.4. 有些更改不能复制,必须通过其他方法传播,比如快照或CopyTable。
启用复制之前存在于活动集群中的数据。
绕过WAL的操作,例如在使用BulkLoad或writeToWal(false)等API调用时。
表模式修改。
3. Hbase replication 需求:
3.1 你必须自己管理zookeeper,并且必须在整个部署过程中可用。
3.2 两个集群中的每个主机必须能够到达其他主机,包括ZooKeeper集群中的主机
3.3 包含用于复制的范围的家族的每个表必须存在于每个集群上,并且具有完全相同的名称. see Creating the Empty Table On the Destination Cluster
3.4 对于复杂的复制拓扑(如active-active),需要HBase 0.92或更高版本
4. HBase Replication 部署
4.1 配置并启动源hbase集群和目标hbase集群
4.2 在源集群和目标集群上创建具有相同名称和列族的表
4.3 在源集群上,启用Cloudera管理器中的replication,或者设置hbase:在hbase-site.xml中hbase.replication为true。
4.4 Obtain Kerberos credentials as the HBase principal. Substitute your fully.qualified.domain.name and realm in the following command:
$ kinit -k -t /etc/hbase/conf/hbase.keytab hbase/fully.qualified.domain.name@YOUR-REALM.COM
4.5 在源集群上,在HBase Shell中,使用add_peer命令将目标集群作为对等节点添加。语法如下:
add_peer 'ID', 'CLUSTER_KEY'
ID必须是一个短整数。要组合CLUSTER_KEY,请使用以下模板:
hbase.zookeeper.quorum:hbase.zookeeper.property.clientPort:zookeeper.znode.parent
如果两个集群使用相同的ZooKeeper集群,则必须使用不同的zookeep .znode。父目录,因为它们不能在同一个文件夹中写入。
4.6 在源集群上,使用HBase Shell中的以下命令将每个列族的REPLICATION_SCOPE设置为1,从而配置要复制的每个列族。
hbase> disable 'example_table'
hbase> alter 'example_table', {NAME => 'example_family', REPLICATION_SCOPE => '1'}
hbase> enable 'example_table'
4.7 通过检查源集群上的日志,查看以下消息,验证复制是否正在发生。
Considering 1 rs, with ratio 0.1
Getting 1 rs from peer cluster # 0
Choosing peer 192.0.2.49:62020
4.8 要验证复制数据的有效性,请使用源集群上包含的VerifyReplication MapReduce作业,为其提供复制对等点的ID和要验证的表名。其他选项也可用,比如要验证的时间范围或特定的家庭。
该命令的形式如下:
hbase org.apache.hadoop.hbase.mapreduce.replication.VerifyReplication [--starttime=timestamp1] [--stoptime=timestamp] [--families=comma separated list of families] <peerId> <tablename>
VerifyReplication命令打印GOODROWS和BADROWS计数器,以指示正确复制和错误复制的行
4.9 紧急情况下停止replication:
If replication is causing serious problems, you can stop it while the clusters are running.
Open the shell on the source cluster and use the disable_peer command for each peer, then the disable_table_replication command. For example:
hbase> disable_peer("1")
hbase> disable_table_replication
Already queued edits will be replicated after you use the disable_table_replication command, but new entries will not. See Understanding How WAL Rolling Affects Replication.
To start replication again, use the enable_peer command.
5. WAL滚动如何影响复制
6. 恢复HBase数据
按照以下指示从灾难恢复场景中的复制集群中恢复HBase数据
6.1 对于要还原的每个列,将sink上的列族属性REPLICATION_SCOPE的值更改为0,以便在还原操作期间不会复制它的数据
6.2 对于要还原的每个列,将源上的列族属性REPLICATION_SCOPE的值更改为1,以便复制它的数据
6.3 使用CopyTable或distcp命令将数据从备份导入到接收器集群, Initiating Replication When Data Already Exists.
6.4 使用部署HBase复制时讨论的add_peer命令,将接收器作为复制对等点添加到源。如果在前面的步骤中使用了distcp,那么重启或滚动重启这两个集群,这样,regionserver将获取新的文件。如果使用CopyTable,则不需要重新启动集群。新数据将在写入时复制。
6.5 当恢复完成时,在启动恢复之前将REPLICATION_SCOPE值更改为它们的值。
7. 验证replication工作
要验证HBase replication是否工作,请按照以下步骤确认数据已从源集群复制到远程目标集群:
1.在源集群或者目标集群上安装和配置纱线。
2.确保您拥有所需的权限:
3.运行VerifyReplication命令:
src-node$ sudo -u hbase hbase org.apache.hadoop.hbase.mapreduce.replication.VerifyReplication peer1 table1 ... org.apache.hadoop.hbase.mapreduce.replication.VerifyReplication$Verifier$Counters BADROWS=2 CONTENT_DIFFERENT_ROWS=1 GOODROWS=1 ONLY_IN_PEER_TABLE_ROWS=1 File Input Format Counters Bytes Read=0 File Output Format Counters Bytes Written=0
8. 复制警告:
在长时间运行、写密集型工作负载的情况下,如果在执行复制时阻塞了目标集群的元处理程序,则目标集群可能会失去响应。CDH有三个特性来处理这个问题:
1. hbase.regionserver.replication.handler。count—目标集群中复制处理程序的数量(缺省值为3)。复制现在由目标集群中的独立处理程序处理,以避免上述延迟。如果主动式和被动式区域服务器的比率很高,则将其增加到一个高值。
2. replication.sink.client.retries。number—sink集群上的HBase复制客户机应该重试编写WAL条目的次数(默认值为1)。
3. replication.sink.client.ops。timeout——sink集群上HBase复制客户机的超时(默认为20秒)。