{{{ #!html
hadoop + Hbase + thrift + php
2010 第一次讀書會準備
}}} [[PageOutline]] = 一、前言 = * 本篇作業系統為Ubuntu (9.04) * 假設已經安裝好 Hadoop (0.20 ) Hbase (0.20) ,完成設定,並且已在運作中 == 安裝設定 hadoop 0.20 == * 本篇的hadoop 安裝於 /opt/hadoop == 安裝設定 hbase 0.20 == * 本篇的Hbase 安裝於 /opt/hbase = 二、安裝 thrift = == 編譯 thrift == * 目前 thrift 最新版本為 0.2 * [http://incubator.apache.org/thrift/download/ thrift 下載頁面] 1. 將原始碼解壓縮後的完整路徑為 /opt/thrift,並進入該目錄 {{{ $ cd /opt/thrift }}} 2. 安裝之前請先確定有裝了 libboost (c++的函式庫),以及make時會用到的yacc flex {{{ $ apt-get install libboost1.38-dev automake libtool flex bison }}} 3. 接著編譯與安裝thrift {{{ $ ./bootstrap.sh $ ./configure $ make $ sudo make install }}} 4. 產生出可以存取hbase的php {{{ $ cp -r /opt/hbase/src/java/org/apache/hadoop/hbase/thrift ./hbase_thrift_src $ cd hbase_thrift_src $ thrift --gen php Hbase.thrift }}} * 以上若動作都確實完成,可以看到已經產生出一個資料夾: gen-php/Hbase/ 並且包含兩個php檔案,此兩個php檔可以幫助你存取hbase,不過此 php 檔還是需要其他檔案當函式庫 = 三、透過 thrift 存取 hbase = == 檢查hadoop 與 hbase 是否正常運作中 == == 啟動 hbase 的 thrift daemon == {{{ $ /opt/hbase/bin/hbase thrift start & }}} == 將整個php 專案都複製到 /var/www/hbase 內 == {{{ $ cp -r /opt/thrift-0.2.0/lib/php/src /var/www/hbase/thrift $(請用 chown 指令來改/var/www/hbase 下的權限) $ mkdir /var/www/hbase/thrift/packages $ cp -r hbase_thrift_src/gen-php/* /var/www/hbase/thrift/packages/ }}} * 完成後/var/www/hbase /的目錄結構為 {{{ #!text ./ |-- DemoClient.php (下一節會提到) `-- thrift |-- Thrift.php |-- autoload.php |-- ext | `-- thrift_protocol | |-- config.m4 | |-- php_thrift_protocol.cpp | `-- php_thrift_protocol.h |-- packages | `-- Hbase | |-- Hbase.php | `-- Hbase_types.php |-- protocol | |-- TBinaryProtocol.php | `-- TProtocol.php `-- transport |-- TBufferedTransport.php |-- TFramedTransport.php |-- THttpClient.php |-- TMemoryBuffer.php |-- TNullTransport.php |-- TPhpStream.php |-- TSocket.php |-- TSocketPool.php `-- TTransport.php }}} = 四、測試 = == 複製DemoClient.php 到測試目錄/var/www/hbase/ == {{{ $ cp /opt/hbase/src/examples/thrift/DemoClient.php /var/www/hbase/DemoClient.php }}} * 修改 /var/www/hbase/DemoClient.php 的THRIFT_ROOT 參數 {{{ #!php $GLOBALS['THRIFT_ROOT'] = '/var/www/hbase/thrift'; $socket = new TSocket( 'secuse.nchc.org.tw', 9090 ); }}} * 用瀏覽器打開 http://localhost/hbase/DemoClient.php 並檢視網頁內容 = 參考 = [http://appaquet.blogspot.com/2008/11/thrift-hbase-php.html André-Philippe Paquet's Blog] = 除錯 = * 出現錯誤訊息 {{{ #!php PHP Warning: Module 'mcrypt' already loaded in Unknown on line 0 DemoClient
scanning tables...
creating table: demo_table
column families in demo_table:
  column: entry, maxVer: 10
  column: unused, maxVer: 3

Fatal error: Uncaught exception 'Exception' with message 'shouldn't get here!' in /var/www/DemoClient.php:158
Stack trace:
#0 {main}
  thrown in /var/www/DemoClient.php on line 158
}}}