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 同步是針對配置后復制的新數據,舊數據需要手動遷移
總結
以上是生活随笔為你收集整理的Hbase复制(Replication )的全部內容,希望文章能夠幫你解決所遇到的問題。