文章目录

Ubuntu Kylin16.04Anaconda环境下的Python3.9HBase1.1.5hbase-thrift-0.20.0.patchThrift0.16.0Python3 通过
thrift,rpc接口操作HBase,指定依赖库为:thrift和hbase-thrift。 然而我们 在 Python3 环境中发现 hbase-thrift-0.20.4无法被支持, hbase-thrift 官方仅推荐用于 python2.x 。 所以需要使用下边的 patch 版本 和 patch 版本写法的客户端「第一种Python调用HBase的方法」。
root@node01:~$ conda create -n test python=3.9
root@node01:~$ conda activate test
(test) root@node01:~$ pip3 list | grep hbase-thrift
(test) root@node01:~$ pip3 uninstall -y hbase-thrift
(test) root@node01:/usr/local$ wget http://dl.cpp.la/Archive/hbase-thrift-0.20.4.patch.tgz
报错
--2022-09-17 20:06:13-- http://dl.cpp.la/Archive/hbase-thrift-0.20.4.patch.tgz
正在解析主机 dl.cpp.la (dl.cpp.la)... 3.0.3.0
正在连接 dl.cpp.la (dl.cpp.la)|3.0.3.0|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 502 Bad Gateway
2022-09-17 20:06:14 错误 502:Bad Gateway。
错误 502:Bad Gateway。
尝试以下方法下载
(test) root@node01:/usr/local$ wget --no-cookies http://dl.cpp.la/Archive/hbase-thrift-0.20.4.patch.tgz
该方法不可行
建议在Windows下载后上传到Linux上
(test) root@node01:/usr/local/$ cd hbase-thrift-0.20.4.patch
(test) root@node01:/usr/local/hbase-thrift-0.20.4.patch$ python3 setup.py install
报错
Traceback (most recent call last):
File "setup.py", line 2, in <module>
from setuptools import setup, find_packages
ImportError: No module named 'setuptools'
按照提示,下载
setuptools
(test) root@node01:/usr/local$ apt-get install python3-setuptools
(test) root@node01:/usr/local/hbase-thrift-0.20.4.patch$ sudo python3 setup.py install
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa2 in position 37: invalid start byte in /usr/local/hbase-thrift-0.20.4.patch/._hbase_thrift.egg-info
各种报错接连不断,人都麻了
删除并卸载hbase-thrift相关内容
看到这些字样就代表成功了
Installed /usr/local/anaconda/envs/test/lib/python3.9/site-packages/six-1.16.0-py3.9.egg
Finished processing dependencies for hbase-thrift===0.20.4.patch
(test) root@node01:/usr/local/hbase-thrift-patch/hbase-thrift-0.20.4.patch$ pip3 list | grep hbase-thrift
hbase-thrift 0.20.4.patch
from thrift import Thrift
from thrift.transport import TSocket,TTransport
from thrift.protocol import TBinaryProtocol
from hbase import Hbase
# thrift默认端口是9090
socket = TSocket.TSocket('127.0.0.1',9090)
socket.setTimeout(5000)
transport = TTransport.TBufferedTransport(socket)
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = Hbase.Client(protocol)
socket.open()
from hbase.ttypes import ColumnDescriptor,Mutation,BatchMutation,TRegionInfo
from hbase.ttypes import IOError,AlreadyExists
print(client.getTableNames()) # 获取当前所有的表名
此处应该提前安装pymysql
(test) root@node01:/usr/local/$ pip3 install -y pymsql
需要提前开启thrift服务,否则会报错
Could not connect to any of [('127.0.0.1', 9090)]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/anaconda/envs/pyhbase/lib/python3.9/site-packages/thrift-0.16.0-py3.9-linux-x86_64.egg/thrift/transport/TSocket.py", line 146, in open
raise TTransportException(type=TTransportException.NOT_OPEN, message=msg)
thrift.transport.TTransport.TTransportException: Could not connect to any of [('127.0.0.1', 9090)]
sudo netstat -lp | grep 9090
test@node01:/usr/local/hbase-1.1.5$ hbase-daemon.sh start thrift
starting thrift, logging to /usr/local/hbase-1.1.5/bin/../logs/hbase-test-thrift-node01.out
test@node01:/usr/local/hbase-1.1.5$ jps
3904 NodeManager
3268 NameNode
5381 Jps
4568 HMaster
4696 HRegionServer
5305 ThriftServer
3420 DataNode
3774 ResourceManager
3614 SecondaryNameNode
4463 HQuorumPeer
可以看到已经有ThriftServer
>>> from thrift import Thrift
>>> from thrift.transport import TSocket,TTransport
>>> from thrift.protocol import TBinaryProtocol
>>> from hbase import Hbase
>>> # thrift默认端口是9090
>>> socket = TSocket.TSocket('127.0.0.1',9090)
>>> socket.setTimeout(5000)
>>> transport = TTransport.TBufferedTransport(socket)
>>> protocol = TBinaryProtocol.TBinaryProtocol(transport)
>>> client = Hbase.Client(protocol)
>>> socket.open()
>>> from hbase.ttypes import ColumnDescriptor,Mutation,BatchMutation,TRegionInfo
>>> from hbase.ttypes import IOError,AlreadyExists
>>> print(client.getTableNames()) # 获取当前所有的表名
['SC', 'Student', 'job_tmp', 'user_action']
使用Python调用HBase需要启动Thrift服务,但由于Linux本身没有内置该安装包,需要手动下载并安装
# 下载
(test) root@node01:/usr/local/$ wget https://mirrors.aliyun.com/apache/thrift/0.16.0/thrift-0.16.0.tar.gz?spm=a2c6h.25603864.0.0.654e1a4a7lakI8
# 重命名
(test) root@node01:/usr/local/$ mv thrift-0.16.0.tar.gz?spm=a2c6h.25603864.0.0.654e1a4a7lakI8 thrift-0.16.0.tar.gz
# 解压
(test) root@node01:/usr/local/$ tar -zxvf thrift-0.16.0.tar.gz -C ./
在编译安装Thrift之前,需要提前安装Thrift依赖的库,如 Automake、LibTool、Bison、Boost等,请参考「Thrift官网安装手册」
https://thrift.apache.org/docs/install/
A relatively POSIX-compliant *NIX system
Cygwin or MinGW can be used on Windows (but there are better options, see below)
g++ 4.2 (4.8 or later required for thrift compiler plug-in support)
boost 1.53.0
Runtime libraries for lex and yacc might be needed for the compiler.
g++ 4.2、boost 1.53.0、编译可能需要的运行时库lex、yacc
– 从源代码构建的要求「Requirements for building from source」
GNU build tools:
autoconf 2.65
automake 1.13
libtool 1.5.24
pkg-config autoconf macros (pkg.m4)
lex and yacc (developed primarily with flex and bison)
libssl-dev
apt-get install automake bison flex g++ git libboost1.55 libevent-dev libssl-dev libtool make pkg-config
## 进入Thrift安装目录
(test) root@node01:/usr/local/thrift-0.16.0$ ./configure
(test) root@node01:/usr/local/thrift-0.16.0$ make
(test) root@node01:/usr/local/thrift-0.16.0$ make install
(test) root@node01:/usr/local/thrift-0.16.0$ thrift --version
Thrift version 0.16.0
HBase的源代码中,
hbase.thrift文件描述了HBase服务API和有关对象的IDl文件,需要使用thrift命令对此文件进行编译,生成Python链接HBase的库包。Hbase.thrift 文件在HBase安装目录中的hbase-thrift目录下
# 创建目录
root@node01:/usr/local/thrift-0.16.0$ mkdir pythonhbase
# 进入pythonhbase目录下
root@node01:/usr/local/thrift-0.16.0$ cd pythonhbase
# 执行thrift命令生成Hbase的Python库
root@node01:/usr/local/thrift-0.16.0$ thrift --gen py ../hbase-1.15/hbase-thrift/src/main/resources/org/apache/hadoop/hbase/thrift/Hbase.thrift
注意:py 指的是Python语言,thrift可以指定多种语言编译
另外,此处的HBase安装目录下是没有hbase-thrift的,需要下载并放置Hbase安装目录下
gen-py 目录下的 hbase 子目录 到工程目录 python3.6/site-packages/hbase 下直接使用如果没有上一步骤中的编译操作,那么Python3操作hbase会报错,可以按以下方法解决
首先要下载Python3的Hbase文件,替换Hbase文件/usr/local/lib/python3.6/dist-packages/hbase/Hbase.py和ttypes.py
https://github.com/626626cdllp/infrastructure/tree/master/hbase
最后就是测试是否可以使用Python成功访问HBase客户端,和第一种方法一样,不再赘述
https://www.qb5200.com/article/359274.html
NoSQL数据库原理与应用[人民邮电出版社]
https://blog.51cto.com/u_15187242/3729044
我正在学习如何使用Nokogiri,根据这段代码我遇到了一些问题:require'rubygems'require'mechanize'post_agent=WWW::Mechanize.newpost_page=post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')puts"\nabsolutepathwithtbodygivesnil"putspost_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div
总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看rubyzip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d
类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc
很好奇,就使用rubyonrails自动化单元测试而言,你们正在做什么?您是否创建了一个脚本来在cron中运行rake作业并将结果邮寄给您?git中的预提交Hook?只是手动调用?我完全理解测试,但想知道在错误发生之前捕获错误的最佳实践是什么。让我们理所当然地认为测试本身是完美无缺的,并且可以正常工作。下一步是什么以确保他们在正确的时间将可能有害的结果传达给您? 最佳答案 不确定您到底想听什么,但是有几个级别的自动代码库控制:在处理某项功能时,您可以使用类似autotest的内容获得关于哪些有效,哪些无效的即时反馈。要确保您的提
假设我做了一个模块如下:m=Module.newdoclassCendend三个问题:除了对m的引用之外,还有什么方法可以访问C和m中的其他内容?我可以在创建匿名模块后为其命名吗(就像我输入“module...”一样)?如何在使用完匿名模块后将其删除,使其定义的常量不再存在? 最佳答案 三个答案:是的,使用ObjectSpace.此代码使c引用你的类(class)C不引用m:c=nilObjectSpace.each_object{|obj|c=objif(Class===objandobj.name=~/::C$/)}当然这取决于
我正在尝试使用ruby和Savon来使用网络服务。测试服务为http://www.webservicex.net/WS/WSDetails.aspx?WSID=9&CATID=2require'rubygems'require'savon'client=Savon::Client.new"http://www.webservicex.net/stockquote.asmx?WSDL"client.get_quotedo|soap|soap.body={:symbol=>"AAPL"}end返回SOAP异常。检查soap信封,在我看来soap请求没有正确的命名空间。任何人都可以建议我
我正在尝试设置一个puppet节点,但rubygems似乎不正常。如果我通过它自己的二进制文件(/usr/lib/ruby/gems/1.8/gems/facter-1.5.8/bin/facter)在cli上运行facter,它工作正常,但如果我通过由rubygems(/usr/bin/facter)安装的二进制文件,它抛出:/usr/lib/ruby/1.8/facter/uptime.rb:11:undefinedmethod`get_uptime'forFacter::Util::Uptime:Module(NoMethodError)from/usr/lib/ruby
关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t