从 Python 和 happybase / Thrift 连接到 Hbase

Connect to Hbase from Python and happybase / Thrift

我已经在 CentOS 7.3 的 VirtualBox 虚拟机中的端口 9090 上安装了 Cloudera Manager Express 5.9.0 安装 HBase 和 Thrift 服务器 运行。

请帮助找出我无法通过 happybase 成功连接的原因,或者帮助确定下一步要执行的操作。

我是一名经验丰富的 Java 程序员,正在学习 Python。我在 Java 使用本机接口使用 Hbase 的经验,尽管不是在这个特定环境中。

Python 几乎直接取自 happybase howto 的脚本:

import happybase

connection = happybase.Connection(host='localhost',port=9090,transport='buffered', protocol='compact')

connection.create_table('mytable',
    {'cf1': dict(max_versions=10),
     'cf2': dict(max_versions=1, block_cache_enabled=False),
     'cf3': dict(),  # use defaults
    }
)

错误消息,我找不到很好的参考:

[root@data1 ~]# python testhbase.py
Traceback (most recent call last):
  File "testhbase.py", line 10, in <module> 'cf3': dict(),  # use defaults
  File "build/bdist.linux-x86_64/egg/happybase/connection.py", line 311, in create_table
  File "/usr/lib64/python2.7/site-packages/thriftpy/thrift.py", line 198, in _req return self._recv(_api)
  File "/usr/lib64/python2.7/site-packages/thriftpy/thrift.py", line 210, in _recv fname, mtype, rseqid = self._iprot.read_message_begin()
  File "/usr/lib64/python2.7/site-packages/thriftpy/protocol/compact.py", line 147, in read_message_begin % proto_id)
thriftpy.protocol.exc.TProtocolException: TProtocolException(type=4)
 [root@data1 ~]#

我在端口 9095 上安装了 Thift Web 服务管理器 运行,它报告:

HBase Version   1.2.0-cdh5.9.0, rUnknown    HBase version and revision
Thrift Impl Type    threadpool  Thrift RPC engine implementation type chosen by this Thrift server
Compact Protocol    true    Thrift RPC engine uses compact protocol
Framed Transport    false   Thrift RPC engine uses framed transport

非常感谢任何帮助。谢谢。

我猜你没有使用受支持的 thrift 守护程序版本。

您确定使用了 thrift 1(不是 thrift2)守护程序,并且协议和传输正确吗?

Happybase 仅支持Thrift1。

要python 使用 Thrift2 支持 hbase,试试这个: https://github.com/apache/hbase/blob/master/hbase-examples/src/main/python/thrift2/DemoClient.py

我遇到了同样的问题,在花了 40 多个小时后我发现在 Cloudera VM 中:

settings->network->advance->port forwarding

您需要添加新端口 9090 和 9095(可选)才能使其正常工作。

由于某些原因,Cloudera 镜像中默认没有添加此端口