As a key feature to ensure high availability of the HBase cluster system, HBase cluster replication provides HBase with remote data replication in real time. It provides basic O&M tools, including tools for maintaining and re-establishing active/standby relationships, verifying data, and querying data synchronization progress. To achieve real-time data replication, you can replicate data from the HBase cluster to another one.
Enable the replication function for the active cluster to synchronize data written by Put.
For versions earlier than MRS 1.9.2: Log in to MRS Manager, and choose Services.
For MRS 1.9.2 or later: Click the cluster name on the MRS console and choose Components.
For clusters of MRS 1.9.2 or later:
If the Components tab is unavailable, complete IAM user synchronization first. (On the Dashboard page, click Synchronize on the right side of IAM User Sync to synchronize IAM users.)
In MRS 2.x, this configuration has been removed. Skip this step.
Navigation Path |
Parameter |
Default Value |
Description |
---|---|---|---|
HMaster > Performance |
hbase.master.logcleaner.ttl |
600000 |
Time to live (TTL) of HLog files. If the value is set to 604800000 (unit: millisecond), the retention period of HLog is 7 days. |
hbase.master.cleaner.interval |
60000 |
Interval for the HMaster to delete historical HLog files. The HLog that exceeds the configured period will be automatically deleted. You are advised to set it to the maximum value to save more HLogs. |
|
RegionServer > Replication |
replication.source.size.capacity |
16777216 |
Maximum size of edits, in bytes. If the edit size exceeds the value, HLog edits will be sent to the standby cluster. |
replication.source.nb.capacity |
25000 |
Maximum number of edits, which is another condition for triggering HLog edits to be sent to the standby cluster. After data in the active cluster is synchronized to the standby cluster, the active cluster reads and sends data in HLog according to this parameter value. This parameter is used together with replication.source.size.capacity. |
|
replication.source.maxretriesmultiplier |
10 |
Maximum number of retries when an exception occurs during replication. |
|
replication.source.sleepforretries |
1000 |
Retry interval (unit: ms) |
|
hbase.regionserver.replication.handler.count |
6 |
Number of replication RPC server instances on RegionServer |
Enable the replication function for the active cluster to synchronize data written by bulkload.
If bulkload import is used and data needs to be synchronized, you need to enable Bulkload replication.
If yes, go to 6.
If no, go to 10.
Restarting the HBase service and install the client
Synchronize table data of the active cluster. (Skip this step if the active cluster has no data.)
The system prompts you to enter the password after you run kinit hbase. The default password of user hbase is Hbase@123.
Run the list command to check the existing tables in the active cluster and run the scan 'tableName' command to check whether the tables contain historical data.
Manual synchronization refers to the synchronization of a single table that is implemented by Export, distcp, and Import.
The process for manually synchronizing data of a single table is as follows:
hbase org.apache.hadoop.hbase.mapreduce.Export -Dhbase.mapreduce.include.deleted.rows=true Table name Directory where the source data is stored
Example: hbase org.apache.hadoop.hbase.mapreduce.Export -Dhbase.mapreduce.include.deleted.rows=true t1 /user/hbase/t1
hadoop distcp Directory for storing source data in the active cluster hdfs://ActiveNameNodeIP:9820/ Directory for storing source data in the standby cluster
ActiveNameNodeIP indicates the IP address of the active NameNode in the standby cluster.
Example: hadoop distcp /user/hbase/t1 hdfs://192.168.40.2:9820/user/hbase/t1
In MRS 1.6.2 and earlier versions, the default port number is 25000. For details, see List of Open Source Component Ports.
hbase org.apache.hadoop.hbase.mapreduce.Import -Dimport.bulk.output=Directory where the output data is stored in the standby cluster Table name Directory where the source data is stored in the standby cluster
hbase org.apache.hadoop.hbase.mapreduce.LoadIncrementalHFiles Directory where the output data is stored in the standby cluster Table name
For example, hbase org.apache.hadoop.hbase.mapreduce.Import -Dimport.bulk.output=/user/hbase/output_t1 t1 /user/hbase/t1 and
hbase org.apache.hadoop.hbase.mapreduce.LoadIncrementalHFiles /user/hbase/output_t1 t1
Add the replication relationship between the active and standby clusters.
add_peer 'Standby cluster ID', CLUSTER_KEY => 'ZooKeeper address of the standby cluster',{HDFS_CONFS => true}
Suppose the standby cluster ID is replication2 and the ZooKeeper address of the standby cluster is 192.168.40.2,192.168.40.3,192.168.40.4:2181:/hbase.
For versions earlier than MRS 1.9.2: Choose Services > ZooKeeper > Instance to obtain the service IP address of ZooKeeper.
For MRS 1.9.2 or later: Log in to the MRS console, click the cluster name, and choose Components > ZooKeeper > Instances to obtain the ZooKeeper service IP address.
hbase(main):003:0> list_peers PEER_ID CLUSTER_KEY ENDPOINT_CLASSNAME STATE REPLICATE_ALL NAMESPACES TABLE_CFS BANDWIDTH SERIAL replication2 192.168.0.13,192.168.0.177,192.168.0.25:2181:/hbase ENABLED true 0 false
hbase(main):003:0> list_peers PEER_ID CLUSTER_KEY STATE TABLE_CFS replication2 192.168.0.13,192.168.0.177,192.168.0.25:2181:/hbase ENABLED
Specify the data writing status for the active and standby clusters.
set_clusterState_active
The command is run successfully if the following information is displayed:
hbase(main):001:0> set_clusterState_active => true
set_clusterState_standby
The command is run successfully if the following information is displayed:
hbase(main):001:0> set_clusterState_standby => true
Enable the HBase replication function to synchronize data.
You can only synchronize data of one HTable at one time.
enable_table_replication 'Table name'
If the standby cluster is offline, start it.
If the standby cluster has a table with the same name but different structure, modify the table structure to make it as the same as the table structure of the active cluster. On the HBase shell of the standby cluster, run the alter command to change the password by referring to the example.
After the permission of the active HBase source data table is modified, to ensure that the standby cluster can properly read data, modify the role permission for the standby cluster.
Check the data synchronization status for the active and standby clusters.
hbase org.apache.hadoop.hbase.mapreduce.replication.VerifyReplication --starttime=Start time --endtime=End time Column family name ID of the standby cluster Table name
Switch over active and standby clusters.
Operation |
Command |
Description |
---|---|---|
Set up the active/standby relationship. |
add_peer 'Standby cluster ID', 'Standby cluster address' Examples: add_peer '1', 'zk1,zk2,zk3:2181:/hbase' add_peer '1', 'zk1,zk2,zk3:2181:/hbase1' |
Set up the relationship between the active cluster and the standby cluster. To enable bulkload replication, run the add_peer 'Standby cluster ID',CLUSTER_KEY => 'Standby cluster address' command, configure hbase.replication.conf.dir, and manually copy the HBase client configuration file in the active cluster to all RegionServer nodes in the standby cluster. For details, see 5 to 11. For MRS 1.9.2 or earlier, to enable bulkload replication, run the following command: add_peer 'Standby cluster ID','Standby cluster address',{HDFS_CONF => true}. |
Remove the active/standby relationship. |
remove_peer 'Standby cluster ID' Example: remove_peer '1' |
Remove standby cluster information from the active cluster. |
Query the active/standby relationship. |
list_peers |
Query standby cluster information (mainly Zookeeper information) in the active cluster. |
Enable the real-time user table synchronization function. |
enable_table_replication 'Table name' Example: enable_table_replication 't1' |
Synchronize user tables from the active cluster to the standby cluster. |
Disable the real-time user table synchronization function. |
disable_table_replication 'Table name' Example: disable_table_replication 't1' |
Do not synchronize user tables from the active cluster to the standby cluster. |
Verify data of the active and standby clusters. |
bin/hbase org.apache.hadoop.hbase.mapreduce.replication.VerifyReplication --starttime --endtime Column family name Standby cluster ID Table name |
Verify whether data of the specified table is the same between the active cluster and the standby cluster. The description of the parameters in this command is as follows:
|
Switch the data writing status. |
set_clusterState_active set_clusterState_standby |
Specifies whether data can be written to the cluster HBase tables. |
Add or update the active cluster HDFS configurations saved in the peer cluster. |
set_replication_hdfs_confs 'PeerId', {'key1' => 'value1', 'key2' => 'value2'} |
Enable replication for data including bulkload data. When HDFS parameters are modified in the active cluster, the modification cannot be automatically synchronized to the standby cluster. You need to manually run the command to synchronize the changes. The affected parameters are as follows:
For example, if the value of fs.defaultFS is changed to hdfs://hacluster_sale, run the set_replication_hdfs_confs '1', {'fs.defaultFS' => 'hdfs://hacluster_sale'} command to synchronization the HDFS configuration to the standby cluster whose ID is 1. In versions later than MRS 1.9.2, this command has been removed. If synchronization is required, manually copy the changed client configurations in the active cluster to the standby cluster. For details, see 8. |