在Azure HDInsight HBase集群中使用Thrift接口

Sun wei  Wed, Feb 25 2015 2:17 AM

Apache Thrift 是一种可扩展的跨语言服务接口,可以通过内置的代码生成引擎帮助创建跨语言服务类库,Apache HBase 也是通过Thrift sever与Python,Ruby等其他程序开发语言进行交互。但是默认情况下Thrift Server默认不是启动的,需要手工处理一下。在Azure HDInight HBase中这种处理的方式有2种,我们可以根据使用场景来进行配置。

第一种方法相对简单,我们可以通过RDP远程连接到HeadNode0上,通过命令行hbase thrift2 start的方法启动thrift server进程。这种方法很简单,但是并不能能满足高可用的要求,只能用于开发测试环境。

第二种方法会复杂很多,但是可以提供生产级别的可用性,可扩展性要求。

  • 创建2个Linux VM并将Azure HDInsight HBase集群部署到相同的虚拟网络上
  • 在VM中设置$JAVA_HOME
  • 在VM中配置repositories wget -nv https://public-repo-1.hortonworks.com/HDP/centos6/2.x/GA/2.2.0.0/hdp.repo -O /etc/yum.repos.d/hdp.repo
  • 在VM中安装HBase sudo yum install hbase
  • 在VM中修改hbase-site.xml,主要是提供zookeeper的地址,可以通过DNS或者host文件的方法提供这些zookeeper及workernode的名字解析,zookeeper以及workernode的名称可以通过Ambari API得到

 <configuration>
   <property>
     <name>hbase.cluster.distributed</name>
     <value>true</value>
   </property>
   <property>
     <name>hbase.zookeeper.quorum</name>
     <value>zookeeper0.hbase.hdicluster.local,zookeeper1.hbase.hdicluster.local,zookeeper2.hbase.hdicluster.local</value>
   </property>
   <property>
     <name>hbase.zookeeper.property.clientPort</name>
     <value>2181</value>
   </property>
 </configuration>

  • 配置服务进程,我们需要在/etc/init.d目录下添加一个名称为hbase-thrift2的服务启动脚本

#!/bin/sh

#
chkconfig :2345 90 60

#
description : hbase thrift gateway service, port 9090

./etc/init.d/functions

FriendlyName="HBase Thrift Gataway"

RETVAL=0

start()

{

echo
-n $"Starting $FriendlyName:"

/usr/hdp/2.2.0.0-2041/hbase/bin/hbase-daemon.sh thrift2 -threadpool &

}

stop()

{

echo
-n $"Stopping $FriendlyName"

/usr/hdp/2.2.0.0-2041/hbase/bin/hbase-daemon.sh stop thrift2

RETVAL=$?

echo

return
$RETVAL

}

case
"$1" in

start)

start

;;

stop)

stop

;;

restart)

stop

start

;;

*)

echo
$"Usage $0 {start|stop|restart}

RETVAL=1

esac

exit
$RETVAL

 

  • 更改脚本的执行权限

sudo chmod +x hbase-thrift2

  • 将服务设置为自动启动

sudo chkconfig --add hbase-thrift2

sudo chkconfig hbase-thrift2 on

  • 将2个VM放置于同一个高可用集中
  • 通过Internal Loadbalancer为这2个VM提供负载均衡,同时也兼具HA的功能

Add-AzureInternalLoadBalancer-ServiceName$svcName-InternalLoadBalancerName$ilb-SubnetName$subnet

$prot="tcp"
$locport=9090
$pubport=9090
$epname="Thrift2"
$vmname01 = "hbthrift01"
$vmname02 = "hbthrift02"
$lbsetname="HBThriftLBSet"

Get-AzureVM -ServiceName$svcName-Name$vmname01|Add-AzureEndpoint-LBSetName$lbsetname-Name$epname-Protocol$prot-LocalPort$locport-PublicPort$pubport-ProbePort$locport-ProbeProtocol$prot-InternalLoadBalancerName$ilb|Update-AzureVM

Get-AzureVM -ServiceName$svcName-Name$vmname02|Add-AzureEndpoint-LBSetName$lbsetname-Name$epname-Protocol$prot-LocalPort$locport-PublicPort$pubport-ProbePort$locport-ProbeProtocol$prot-InternalLoadBalancerName$ilb|Update-AzureVM

通过这些步骤你的Thrift sever就可以工作了,enjoy

如果你有任何疑问,欢迎访问MSDN社区,由专家来为您解答Windows Azure各种技术问题,或者拨打世纪互联客户服务热线400-089-0365/010-84563652咨询各类服务信息。

本文转载自: https://blogs.msdn.com/b/cciccat/archive/2015/02/25/azure-hdinsight-hbase-thrift.aspx