详解PHP连接Impala安装与配置


title: 详解PHP连接Impala安装与配置
date: 2017-12-08
categories:

  • 技术
    tags:
  • PHP
  • impala

Impala的SQL语法参考

https://www.cloudera.com/documentation/enterprise/latest/topics/impala_langref_sql.html

PHP通过Thrift连接Impala

安装thrift服务
  • Thrift最初由Facebook开发用做系统内各语言之间的RPC通信.
  • Thrift是一款可伸缩跨语言的服务开发框架, 该框架已经开源并且加入的Apache项目.
  • Thrift主要功能是: 通过自定义的Interface Definition Language(IDL), 可以创建基于RPC的客户端和服务端的服务代码.
  • 数据和服务代码的生成是通过Thrift内置的代码生成器来实现的, Thrift的跨语言性体现在:它可以生成C++/Java/Python/PHP/Ruby/Erlang/Perl/Haskell/C#/Cocoa/JavaScript/Node.js/Smalltalk/OCaml/Delphi等语言的代码,且它们之间可以进行透明的通信.
[root@localhost tools]# rpm -ivh thrift-0.9.0-28.1.i686.rpm

warning: thrift-0.9.0-28.1.i686.rpm: Header V3 DSA/SHA1 Signature, key ID a949b429: NOKEY
error: Failed dependencies:
libc.so.6 is needed by thrift-0.9.0-28.1.i686
libc.so.6(GLIBC_2.0) is needed by thrift-0.9.0-28.1.i686
libc.so.6(GLIBC_2.1) is needed by thrift-0.9.0-28.1.i686
libc.so.6(GLIBC_2.1.3) is needed by thrift-0.9.0-28.1.i686
libc.so.6(GLIBC_2.3) is needed by thrift-0.9.0-28.1.i686
libc.so.6(GLIBC_2.3.4) is needed by thrift-0.9.0-28.1.i686
libc.so.6(GLIBC_2.4) is needed by thrift-0.9.0-28.1.i686
libgcc_s.so.1 is needed by thrift-0.9.0-28.1.i686
libgcc_s.so.1(GCC_3.0) is needed by thrift-0.9.0-28.1.i686
libm.so.6 is needed by thrift-0.9.0-28.1.i686
libstdc++.so.6 is needed by thrift-0.9.0-28.1.i686
libstdc++.so.6(CXXABI_1.3) is needed by thrift-0.9.0-28.1.i686
libstdc++.so.6(CXXABI_1.3.1) is needed by thrift-0.9.0-28.1.i686
libstdc++.so.6(GLIBCXX_3.4) is needed by thrift-0.9.0-28.1.i686
libstdc++.so.6(GLIBCXX_3.4.11) is needed by thrift-0.9.0-28.1.i686
libstdc++.so.6(GLIBCXX_3.4.9) is needed by thrift-0.9.0-28.1.i686

#报错, 缺少相关依赖.
#解决libc.so.6依赖:

[root@localhost tools]# yum list glibc*
[root@localhost tools]# yum install glibc.i686

#解决libgcc_s.so.1依赖:到https://rpmfind.net/linux/rpm2html/search.php?query=libgcc_s.so.1下载相关依赖rpm包

[root@localhost tools]# rpm -ivh libgcc-4.4.7-18.el6.x86_64.rpm
[root@localhost tools]# rpm -ivh libgcc-4.4.7-18.el6.i686.rpm

#解决libstdc++.so.6依赖:
#到https://rpmfind.net/linux/rpm2html/search.php?query=libstdc++.so.6下载相关依赖rpm包

[root@localhost tools]# rpm -ivh libstdc++-4.4.7-18.el6.i686.rpm

#最后重新安装即可:
[root@localhost tools]# rpm -ivh thrift-0.9.0-28.1.i686.rpm
        warning: thrift-0.9.0-28.1.i686.rpm: Header V3 DSA/SHA1 Signature, key ID a949b429: NOKEY
        Preparing...                ########################################### [100%]
           1:thrift                 ########################################### [100%]
检查是否安装成功

a. 首先创建Thrift的语法规则文件, 命名为server.thrift, 内容如下:

struct message
{
    i32 seqId,
    string content
}
service serDemo
{
    void put(message msg)
}

b. 然后shell下执行命令:

# thrift -gen php server.thrift

该语句用于创建php服务框架, 创建成功后会在该目录下生成gen-php文件夹.

impala的SQL查询参考

http://www.cloudera.com/documentation/archive/impala/2-x/2-1-x/topics/impala_select.html

连接PHP例子参考

https://github.com/Automattic/php-thrift-sql

# git clone https://github.com/Automattic/php-thrift-sql.git
# cd php-thrift-sql/
# php -c php.ini build.php  【重新生成ThriftSQL.phar文件】
# vim test.php  

内容如下:

<?php
// Load this lib
require_once __DIR__ . '/ThriftSQL.phar';
// 1.Try out a Hive query
$hive = new \ThriftSQL\Hive('192.168.8.207', 21050);
$hiveTables = $hive
    ->setSasl(false) // To turn SASL auth off, on by default
    ->connect()
    ->queryAndFetchAll('SHOW TABLES');
print_r($hiveTables);
// 2.Try out an Impala query
$impala = new \ThriftSQL\Impala('192.168.8.207');
$impalaTables = $impala
    ->connect()
    ->queryAndFetchAll('SHOW TABLES');
print_r($impalaTables);
// 3.Try out an Impala query
$impalaDatas = $impala
    ->connect()
    ->queryAndFetchAll('select * from db_mcfx_log.t
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值