1. 程式人生 > >Hbase叢集間資料遷移方法總結

Hbase叢集間資料遷移方法總結

呵呵,今天花了一天的時間查資料做測試,略微的總結了一下hbase資料遷移的方法。

一、需要在hbase叢集停掉的情況下遷移

  步驟:(1)執行hadoop distcp -f filelist "hdfs://new cluster ip:9000/hbasetest" 
       (2)在new cluster執行./hbase org.jruby.Main add_table.rb /hbase/table20111222,將拷貝來的表加入到.MEAT.中(會出現region的數目不一致的問題,這個需要重啟hase才能解決)
  說明:(1)filelist為hdfs上的列表檔案,內容如下:
              /hbase/table20111222
            /hbase/table20120131
       (2)如果兩個叢集的hadoop版本不一致,需要在new cluster上執行hadoop distcp,否則會出現讀寫異常;

二、在叢集執行的時候進行資料遷移
1、Replication:這個是動態的備份(可以理解為實時備份)

     步驟:(1)在old cluster將需要遷移的表屬性進行修改:
               disable 'your_table'
              alter 'your_table', {NAME => 'family_name', REPLICATION_SCOPE => '1'}
              enable 'your_table'
         (2)開啟new cluster叢集的replication,修改hbase-site.xml
            <property>
              <name>hbase.replication</name>
              <value>true</value>
            </property>
         (3)新增peer,在new cluster的hbase shell中執行:add_peer '1','old cluster ip:2181:/hbase',啟動replication,執行start_replication
     說明:需要兩個叢集的hadoop版本一致,否則出現讀寫錯誤

2、CopyTable:可以在本叢集中拷貝一張表,也可以將表拷貝到其他的叢集中。
    命令:./hbase org.apache.hadoop.hbase.mapreduce.CopyTable --peer.adr=new cluster ip:2181:/hbase zy_test
    說明:(1)拷貝完成,不需要重啟機器,在new cluster中就可以看到該表;
         (2)穩定性還需要考慮,測試過程中遇到一個問題,拷貝過程中始終都停留在這裡Lookedup root region location, 檢視日誌沒有什麼錯誤和相關的資訊。

3、Export and Import
    步驟:(1)在old cluster上執行:./hbase org.apache.hadoop.hbase.mapreduce.Export test hdfs://new cluster ip:9000/zhuangyang/test
         (2)在new cluster上執行:./hbase org.apache.hadoop.hbase.mapreduce.Import test hdfs://new cluster ip:9000/zhuangyang/test
    說明:(1)一定要寫全路徑,不能寫相對路勁;
         (2)在import前,需要將表事先在new cluster中建立好.

以上都是在old cluster和new cluster網路相通的情況下實現資料遷移的辦法。
如果兩個叢集網路不通,只能先將old cluster中的資料都下載到本地或者其他的地方,然後在人工的轉移到new cluster上了,可以參看這篇文章http://blog.csdn.net/hua840812/article/details/6866175。