php通过thrift操作hbase
来源:互联网 发布:centos启动mysql服务 编辑:程序博客网 时间:2024/05/17 22:50
环境配置
操作系统 centos 5.8 hadoop版本cloudera cdh3u3 hbase版本hbase-0.90.4-cdh3u3 php版本5.2
1. 下载并编译thrift
# wget http://ftp.tc.edu.tw/pub/Apache/thrift/0.8.0/thrift-0.8.0.tar.gz
安装所需的依赖包
# yum install automake libtool flex bison pkgconfig gcc-c++ boost-devel libevent-devel zlib-devel python-devel ruby-devel php php-devel
# tar zxvf thrift-0.8.0.tar.gz
# cd thrift-0.8.0
# ./configure --prefix=/home/thrift --with-php-config=/usr/bin/php-config
# make && make install
2 生成php和hbase的接口文件:
# cd /home/thrift/
# bin/thrift --gen php $HBASE_HOME/src/main/resources/org/apache/hadoop/hbase/thrift/Hbase.thrift
# cd gen-php/Hbase
# ls
Hbase.php Hbase_types.php
3. 把PHP客户端需要的包及刚才生成的接口文件复制出来供php程序调用:
# mkdir -p /var/www/html/hbasethrift/libs (/var/www/html为apache的web主目录)
# cp -a /home/soft/thrift-0.8.0/lib/php/src /var/www/html/hbasethrift/libs
# mkdir -p /var/www/html/hbasethrift/libs/packages
# cp -a /home/thrift/gen-php/Hbase /var/www/html/hbasethrift/libs/packages
4. 启动hbase thrift server,测试php连接hbase
# ./bin/hbase-daemon.sh start thrift
hbase thrift 默认监听端口为9090
测试php连接与操作hbase代码
# vi hbasethrift.php
<?php$GLOBALS['THRIFT_ROOT'] = '/home/www/html/hbasethrift/libs';require_once( $GLOBALS['THRIFT_ROOT'].'/Thrift.php' );require_once( $GLOBALS['THRIFT_ROOT'].'/transport/TSocket.php' );require_once( $GLOBALS['THRIFT_ROOT'].'/transport/TBufferedTransport.php' );require_once( $GLOBALS['THRIFT_ROOT'].'/protocol/TBinaryProtocol.php' );require_once( $GLOBALS['THRIFT_ROOT'].'/packages/Hbase/Hbase.php' );$socket = new TSocket( 'localhost', 9090 );$socket->setSendTimeout( 10000 ); // Ten seconds (too long for production, but this is just a demo ;)$socket->setRecvTimeout( 20000 ); // Twenty seconds$transport = new TBufferedTransport( $socket );$protocol = new TBinaryProtocol( $transport );$client = new HbaseClient( $protocol );$transport->open();echo nl2br( "listing tables...\n" );$tables = $client->getTableNames();sort( $tables );foreach ( $tables as $name ) {echo nl2br( " found: {$name}\n" );}$columns = array(new ColumnDescriptor( array('name' => 'entry:','maxVersions' => 10) ),new ColumnDescriptor( array('name' => 'unused:') ));$t = "table1";echo( "creating table: {$t}\n" );try {$client->createTable( $t, $columns );} catch ( AlreadyExists $ae ) {echo( "WARN: {$ae->message}\n" );}$t = "test";echo( "column families in {$t}:\n" );$descriptors = $client->getColumnDescriptors( $t );asort( $descriptors );foreach ( $descriptors as $col ) {echo( " column: {$col->name}, maxVer: {$col->maxVersions}\n" );}$t = "table1";echo( "column families in {$t}:\n" );$descriptors = $client->getColumnDescriptors( $t );asort( $descriptors );foreach ( $descriptors as $col ) {echo( " column: {$col->name}, maxVer: {$col->maxVersions}\n" );}$t = "table1";$row = "row_name";$valid = "foobar-\xE7\x94\x9F\xE3\x83\x93";$mutations = array(new Mutation( array('column' => 'entry:foo','value' => $valid) ),);$client->mutateRow( $t, $row, $mutations );$table_name = "table1";$row_name = 'row_name';$fam_col_name = 'entry:foo';$arr = $client->get($table_name, $row_name , $fam_col_name);// $arr = arrayforeach ( $arr as $k=>$v ) {// $k = TCellecho ("value = {$v->value} , <br> ");echo ("timestamp = {$v->timestamp} <br>");}$table_name = "table1";$row_name = "row_name";$arr = $client->getRow($table_name, $row_name);// $client->getRow return a arrayforeach ( $arr as $k=>$TRowResult ) {// $k = 0 ; non-use// $TRowResult = TRowResultvar_dump($TRowResult);}$transport->close();?>
通过浏览器访问http://localhost/hbasethrift/hbasethrift.php,如果显示hbase中的表名与新建表table1 ,说明连接成功。
hbase thrift api 参考http://hbase.apache.org/apidocs/org/apache/hadoop/hbase/thrift/doc-files/index.html
参考http://www.banping.com/2011/07/08/hbase-thrift-php/
- PHP通过Thrift操作Hbase
- PHP通过Thrift操作Hbase
- php通过thrift操作hbase
- PHP通过Thrift操作Hbase
- PHP操作HBASE(通过thrift)
- php通过thrift操作hbase
- php通过thrift操作hbase
- PHP通过Thrift操作Hbase
- php通过thrift 0.9.0操作HBase
- python通过thrift操作hbase
- 通过thrift使用PHP访问Hbase
- python 通过thrift 简单操作hbase
- C#通过thrift连接hbase操作步骤
- 使用C++(通过Thrift) 操作Hbase
- python 通过thrift 简单操作hbase
- C# 通过Thrift 1 操作 HBase
- Thrift了解4:C#通过Thrift操作HBase实战
- php 通过 thrift-0.8.0 连接hbase 以及函数使用
- Altera下载脚本三
- error C2220: 警告被视为错误 - 没有生成“object”文件
- POJ 1201 Intervals
- TempData、ViewData和ViewBag异同
- 【成功案例】风起亚洲助力,创业比赛夺冠
- php通过thrift操作hbase
- Ubuntu 下StarDict词典的安装
- C++创始人——Bjarne Stroustrup,写给c++初学者,创始人的一些经验,此贴转的!希望给初学者能提供一些建议,为中共的软件爱你事业加油啊吧!有好东东大家都出来晒晒晒吧!
- VC内存分配:GlobalAlloc、new、malloc、HeapAlloc
- 写给刚毕业参加工作的朋友
- [Android] 获得系统当前屏幕的分辨率
- IO输入输出之Reader、Writer
- Ext.Net 1.x_Ext.Net.皮肤切换
- 【热门技术】vs2005 下配置WinCE6.0环境