我們都知道hbase 叢集中通常有一個master 節點,多個region server節點,為了防止HBase 叢集中master的單點故障,可以向叢集中添加一個slave master,這些新添加的master 會分布在不同的實體機器上,是以以最壞的情形來看,目前運作master的那台實體機down了,整個系統可以由backup的 master 來接管!
在介紹如何添加master 節點之前,我們先了解一下在hbase叢集中master是如何産生的.master 程序使用Zookeeper 來判斷哪一個是目前活動的master:所有的master 競争建立Zookeeper 中有一個專用的znode,第一個成功建立znode的成為叢集中的目前活動的master !
以上場景會發生在整個叢集啟動時,如果存在多個master 程序同時啟動,則成功建立znode的成為叢集中的master。所有其他未成功的節點則<b>simply loop around the znode</b>并且等待master建立的znode消失,并觸發重新競争。下面的是來自《HBase: The Definitive Guide》的文章(有些疑問)
“ The /hbase/master znode is ephemeral, (短暫 的?zookeeper 機制)and is the same kind the region servers use to
report their presence. <b>When the master process that created the znode fails, ZooKeeper will notice the end of the session with that server and remove the znode accordingly, triggering the election process. (既然建立失敗,又怎麼删除?)</b>”
在完全分布式hbase叢集上啟動master 需要滿足它的配置要和叢集中其他節點的配置一樣。叢集中的master節點通常和叢集中的其他節點都共用一套配置資訊。一旦你确定系統的配置資訊已經配置正确,就可以執行如下語句:
$ <b>./bin/hbase-daemon.sh start master</b>
日志如下:
2012-02-01 15:39:42,552 INFO org.apache.hadoop.hbase.metrics: new MBeanInfo
2012-02-01 15:39:42,553 INFO org.apache.hadoop.hbase.metrics: new MBeanInfo
2012-02-01 15:39:42,553 INFO org.apache.hadoop.hbase.master.metrics.MasterMetrics: Initialized
2012-02-01 15:39:42,575 INFO org.apache.hadoop.hbase.master.ActiveMasterManager:<b> Another master is the active master, rac3:60000; waiting to become the next active master</b>
假設叢集中已經有了一個master正在運作,執行上述指令将會帶來如下情況:新起來的master會等待目前的znode被删除。如果你想要在一個 以自動運作的方式<b>(in an automated fashion )</b>啟動多個master并且指定一個特定的機器作為目前master的主控端。可以使用如下指令:
$ <b>./bin/hbase-daemon.sh start master --backup</b>
使用 --backup 參數的啟動方式,日志資訊裡多了紅色部分:
2012-02-01 15:57:05,413 INFO org.apache.hadoop.hbase.metrics: new MBeanInfo
2012-02-01 15:57:05,413 INFO org.apache.hadoop.hbase.master.metrics.MasterMetrics: Initialized
<b>2012-02-01 15:57:05,414 DEBUG org.apache.hadoop.hbase.master.HMaster: HMaster started in backup mode.Stalling(停轉)until master znode is written.##可能意思翻譯不準,就是以空閑模式等待目前的master down 機!</b>
2012-02-01 15:57:05,425 INFO org.apache.hadoop.hbase.master.ActiveMasterManager: Another master is the active master, rac1:60000; <b>waiting to become the next active master</b>
使用帶--backup 參數啟動的master 将會等待特定的master 程序比如: 使用start-hbase.sh 腳本啟動的或者不帶--backup參數的<b>hbase-daemon.sh start master 指令啟動的master 在Zookeeper中建立</b> /hbase/master znode。一旦特定的master 程序建立znode成功,由于現在叢集中已經有了master了,是以那些以--backkup 模式啟動的master則會進入一個空閑模式!
總結:
其實兩種啟動方式的差别是在于對zookeeper上的master 建立的znode 的處理方式和之後進入的狀态。start master是等待znode被删除,而start master --backup 是以休眠的方式等待znode 被删除。
------------------------------------------------
目前隻研究或者了解到這裡,如有錯誤,請各位朋友指正。。