1安装 thrift
安裝需要使用到的软件:
我用的是thrift-0.6.0
yum install libboost-dev libevent-dev python-dev automake pkg-config libtool flex bison g++
./configure
make && make install
2,配合 hbase
[root@localhost thrift-0.6.0]# cp -r lib/php/src/ /data/html/
[root@localhost thrift-0.6.0]# cd /data/html/src
[root@localhost src]# thrift --gen php /usr/local/hbase/src/
[root@localhost src]# thrift --gen php /usr/local/hbase/src/main/resources/org/apache/hadoop/hbase/thrift/Hbase.thrift
[root@localhost src]# mv gen-php/ packages
[root@localhost src]# cp /usr/local/hbase/src/examples/thrift/DemoClient.php /data/html/
[root@localhost html]# vim DemoClient.php
改路径:$GLOBALS['THRIFT_ROOT'] = '/data/html/src';
[root@localhost html]# /usr/local/hbase/bin/hbase-daemon.sh start thrift
这里要将Hbase.php Hbase_types.php 放在 Hbase目录下
当然也可以改 DemoClient.php ,将路径对应一下,总之找到就行!!!
[root@localhost packages]# mkdir Hbase
[root@localhost packages]# cp /data/html/src/packages/gen-php/Hbase/* Hbase
安装教程: http://blog.kfchph.com/20-hbase-thrift-050-php5/
API: http://trac.nchc.org.tw/cloud/wiki/waue/2010/HbaseThrift
3,配合 hive
/usr/local /hive /bin/hive --service hiveserver >/dev/null 2>/dev/null &
查看 10000端口是否开启,如下所示
[root@localhost html]# netstat -an|grep 10000
安装教程: http://blog.csdn.net/jiedushi/article/details/6579285
附代码:
<?php
$GLOBALS['THRIFT_ROOT'] = '/data/html/hivephp/Thrift/';
// load the required files for connecting to Hive
require_once $GLOBALS['THRIFT_ROOT'] . 'packages/hive_service/ThriftHive.php';
require_once $GLOBALS['THRIFT_ROOT'] . 'transport/TSocket.php';
require_once $GLOBALS['THRIFT_ROOT'] . 'protocol/TBinaryProtocol.php';
// Set up the transport/protocol/client
$transport = new TSocket('localhost', 10000);
$protocol = new TBinaryProtocol($transport);
$client = new ThriftHiveClient($protocol);
$transport->open();
// run queries, metadata calls etc
#$client->execute('add jar /usr/local/hadoop/hive/lib/hive-contrib-0.7.0-cdh3u0.jar');
$client->execute('add jar /usr/local/hive/lib/hive-contrib-0.8.0.jar');
$client->execute('select count(1) from hdfs_orders');
var_dump($client->fetchAll());
$transport->close();
?>