长沙模板建站,电子贺卡免费制作,为wordpress添加虚拟用户权限,没人注意的暴利行业系统架构图HBase 启动 Thrift服务hbase启动thrift服务// 进入安装的hbase bin目录下// 执行hbase-daemon.sh start thrift2需要注意的是#xff0c;这里启动的是thrift2服务#xff0c;如果需要启动thrift服务只需要将thrift2改为thrift就可以了#xff0c;具体thrift和thri…系统架构图HBase 启动 Thrift服务hbase启动thrift服务// 进入安装的hbase bin目录下// 执行hbase-daemon.sh start thrift2需要注意的是这里启动的是thrift2服务如果需要启动thrift服务只需要将thrift2改为thrift就可以了具体thrift和thrift2之间的区别可以参考以下文章hbase的thrift接口生成 php所需hbase相关php类首先到appache官网上下载thrift windows 可执行程序 thrift-0.9.0.exe 和thrift-0.9.0.tar.gz 两个文件 下载地址从linux环境中的Hbase安装目录里获取hbase.thrift文件这个文件用来生成相关php类// thrift/opt/soft/hbase/hbase-thrift/src/main/resources/org/apache/hadoop/hbase/thrift/Hbase.thrift// thrift2/opt/soft/hbase/hbase-thrift/src/main/resources/org/apache/hadoop/hbase/thrift2/hbase.thrift这里/opt/soft/hbase为hbase安装目录将上面的hbase.thrift文件移到windows下放到刚刚下载好的thrift-0.9.0.exe目录下,执行// 生成hbase必要的php相关类thrift-0.9.0.exe -gen php hbase.thrift可以看到目录下多出了gen-php目录gen-php目录下包含THBaseService.php和Types.php两个php文件注意这里采用的是thrift-0.9.0版本生成的是上述两个版本在 thrift-1.0.0以上的版本生成的文件和引入方式有所不同这里暂只介绍thrift-0.9.0版本所生成的相关php文件引入方式在php项目中新建一个hbase目录并拷贝如下文件1.THBaseService.php 和 Types.php 拷贝到/hbase目录下2.解压thrift-0.9.0.tar.gz 并将 thrift-0.9.0\lib\php\lib\Thrift 下所有文件拷贝到 /hbase/Thrift目录下此时目录结构应该是这样的hbase目录Thrift目录这样php所需要的hbase相关php类都在/hbase这个目录下了PHP导入Hbase相关类在php文件中编写如下代码导入Hbase相关依赖$GLOBALS[HBASE_ROOT] /hbase;require_once $GLOBALS[HBASE_ROOT]./Thrift/ClassLoader/ThriftClassLoader.php;use Thrift\ClassLoader\ThriftClassLoader;use Thrift\Protocol\TBinaryProtocol;use Thrift\Transport\TSocket;use Thrift\Transport\TBufferedTransport;$loader new ThriftClassLoader();$loader-registerNamespace(Thrift, dirname(dirname(__DIR__)) . /hbase/);$loader-register();require_once $GLOBALS[HBASE_ROOT]./THBaseService.php;require_once $GLOBALS[HBASE_ROOT]./Types.php;测试连接是否成功$host 127.0.0.1;$port 8020;$socket new TSocket($host, $port);$transport new TBufferedTransport($socket);$protocol new TBinaryProtocol($transport);$client new THBaseServiceClient($protocol);$transport-open();return $client;再来个查询$scanId $client-openScanner( $tableName , $scan);$numRows 100;$resultList [];while (true) {$arr $client-getScannerRows($scanId, $numRows);$resultList array_merge($resultList, $arr);if (count($arr) $numRows) {break;}}$client-closeScanner($scanId);return $resultList;Types.php 存放的是hbase定义的相关类、THBaseService定义的是client相关操作