温馨提示:如果使用电脑查看图片不清晰,可以使用手机打开文章单击文中的图片放大查看高清原图。
Fayson的github:
https://github.com/fayson/cdhproject
提示:代码块部分可以左右滑动查看噢
1.文档编写目的
Fayson在前面的文章《
如何使用Python Impyla客户端连接Hive和Impala
》介绍了在非安全的CDH集群中使用impyla访问Impala服务,本篇文章Fayson主要介绍如何在集成了OpenLDAP并启用了Sentry的环境下访问Impala。
- 内容概述
1.依赖包安装
2.Python示例代码
3.代码测试
- 测试环境
1.CM5.15.0和CDH5.14.2
2.RedHat7.2
- 前置条件
1.pip工具能够正常安装Python包
2.Impala已集成OpenLDAP
3.Impala已集成Sentry服务
2.Impyla依赖包安装
Impyla所依赖的Python包
- six
- bit_array
- thrift (on Python 2.x) or thriftpy (on Python 3.x)
- thrift_sasl
- sasl
1.首先安装Impyla依赖的Python包
[root@cdh03 ~]# pip install bit_array [root@cdh03 ~]# pip install thrift==0.9.3 [root@cdh03 ~]# pip install six [root@cdh03 ~]# pip install thrift_sasl [root@cdh03 ~]# pip install sasl
(可左右滑动)
注意:thrift的版本必须使用0.9.3,因为Impyla需要0.9.3版本的thrift,使用pip默认安装的为0.10.0或更高版本,需要卸载后重新安装0.9.3版本,卸载命令pip uninstall thrift
2.安装Impyla包
[root@cdh03 ~]# pip install impyla
(可左右滑动)
这里Fayson安装的是impyla0.14.1版本,安装时会判断python中的thrift版本是否为0.9.3,如果thrift非0.9.3版本会被卸载并安装其依赖的版本。
3.Python示例代码
Python连接Impala(impala_test_ldap.py)
root@cdh03 ~]# vim impala_test_ldap.py #coding=utf-8 from impala.dbapi import connect conn = connect(host='cdh01.fayson.com',port=25004,database='default',use_ssl=False,auth_mechanism='PLAIN',user='fayson',password='fayson') cursor = conn.cursor() cursor.execute('show databases') results = cursor.fetchall() print("--------输出所有的DataBases:") print(results) print("--------输出students表的前10行数据:") cursor.execute("select * from students limit 10") results = cursor.fetchall() print(results) cursor.close() conn.close()
(可左右滑动)
4.测试代码
1.在命令行使用python执行impala_test_ldap.py测试
[root@cdh03 ~]# python impala_test_ldap.py
(可左右滑动)
5.总结
Impala服务启用了Sentry并集成了OpenLDAP后,在使用Python的Impyla访问Impala服务时,需要在连接的connect中指定auth_mechanism和use_ssl参数,auth_mechanism参数必须为PLAIN,use_ssl可以根据自己集群的OpenLDAP是否启用SSL指定Ture或False。user和password参数即为OpenLDAP用户的账号和密码。
提示:代码块部分可以左右滑动查看噢
为天地立心,为生民立命,为往圣继绝学,为万世开太平。
温馨提示:如果使用电脑查看图片不清晰,可以使用手机打开文章单击文中的图片放大查看高清原图。
推荐关注Hadoop实操,第一时间,分享更多Hadoop干货,欢迎转发和分享。
原创文章,欢迎转载,转载请注明:转载自微信公众号Hadoop实操
本文暂时没有评论,来添加一个吧(●'◡'●)