hbase 0.94 + thrift 0.7.0 安裝 (2)

之前介紹了thrift的安裝,
在這裡要特別提醒的是, thrift有版本相容問題,
以作者的測試經驗, 0.9.1和0.9.2版的thrift都和hbase 0.94不相容,
不相容的地方主要在於library的位置, 以及name space的支援,
若是使用較新版本的thrift, 可能要自行更改一些變數設定,


完成thrift的安裝後, 接下來, 要使用PHP存取hbase,
在PHP架構下, 網頁存放在/var/www資料夾下,
因此, 我們先為測試用的網頁(DemoClient.php)建立資料夾,
指令如下:

$ sudo mkdir /var/www/hbase
$ sudo mkdir /var/www/hbase/thrift

接著, 我們產生thrift需要的library檔案,
這裡, 需要引入hbase的library, 我們在/opt/thrift下進行操作:
[note: 2016/05/09]如果出現權限問題, 請用chmod -R 777 /opt/thrift 更改權限

$ cd /opt/thrift
$ mkdir hbase_thrift_src
$ cp -r /opt/hbase/src/main/resources/org/apache/hadoop/hbase/thrift/* ./hbase_thrift_src
$ cd hbase_thrift_src
$ thrift --gen php Hbase.thrift

這個指令會產生thrift PHP的library在gen-php/Hbase資料夾中,
裡面並包含兩個PHP檔案(Hbase.php  Hbase_types.php),
我們將這兩個檔案放到/var/www/hbase/thrift/packages下,
並從hbase的位置複製DemoClient.php以及其他library到/var/www/hbase/thrift/
以下是參考的指令:

$ sudo cp -r /opt/thrift/lib/php/src/* /var/www/hbase/thrift
$ sudo mkdir /var/www/hbase/thrift/packages
$ sudo cp -r /opt/thrift/hbase_thrift_src/gen-php/* /var/www/hbase/thrift/packages/
$ sudo cp /opt/hbase/src/examples/thrift/DemoClient.php /var/www/hbase/DemoClient.php

接著, 我們要修改DemoClient.php檔,
改變下列兩個變數:

$GLOBALS['THRIFT_ROOT'] = '/var/www/hbase/thrift';
$socket = new TSocket( '127.0.0.1', 9090 );

在這裡, 把127.0.0.1改成thrift服務所在的機器IP位址,
並在該機器上開啟thrift服務, 

$ /opt/hbase/bin/hbase-daemon.sh start thrift

這樣一來, 就可以透過網頁(PHP)存取hbase,
由於我們在VM中建立環境, 因此, 我們已curl取代瀏覽器測試,

$ curl 192.168.2.52/hbase/DemoClient.php
<html>
<head>
<title>DemoClient</title>
</head>
<body>
<pre>
scanning tables...
  found: demo_table
    disabling table: demo_table
    deleting table: demo_table
creating table: demo_table
column families in demo_table:
  column: entry:, maxVer: 10
  column: unused:, maxVer: 3

在網頁中, 我們看到DemoClient.php先刪除了demo_table,
之後並建立一個新的demo_table, 並進行讀取(scan),
更多的PHP存取hbase的API可以參考這裡.

參考資料:
http://thrift.apache.org/
http://thrift.apache.org/docs/install/debian
https://sites.google.com/site/waue0920/Home/hbase/hadoop-hbase-thrift-php-an-zhuang-she-ding-cheng-shi-she-ji
http://wiki.apache.org/hadoop/Hbase/ThriftApi
http://blog.johnsonlu.org/ubuntuhbase-thrift-php/

留言

熱門文章

LTE筆記: RSRP, RSSI and RSRQ

[WiFi] WiFi 網路的識別: BSS, ESS, SSID, ESSID, BSSID

LTE筆記: 波束成型 (beamforming) 和天線陣列