wiki:waue/2010/0401

Version 12 (modified by waue, 14 years ago) (diff)

--

安裝編譯及測試

一、前言

  • 本篇作業系統為Ubuntu (9.04)
  • 假設已經安裝好 Hadoop (0.20 ) Hbase (0.20) ,完成設定,並且已在運作中

安裝設定 hadoop 0.20

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

安裝設定 hbase 0.20

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

二、安裝 thrift

編譯 thrift

  1. 將原始碼解壓縮後的完整路徑為 /opt/thrift,並進入該目錄
    $ cd /opt/thrift
    
  1. 安裝之前請先確定有裝了 libboost (c++的函式庫),以及make時會用到的yacc flex
    $ apt-get install libboost1.38-dev automake libtool flex bison
    
  1. 接著編譯與安裝thrift
    $ ./bootstrap.sh
    $ ./configure
    $ make
    $ sudo make install
    
  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 檔還是需要其他檔案當函式庫

三、透過 thrift 存取 hbase

檢查hadoop 與 hbase 是否正常運作中

$ jps
26582 HQuorumPeer
26658 HMaster
16222 TaskTracker
16138 JobTracker
15952 NameNode
16047 DataNode

啟動 hbase 的 thrift daemon

$ /opt/hbase/bin/hbase thrift start &

複製 thrift 的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 /的目錄結構為
    ./
    |-- 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 參數

 $GLOBALS['THRIFT_ROOT'] = '/var/www/hbase/thrift';
 
 $socket = new TSocket( 'secuse.nchc.org.tw', 9090 );

執行

  • 用瀏覽器打開 http://localhost/hbase/DemoClient.php 並檢視網頁內容
    • 出現錯誤訊息為正常現象,可修改程式碼解決
      PHP Warning:  Module 'mcrypt' already loaded in Unknown on line 0
      <html>
      <head>
      <title>DemoClient</title>
      </head>
      <body>
      <pre>
      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
      

參考

André-Philippe Paquet's Blog