系統環境與套件版本
- 作業系統環境: Ubuntu 9.04 Server x2
- Hadoop 0.20.2 Fully-distributed modes
- HBase 0.89.20100621 Fully-distributed modes
- Thrift 0.5.0
1. 下載 Thrift 0.5.0
1 |
wget ftp :// ftp .stu.edu.tw/Unix/Web/apache//incubator/thrift/0.5.0-incubating/thrift-0.5.0. tar .gz |
2. 安裝 Thrift 相依套件
Thrift 需要 C++ 的 libboost 函式庫, 以及 flex, libtool 方能運作
1 |
$ sudo apt-get install libboost-dev automake libtool flex bison g++ |
3. 安裝需要的程式語言, 這裡安裝 Python & PHP
注意, 不能裝 php5, 不然會沒有設定檔
1 |
$ sudo apt-get install python python-all-dev |
2 |
$ sudo apt-get install php5-dev |
4. 於 Thrift 目錄執行環境設定檢測
正常應輸出:
03 |
Building code generators ..... : cpp java as3 csharp py rb perl php erl cocoa st ocaml hs xsd html js javame |
05 |
Building C++ Library ......... : yes |
06 |
Building Java Library ........ : yes |
08 |
Building Python Library ...... : yes |
09 |
Building Ruby Library ........ : no |
10 |
Building Haskell Library ..... : no |
11 |
Building Perl Library ........ : no |
12 |
Building PHP Library ......... : yes |
13 |
Building Erlang Library ...... : no |
15 |
Building TZlibTransport ...... : yes |
16 |
Building TNonblockingServer .. : no |
18 |
Using javac .................. : javac |
19 |
Using java ................... : java |
20 |
Using ant .................... : /usr/bin/ant |
22 |
Using Python ................. : /usr/bin/python |
若遇到 Cannot find php-config. Please use –with-php-config=PATH 的問題,表示 Thrift 找不到 PHP5 的設定檔 (不是php.ini)
安裝 php5-dev 後, /usr/bin/php/ 目錄下會有 php-config
5. 編譯與安裝
建立 HBase Thrift PHP 測試專案
- /var/www/hbase — 測試專案目錄
- thrift0.5.0/lib/php/src — Thrift PHP 函式庫
1. 複製 Thrift PHP 函式庫至專案目錄下的thrift目錄
1 |
$ cp -r thrift0.5.0/lib/php/src /var/www/hbase/thrift |
2. 產生HBase Thrift PHP 函式庫
1 |
$ cd /var/www/hbase/thrift |
2 |
$ thrift --gen php $/opt/hbase/src/java/org/apache/hadoop/hbase/thrift/Hbase.thrift |
該指令會在目前位置產生 gen-php 的目錄,目錄內的檔案如下:
2 |
./Hbase/Hbase_types.php |
接著將 gen-php 目錄更名為 packages
3. 從 HBase 原始碼目錄複製出 DemoClient.php 來做測試
1 |
$ cp /opt/hbase/src/examples/thrift/DemoClient.php /var/www/hbase/DemoClient.php |
4. /var/www/hbase 目錄結構
注意是否遺漏 DemoClient & packages目錄
./DemoClient.php
./thrift
./thrift/server
./thrift/server/TServer.php
./thrift/server/TSimpleServer.php
./thrift/packages
./thrift/packages/Hbase
./thrift/packages/Hbase/Hbase_types.php
./thrift/packages/Hbase/Hbase.php
./thrift/Thrift.php
./thrift/autoload.php
./thrift/packages.bak
./thrift/packages.bak/Hbase
./thrift/packages.bak/Hbase/Hbase_types.php
./thrift/packages.bak/Hbase/Hbase.php
./thrift/ext
./thrift/ext/thrift_protocol
./thrift/ext/thrift_protocol/…….
./thrift/protocol
./thrift/protocol/TProtocol.php
./thrift/protocol/TBinaryProtocol.php
./thrift/transport
./thrift/transport/TPhpStream.php
./thrift/transport/TSocketPool.php
./thrift/transport/TMemoryBuffer.php
./thrift/transport/TFramedTransport.php
./thrift/transport/TServerSocket.php
./thrift/transport/TServerTransport.php
./thrift/transport/TTransport.php
./thrift/transport/TSocket.php
./thrift/transport/TNullTransport.php
./thrift/transport/TBufferedTransport.php
./thrift/transport/THttpClient.php
./thrift/transport/TTransportFactory.php
5. 修改 DemoClient.php 的設定參數
cloud1.example.com為主機名稱,不可使用 IP ;9090 是 Thrift 預設使用的port
1 |
(Line 31) $GLOBALS[ 'THRIFT_ROOT' ] = '/var/www/hbase/thrift' ; |
2 |
(Line 52) $socket = new TSocket( 'cloud1.example.com' , 9090 ); |
啟動/停止 HBase thrift 服務
1. 確認 Hadoop 與 HBase 運作狀態
由於 Hadoop 相關專案都是使用 Java 開發, jps 指令可以列出系統目前運作的 Java 程序,方便檢視相關服務有無啟動
啟動服務
省略 --port 參數即表示使用預設 port
$ ./opt/hbase/bin/hbase-daemon.sh start thrift [--port=PORT]
停止服務
$ ./opt/hbase/bin/hbase-daemon.sh stop thrift
檢查運作狀態
瀏覽測試結果
檢視網頁內容:http://cloud1.example.com/hbase/DemoClient.php
正常執行結果應會拋出一個例外,如下:
scanning tables...
found: demo_table
disabling table: demo_table
deleting table: demo_table
found: mytable
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/hbase/DemoClient.php:159
Stack trace:
#0 {main}
thrown in /var/www/hbase/DemoClient.php on line 159