{{{ #!html
hadoop + Hbase + thrift + php
2010 第一次讀書會準備
}}} [[PageOutline]] == 安裝設定 hadoop 0.20 == 略 == 安裝設定 hbase 0.20 == 略 == 安裝設定 thrift 0.2 == [http://incubator.apache.org/thrift/download/ thrift 下載頁面] 將原始碼解壓縮後的完整路徑為 /opt/thrift-0.2.0 安裝之前請先確定有裝了 libboost (c++的函式庫),以及make時會用到的yacc flex {{{ $ apt-get install libboost1.38-dev automake libtool flex bison }}} 接著編譯與安裝thrift {{{ $ ./bootstrap.sh $ ./configure $ make $ sudo make install }}} You should now have a fresh Thrift installation. We now need to generate PHP files that will be included in your application in order to access Hbase. {{{ $ cp -r /opt/hbase/src/java/org/apache/hadoop/hbase/thrift ./hbase_thrift_src $ cd hbase_thrift_src $ thrift --gen php Hbase.thrift }}} If you have followed all above the steps correctly, Thrift should have generated a directory named gen-php/Hbase/ wich contains 2 php files. Those two files contains classes you will use to access hbase. But those files also depends on Thrift base files that you can find in thrift source directory. Following steps assume that your apache home directory is /var/www. Let's copy Thrift base files and create a "packages" directory wich will contains previously generated files. {{{ $ cp -r /opt/thrift-0.2.0/lib/php/src /var/www/thrift (請記得改/var/www下的權限) $ mkdir /var/www/thrift/packages $ cp -r hbase_thrift_src/gen-php/* /var/www/thrift/packages/ }}} Let's now start Hbase thrift server. {{{ $ /opt/hbase/bin/hbase thrift start & }}} == test == {{{ $ cp /opt/hbase/src/examples/thrift/DemoClient.php /var/www/DemoClient.php }}} 修改 /var/www/DemoClient.php 的 {{{ #!text $GLOBALS['THRIFT_ROOT'] = '/var/www/thrift'; $socket = new TSocket( 'secuse.nchc.org.tw', 9090 ); }}} == 參考 == [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
}}}