Changes between Version 15 and Version 16 of waue/2010/0401


Ignore:
Timestamp:
Sep 27, 2010, 5:25:59 PM (14 years ago)
Author:
waue
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • waue/2010/0401

    v15 v16  
    2222
    2323 1. 將原始碼解壓縮後的完整路徑為 /opt/thrift,並進入該目錄
     24
    2425{{{
    2526$ cd /opt/thrift
     
    2728
    2829 2.  安裝之前請先確定有裝了 libboost (c++的函式庫),以及make時會用到的yacc flex
     30
    2931{{{
    3032$ sudo apt-get install libboost-dev automake libtool flex bison g++ python python-all-dev
     
    3234
    3335 3. 接著編譯與安裝thrift
     36
    3437{{{
    3538$ ./bootstrap.sh
     
    3942}}}
    4043
    41  4. 產生出可以存取hbase的php
     44 4. 產生可以存取hbase的php函式庫
    4245
    4346{{{
     
    4750}}}
    4851
    49  * 以上若動作都確實完成,可以看到已經產生出一個資料夾: gen-php/Hbase/ 並且包含兩個php檔案,此兩個php檔可以幫助你存取hbase,不過此 php 檔還是需要其他檔案當函式庫
     52以上若動作都確實完成,可以看到已經產生出一個資料夾: gen-php/Hbase/ 並且包含兩個php檔案,此兩個php檔可以幫助你存取hbase,不過此 php 檔還是需要其他檔案當函式庫
    5053
    51  = 三、透過 thrift 存取 hbase =
    52 
    53  == 檢查hadoop 與 hbase 是否正常運作中 ==
     54 5. 在/var/www內產放入php的thrift函式庫
    5455
    5556{{{
    56 $ jps
    57 26582 HQuorumPeer
    58 26658 HMaster
    59 16222 TaskTracker
    60 16138 JobTracker
    61 15952 NameNode
    62 16047 DataNode
     57$ mkdir /var/www/hbase
     58$ cp -r /opt/hbase/thrift/lib/php/src /var/www/hbase/thrift
     59$ chown -R $USER:$USER /var/www/hbase
     60$ mkdir /var/www/hbase/thrift/packages
     61$ cp -r hbase_thrift_src/gen-php/* /var/www/hbase/thrift/packages/
    6362}}}
    6463
    65  == 啟動 hbase 的 thrift daemon ==
     64
     65 = 三、測試 php -> thrift -> hbase =
     66
     67 1. 複製範例程式 DemoClient.php
     68
     69{{{
     70$ cp /opt/hbase/src/examples/thrift/DemoClient.php /var/www/hbase/DemoClient.php
     71}}}
     72
     73 2. 修改 /var/www/hbase/DemoClient.php
     74
     75{{{
     76$GLOBALS['THRIFT_ROOT'] = '/var/www/hbase/thrift';
     77.....
     78$socket = new TSocket( 'localhost’', 9090 );
     79.....
     80}}}
     81
     82
     83 3. 啟動hbase 的 thrift 服務
    6684
    6785{{{
     
    6987}}}
    7088
    71  == 複製 thrift 的php 專案到網頁伺服器 ==
    72  * 複製到 /var/www/hbase 內
     89 4. 用瀏覽器開啟 [http://localhost/hbase/DemoClient.php]
    7390
    7491{{{
    75 $ cp -r /opt/thrift-0.2.0/lib/php/src /var/www/hbase/thrift
    76 $(請用 chown 指令來改/var/www/hbase 下的權限)
    77 $ mkdir /var/www/hbase/thrift/packages
    78 $ cp -r hbase_thrift_src/gen-php/* /var/www/hbase/thrift/packages/
    79 }}}
    80 
    81  * 完成後/var/www/hbase /的目錄結構為
    82 {{{
    8392#!text
    84 ./
    85 |-- DemoClient.php (下一節會提到)
    86 `-- thrift
    87     |-- Thrift.php
    88     |-- autoload.php
    89     |-- ext
    90     |   `-- thrift_protocol
    91     |       |-- config.m4
    92     |       |-- php_thrift_protocol.cpp
    93     |       `-- php_thrift_protocol.h
    94     |-- packages
    95     |   `-- Hbase
    96     |       |-- Hbase.php
    97     |       `-- Hbase_types.php
    98     |-- protocol
    99     |   |-- TBinaryProtocol.php
    100     |   `-- TProtocol.php
    101     `-- transport
    102         |-- TBufferedTransport.php
    103         |-- TFramedTransport.php
    104         |-- THttpClient.php
    105         |-- TMemoryBuffer.php
    106         |-- TNullTransport.php
    107         |-- TPhpStream.php
    108         |-- TSocket.php
    109         |-- TSocketPool.php
    110         `-- TTransport.php
    111 }}}
    112 
    113  = 四、測試 =
    114  
    115  == 複製DemoClient.php 到測試目錄/var/www/hbase/  ==
    116 {{{
    117 $ cp /opt/hbase/src/examples/thrift/DemoClient.php /var/www/hbase/DemoClient.php
    118 }}}
    119 
    120  == 修改 /var/www/hbase/DemoClient.php 的THRIFT_ROOT 參數 ==
    121 
    122 {{{
    123 #!php
    124  $GLOBALS['THRIFT_ROOT'] = '/var/www/hbase/thrift';
    125  
    126  $socket = new TSocket( 'localhost', 9090 );
    127 }}}
    128 
    129  == 執行 ==
    130  *  用瀏覽器打開 http://localhost/hbase/DemoClient.php 並檢視網頁內容
    131    *  出現錯誤訊息為正常現象,可修改程式碼解決
    132 {{{
    133 #!php
    134 PHP Warning:  Module 'mcrypt' already loaded in Unknown on line 0
    135 <html>
    136 <head>
    137 <title>DemoClient</title>
    138 </head>
    139 <body>
    140 <pre>
    14193scanning tables...
     94  found: t1
     95  found: t2
    14296creating table: demo_table
    14397column families in demo_table:
    14498  column: entry, maxVer: 10
    14599  column: unused, maxVer: 3
    146 
    147 Fatal error: Uncaught exception 'Exception' with message 'shouldn't get here!' in /var/www/DemoClient.php:158
    148 Stack trace:
    149 #0 {main}
    150   thrown in /var/www/DemoClient.php on line 158
    151100}}}
    152101