python thrift hbase安装连接

作者: ximengchj 2017-02-22 09:31:52

默认已装好


1.hbase,我的版本是hbase-0.98.24,并运行


2.python 2.7.x


 


步骤:


1.sudo apt-get install automake bison flex g++ git libboost-all-dev libevent-dev libssl-dev libtool make pkg-config,安装这些必要的包和库,官网的是libboost1.55-all-dev,但是我是用的是ubuntu16.04 LTS好像没这么低的版本,所以使用了libboost-all-dev替代


2.安装boost_1_60_0.tar.gz,这一步要好长时间


wget http://sourceforge.net/projects/boost/files/boost/1.60.0/boost_1_60_0.tar.gz


tar xvf boost_1_60_0.tar.gz


cd boost_1_60_0


./bootstrap.sh


sudo ./b2 install


3.下载thrift,


download 地址:http://www.apache.org/dyn/closer.cgi?path=/thrift/0.10.0/thrift-0.10.0.tar.gz


tar thrift-0.10.0.tar.gz


cd thrift-0.10.0.tar.gz


./configure && make


sudo make install


4.检验thrift安装


root@ubuntu:/home/wasdns/thrift# thrift -version


Thrift version 1.0.0-dev


如果出错参考:http://www.linuxdiyf.com/linux/27018.html


一般我们在Linux下执行某些外部程序的时候可能会提示找不到共享库的错误, 比如:


tmux: error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory


原因一般有两个, 一个是操作系统里确实没有包含该共享库(lib.so.文件)或者共享库版本不对, 遇到这种情况那就去网上下载并安装上即可.


另外一个原因就是已经安装了该共享库, 但执行需要调用该共享库的程序的时候, 程序按照默认共享库路径找不到该共享库文件.


root@ubuntu:/home/wasdns/thrift# cat /etc/ld.so.conf


include /etc/ld.so.conf.d/*.conf


root@ubuntu:/home/wasdns/thrift# echo "/usr/local/lib" >> /etc/ld.so.conf


root@ubuntu:/home/wasdns/thrift# cat /etc/ld.so.conf


include /etc/ld.so.conf.d/*.conf


/usr/local/lib


root@ubuntu:/home/wasdns/thrift# ldconfig


root@ubuntu:/home/wasdns/thrift# thrift -version


Thrift version 1.0.0-dev


 


5.安装完成后到hbase的目录下,找到Hbase.thrift,该文件一般在hbase目录下的src/main/resources/org/apache/hadoop/hbase/thrift。如果没有,那么下载响应的源码安装包,把其中的hbase-thrift目录下的src复制到hbase目录下。


thrift --gen python hbase.thrift 会生成gen-py文件夹,将其修改成hbase


sudo pip install thrift 安装python的thrift库


bin/hbase-daemon.sh start thrift 启动hbase的thrift服务,默认端口是9090


创建hbase表


from thrift import Thrift


from thrift.transport import TSocket


from thrift.transport import TTransport


from thrift.protocol import TBinaryProtocol


from hbase import Hbase


from hbase.ttypes import *


transport = TSocket.TSocket('localhost', 9090);


transport = TTransport.TBufferedTransport(transport)


protocol = TBinaryProtocol.TBinaryProtocol(transport);


client = Hbase.Client(protocol)


transport.open()


contents = ColumnDescriptor(name='cf:', maxVersions=1)


client.createTable('test', [contents])


print client.getTableNames()


执行代码,成功后,进入hbase的shell,用命令list可以看到刚刚的test表已经创建成功。


 


本文永久更新地址:http://www.linuxdiyf.com/linux/28591.html

相关资讯