更新时间:2022-07-19 GMT+08:00
分享

HBase python样例代码调测

仅MRS 1.9.x及之前版本支持HBase python样例代码调测。

HBase支持使用自带的ThriftServer2服务通过python来访问HBase服务。python样例仅支持在Linux环境中运行,调测HBase python样例程序需有与集群环境网络相通的ECS,详情请参见开发和运行环境简介,并需要安装python环境,安装包下载详情请参见:https://www.python.org/。当前以在集群的master节点上运行样例为例。

  1. 搭建样例运行环境。

    获取运行样例程序时python依赖,请从https://pypi.org/地址中搜索下载decorator、gssapi、kerberos、krbcontext、pure-sasl、thrift包(未开启Kerberos认证的普通集群仅需安装thrift包),并上传到master节点上,例如:新建目录“/opt/hbase-examples/python”,并上传到该目录下。
    decorator-4.3.2.tar.gz
    gssapi-1.5.1.tar.gz
    kerberos-1.3.0.tar.gz
    krbcontext-0.8.tar.gz
    pure-sasl-0.6.1.tar.gz
    thrift-0.11.0.tar.gz

  2. 将样例工程中的“hbase-python-example”文件夹上传到集群Master节点的“/opt/hbase-examples”下,并上传从准备开发用户中获取的认证文件至该目录下。
  3. 在“/opt/hbase-examples”新建hbasepython.properties文件,并修改配置内容如下。

    clientHome=/opt/client
    exampleCodeDir=/opt/hbase-examples/hbase-python-example
    pythonLib=/opt/hbase-examples/python
    keyTabFile=/opt/hbase-examples/user.keytab
    userName=hbaseuser
    thriftIp=xxx.xxx.xx.xxx
    • clientHome为集群客户端路径
    • exampleCodeDir为hbase-python-example文件路径
    • pythonLib为1中python依赖存放路径
    • keyTabFile为从准备开发用户获取的用户认证凭据user.keytab
    • userName为准备开发用户中开发用户名
    • thriftIp为安装了thriftserver2的节点的IP地址

  4. 执行如下命令创建表名为example的HBase表。

    source /opt/client/bigdata_env

    kinit 用户名

    echo "create 'example','family1','family2'" | hbase shell

  5. 安装python环境并运行程序。

    cd /opt/hbase-examples/hbase-python-example
    sh initEnvAndRunDemo.sh /opt/hbase-examples/hbasepython.properties
    • 在运行程序之前需要格式化initEnvAndRunDemo.sh脚本。例如执行,dos2unix /opt/hbase-examples/hbasepython.properties
    • 在执行脚本前,请确定“example”表包含列族'family1','family2'并已经存在于集群中。
    • 再次运行程序时只需进入“/opt/hbase-examples/hbase-python-example”目录下,执行如下命令执行程序调测样例:python DemoClient.py

  6. HBase Python应用程序运行完成后,可直接通过运行结果查看应用程序运行情况。

    图1 程序运行成功信息

分享:

    相关文档

    相关产品