簡體   English   中英

從 Python 和 happybase / Thrift 連接到 Hbase

[英]Connect to Hbase from Python and happybase / Thrift

我已經安裝了 Cloudera Manager Express 5.9.0 安裝了 HBase,Thrift 服務器在 VirtualBox 虛擬機中的 CentOS 7.3 上的端口 9090 上運行。

請幫助找出我無法通過happybase 成功連接的原因,或幫助確定下一步要采取的措施。

我是一名經驗豐富的 Java 程序員,正在學習 Python。 我有使用本機接口從 Java 使用 Hbase 的經驗,盡管不是在這個特定環境中。

  • 我已經驗證我可以使用 hbase shell 創建表、插入數據等。
  • 我已經驗證 9090(節儉)正在偵聽和接受連接。
  • 我想我已經驗證了 Thrift 服務器正在使用與 happybase 連接參數相同的協議/傳輸設置運行。

幾乎直接從 happybase howto 獲取的 Python 腳本:

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

任何幫助是極大的贊賞。 謝謝你。

Happybase 只支持 Thrift1。

對於使用 Thrift2 的 hbase 的 python 支持,試試這個: https : //github.com/apache/hbase/blob/master/hbase-examples/src/main/python/thrift2/DemoClient.py

我猜您沒有使用受支持的 thrift 守護程序版本。

您確定使用了 thrift 1(不是 thrift2)守護進程,並且使用了正確的協議和傳輸?

我遇到了同樣的問題,在花了 40 多個小時后,我在 Cloudera VM 中發現了這一點:

settings->network->advance->port forwarding

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

出於某種原因,默認情況下未在 Cloudera 映像中添加此端口

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM