操作系统是Ubuntu Server 12.10

先安装Thrift

sudo apt-get install libboost-dev libboost-test-dev \
libboost-program-options-dev libevent-dev automake \
libtool flex bison pkg-config g++ libssl-dev

如果你还要使用别的语言,也需要安装对应的包

  • Ruby

    • ruby-full ruby-dev librspec-ruby rake rubygems libdaemons-ruby libgemplugin-ruby mongrel
  • Python
    • python-dev python-twisted
  • Perl
    • libbit-vector-perl
  • Php, install
    • php5-dev php5-cli
  • C_glib
    • libglib2.0-dev
  • Erlang
    • erlang-base erlang-eunit erlang-dev
  • Csharp
    • mono-gmcs libmono-dev libmono-system-web2.0-cil
  • Haskell
    • ghc6 cabal-install libghc6-binary-dev libghc6-network-dev libghc6-http-dev
cd thrift
./bootstrap.sh
./configure --with-boost=/usr/local
make
make install

安装Hbase

修改源码包中的conf/hbase-site.xml文件。替换成以下内容:


    hbase.rootdir
file:///DIRECTORY/hbase hbase.zookeeper.property.dataDir
/DIRECTORY/zookeeper

替换上文中对应的目录位置 修改conf/hbase-env.sh 添加JAVA_HOME export JAVA_HOME=/usr/local/jdk 启动Hbase

$ ./bin/start-hbase.sh
starting Master, logging to logs/hbase-user-master-example.org.out $ ./bin/hbase shell
HBase Shell; enter 'help' for list of supported commands.
Type "exit" to leave the HBase Shell
Version 0.94.2, r1395367, Sun Oct 7 19:11:01 UTC 2012 hbase(main):001:0> hbase(main):001:0> create 't1','cf'
0 row(s) in 1.6600 seconds hbase(main):002:0> list
TABLE
t1
1 row(s) in 0.0130 seconds
hbase(main):004:0> put 't1', 'row1', 'cf:a', 'value1'
0 row(s) in 0.0330 seconds hbase(main):005:0> put 't1', 'row2', 'cf:a', 'value2'
0 row(s) in 0.0040 seconds hbase(main):006:0> put 't1', 'row3', 'cf:a', 'value3'
0 row(s) in 0.0040 seconds hbase(main):007:0> scan 't1'
ROW COLUMN+CELL
row1 column=cf:a, timestamp=1352453214504, value=value1
row2 column=cf:a, timestamp=1352453236805, value=value2
row3 column=cf:a, timestamp=1352453244172, value=value3
3 row(s) in 0.0320 seconds hbase(main):008:0> get 't1', 'row1'
COLUMN CELL
cf:a timestamp=1352453214504, value=value1
1 row(s) in 0.0120 seconds hbase(main):009:0> disable 't1'
0 row(s) in 2.0510 seconds hbase(main):011:0> drop 't1'
0 row(s) in 1.0480 seconds hbase(main):012:0> exit

如果上述测试脚本都能正常执行,就证明你Hbase安装成功了。 注意,如果你使用ubuntu,当执行命令的时候,提示

ERROR: org.apache.hadoop.hbase.PleaseHoldException: org.apache.hadoop.hbase.PleaseHoldException: Master is initializing

在logs/hbase-*-ubuntu.log中显示类似

Failed setting up proxy interface org.apache.hadoop.hbase.ipc.HRegionInterface to localhost/127.0.0.1:55915 after attempts=1
Caused by: java.net.ConnectException: Connection refused

出现这种情形,请检查/etc/hosts文件,把 127.0.1.1 ubuntu 改成 127.0.0.1 ubuntu 之后重新启动Hbase就可以正常运行了。

通过Thrift操作Hbase

生产Thrift客户端

mkdir ~/thrift
cd ~/thrift
thrift –gen erl [hbase-root]/src/main/resources/org/apache/hadoop/hbase/thrift/Hbase.thrift

启动两个客户端

$ cd ~/hbase
$ ./bin/start-hbase.sh

在另外一个客户端,启动Thrift Server

$ cd ~/hbase
elton@ubuntu:~/hbase$ ./bin/hbase thrift start
1211/09 17:41:33 INFO util.VersionInfo: HBase 0.94.2

1211/09 17:41:35 DEBUG thrift.ThriftServerRunner: Using binary protocol
1211/09 17:41:35 INFO thrift.ThriftServerRunner: starting TBoundedThreadPoolServer on /0.0.0.0:9090; min worker threads=16, max worker threads=1000, max queued requests=1000

之后就可以产生一个gen-erl,进入它,编译其中的Erlang源文件

cd gen-erl
erlc *.erl

在gen-erl目录下,进入erlang shell。

$ erl
Erlang R15B02 (erts-5.9.2) [source] [64-bit] [smp:4:4] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.9.2 (abort with ^G) 1> {ok, Client} = thrift_client_util:new(“127.0.0.1”, 9090, hbase_thrift, []). {ok,{tclient,hbase_thrift, {protocol,thrift_binary_protocol, {binary_protocol, {transport,thrift_buffered_transport, {buffered_transport, {transport,thrift_socket_transport, {data,#Port<0.631>,infinity}}, []}}, true,true}}, 0}}

2> thrift_client:call(Client, getTableNames, []). tclient,hbase_thrift, {protocol,thrift_binary_protocol, {binary_protocol, {transport,thrift_buffered_transport, {buffered_transport, {transport,thrift_socket_transport, {data,#Port<0.631>,infinity}}, []}}, true,true}}, 0}, {ok,[]}}

具体的clinet API可以参见 https://github.com/interline/erlang-thrift

转自: http://blog.prosight.me/blogs/1025/

使用Erlang和Thrift,与Hbase通信(转)的更多相关文章

  1. 使用C#通过Thrift访问HBase

    前言 因为项目需要要为客户程序提供C#.Net的HBase访问接口,而HBase并没有提供原生的.Net客户端接口,可以通过启动HBase的Thrift服务来提供多语言支持. Thrift介绍 环境 ...

  2. PHP通过Thrift操作Hbase

    PHP通过Thrift操作Hbase     HBase是一个开源的NoSQL产品,它是实现了Google BigTable论文的一个开源产品,和Hadoop和HDFS一起,可用来存储和处理海量col ...

  3. Nodejs通过Thrift操作hbase卡住原因分析及与javascript的垃圾回收机制的关系

    在最近使用Nodejs通过Thrift操作hbase的时候写了个脚本,不断发送http请求,从而取得hbase下所需的数据,但是在run的过程中for循环并没有执行完全,在执行一部分后会卡住,就再也进 ...

  4. python Hbase Thrift pycharm 及引入包

    cp -r hbase/ /usr/lib/python2.7/site-packages/ 官方示例子http://code.google.com/p/hbase-thrift/source/bro ...

  5. 使用C#和Thrift来访问Hbase实例

    今天试着用C#和Thrift来访问Hbase,主要参考了博客园上的这篇文章.查了Thrift,Hbase的资料,结合博客园的这篇文章,终于搞好了.期间经历了不少弯路,下面我尽量详细的记录下来,免得大家 ...

  6. python thrift hbase安装连接

    默认已装好 hbase,我的版本是hbase-0.98.24,并运行 python 2.7.x 步骤: sudo apt-get install automake bison flex g++ git ...

  7. Erlang下与其他程序和语言的通信机制(3)

    这部分主要聊C Nodes.首先我们需要了解下Erlang的分布式系统: 分布式Erlang: 分布式Erlang是由一组相互通信的Erlang运行时组成,其中每一个运行时称为一个Node.不同Nod ...

  8. dotnetcore 与 hbase 之二——thrift 客户端的制作

    说明 在上一篇文章dotnetcore 与 hbase 之一--hbase 环境准备结束后,我们已经有了 hbase 数据库环境.接下来就可以利用 thrift 生成 c# hbase 客户端了.如果 ...

  9. 什么是Thrift

    起源 百度百科怎么说 thrift是一个软件框架,用来进行可扩展且跨语言的服务的开发. 它结合了功能强大的软件堆栈和代码生成引擎,以构建在 C++, Java, Python, PHP, Ruby, ...

随机推荐

  1. Spring积累总结

    1.spring 的优点: 1.降低了组件之间的耦合性 ,实现了软件各层之间的解耦 2.可以使用容易提供的众多服务,如事务管理,消息服务等 3.容器提供单例模式支持 4.容器提供了AOP技术,利用它很 ...

  2. Spring Boot学习——统一异常处理

    本随笔记录使用Spring Boot统一处理异常. 本文实例是从数据库中根据ID查询学生信息,要求学生的年龄在14——20岁之间.小于14岁,提示“你可能在上初中”:大于20岁,提示“呢可能在上大学” ...

  3. pyinstaller打包exe程序各种坑!!!

    pyinstaller打包python成exe可执行程序,各种报错,各种坑,在次记录下 一.pyinstaller打包报错for real_module_name, six_moduleAttribu ...

  4. Android 设置图片倒影效果

    首先,贴出效果图: 1.布局文件main.xml <?xml version="1.0" encoding="utf-8"?> <Linear ...

  5. 数据库索引实现原理—B_TREE

    数据库索引,是数据库管理系统中一个排序的数据结构,以协助快速查询.更新数据库表中数据.索引的实现通常使用B_TREE.B_TREE索引加速了数据访问,因为存储引擎不会再去扫描整张表得到需要的数据:相反 ...

  6. [Machine Learning with Python] My First Data Preprocessing Pipeline with Titanic Dataset

    The Dataset was acquired from https://www.kaggle.com/c/titanic For data preprocessing, I firstly def ...

  7. advanced-performance-troubleshooting-waits-latches-spinlocks

    https://www.sqlskills.com/blogs/paul/advanced-performance-troubleshooting-waits-latches-spinlocks/

  8. Mark S. Rasmussen improve.dk-----knife-for-mdf-files

    http://improve.dk/orcamdf-rawdatabase-a-swiss-army-knife-for-mdf-files/ http://www.cnblogs.com/lyhab ...

  9. DB11 TCP数据协议拆包接收主要方法

    北京地标(DB11) 据接收器. /// <summary> /// DB11协议拆包器 /// </summary> public class SplictProtocol ...

  10. 2016.7.14 去掉Mybatis Generator生成的一堆 example

    参考资料: http://www.cnblogs.com/zerocold/p/4220955.html   mybatis generator自动生成的代码里老是有一堆example,需要改的时候, ...