wiki:waue/2010/0401

Version 20 (modified by waue, 13 years ago) (diff)

--

安裝編譯及測試

一、前言

  • 本篇建議使用 Linux 作業系統 Ubuntu 8.04 含以上
  • 假設已經安裝好 Hadoop (0.20 ) Hbase (0.20) Sun Java 6,完成設定,並且已在運作中

安裝設定 hadoop 0.20

  • 本篇的hadoop 安裝於 /opt/hadoop

安裝設定 hbase 0.20

  • 本篇的Hbase 安裝於 /opt/hbase

安裝設定 php & apache

  • 用apt-get install 方式安裝 php 與 apache

二、安裝 thrift

編譯 thrift

  1. 將原始碼解壓縮後的完整路徑為 /opt/thrift,並進入該目錄
$ cd /opt/thrift
  1. 安裝之前請先確定有裝了 libboost (c++的函式庫),以及make時會用到的yacc flex
$ sudo apt-get install build-essential libboost-dev automake libtool flex bison g++ python python-all-dev
  1. 接著編譯與安裝thrift
$ ./bootstrap.sh
$ ./configure
$ make
$ sudo make install

產生 thrift 函式庫

  1. 產生可以存取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 檔還是需要其他檔案當函式庫

  1. 在/var/www內產放入php的thrift函式庫
$ sudo mkdir /var/www/hbase
$ sudo cp -r /opt/thrift/lib/php/src /var/www/hbase/thrift
$ sudo chown -R $USER:$USER /var/www/hbase
$ mkdir /var/www/hbase/thrift/packages
$ cp -r /opt/thrift/hbase_thrift_src/gen-php/* /var/www/hbase/thrift/packages/

三、測試 php -> thrift -> hbase

  1. 複製範例程式 DemoClient.php
$ cd /var/www/hbase
$ cp /opt/hbase/src/examples/thrift/DemoClient.php /var/www/hbase/DemoClient.php
  1. 修改 /var/www/hbase/DemoClient.php
$GLOBALS['THRIFT_ROOT'] = '/var/www/hbase/thrift';
.....
$socket = new TSocket( 'localhost’', 9090 );
.....
  1. 啟動hbase 的 thrift 服務
$ /opt/hbase/bin/hbase thrift start &
  1. 用瀏覽器開啟 http://localhost/hbase/DemoClient.php
scanning tables...
  found: t1
  found: t2
creating table: demo_table
column families in demo_table:
  column: entry, maxVer: 10
  column: unused, maxVer: 3

參考

André-Philippe Paquet's Blog