zoukankan      html  css  js  c++  java
  • python thrift hbase安装连接

    默认已装好

    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,这一步要好长时间

      1. wget http://sourceforge.net/projects/boost/files/boost/1.60.0/boost_1_60_0.tar.gz
      2. tar xvf boost_1_60_0.tar.gz
      3. cd boost_1_60_0
      4. ./bootstrap.sh
      5. sudo ./b2 install
    3. 下载thrift,

      1. download 地址
      2. tar thrift-0.10.0.tar.gz
      3. cd thrift-0.10.0.tar.gz
      4. ./configure && make
      5. sudo make install
    4. 检验thrift安装

      root@ubuntu:/home/wasdns/thrift# thrift -version
      Thrift version 1.0.0-dev
      

      如果出错参考 http://www.cnblogs.com/qq952693358/p/6193842.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目录下。

      1. thrift --gen py Hbase.thrift 会生成gen-py文件夹,将其修改成hbase
      2. sudo pip install thrift 安装python的thrift库
      3. bin/hbase-daemon.sh start thrift 启动hbase的thrift服务,默认端口是9090
      4. 创建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表已经创建成功。
  • 相关阅读:
    js对象写法
    IE6双边距bug及其解决办法
    图片轮播
    盒子水平和垂直同时居中方法
    选项卡切换
    针对IE6兼容png
    html5兼容
    sublime快捷键总结
    七种设计原则
    Git基本命令
  • 原文地址:https://www.cnblogs.com/ximengchj/p/6423667.html
Copyright © 2011-2022 走看看