hbase rest 访问_Hbase的REST访问

使用hbase REST服务器需要先去服务器上启动服务前台启动hbase rest服务

bin/hbase rest start -p

后台启动hbase服务

bin/hbase-daemon.sh start rest -p

停止服务

bin/hbase-daemon.sh stop rest

不加端口的情况下,端口默认为8080

利用requests模块访问rest接口的python代码如下,其中注释是利用curl命令的访问方式:

baseurl = "http://192.168.119.128:8080";

#获取表table2中rowkey为liu的行

response = requests.get(baseurl+'/table2/liu', headers={"Accept" : "application/json"})

'''

相当于 curl -H "Accept:application/json" http://192.168.119.128:8080/table2/liu

'''

print response.json()

#返回的字段名称和值为base64编码的,需要解密查看

print base64.b64decode(u'bW9ibGllOg==')

#查看集群状态

response = requests.get(baseurl+'/status/cluster', headers={"Accept" : "application/json"})

'''

相当于 curl -H "Accept:application/json" http://192.168.119.128:8080/status/cluster

'''

print response.json()

#查看集群版本

response = requests.get(baseurl+'/version/cluster', headers={"Accept" : "application/json"})

'''

相当于 curl -H "Accept:application/json" http://192.168.119.128:8080/status/cluster

'''

print response.json()

#获得表list

response = requests.get(baseurl+'/', headers={"Accept" : "application/json"})

'''

相当于 curl -H "Accept:application/json" http://192.168.119.128:8080/

'''

print response.json()

#table2中添加一行数据rowkey为moblie,xml字段名称和数据base64编码

rdata='<?xml version="1.0" encoding="UTF-8" standalone="yes"?>bGl1emhvdWxvbmcy'

response = requests.put(baseurl+'/table2/moblie', data=rdata,headers = {'content-type': 'text/xml'})

print response

#curl -vi -X PUT -H "Accept: text/xml" -H "Content-Type: text/xml" -d '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>bGl1emhvdWxvbmcy' "http://192.168.119.128:8080/table2/moblie"

#添加表users

rdata='<?xml version="1.0" encoding="UTF-8"?>'

response = requests.post(baseurl+'/users/schema', data=rdata,headers = {'content-type': 'text/xml'})

print response

#curl -vi -X POST -H "Accept: text/xml" -H "Content-Type: text/xml" -d '<?xml version="1.0" encoding="UTF-8"?>' "http://192.168.119.128:8080/users/schema"

#删除表users

response = requests.delete(baseurl+'/users/schema')

print response

#curl -vi -X DELETE -H "Accept: text/xml" "http://192.168.119.128:8080/users/schema"

更多信息请参考

http://hbase.apache.org/book.html#_rest

扩展curl 参数含义

-X/--request [GET|POST|PUT|DELETE|…]  使用指定的http method發出 http request

-H/--header                           設定request裡的header

-i/--include                          顯示response的header

-d/--data                             設定 http parameters

-v/--verbose                          輸出比較多的訊息

-u/--user                             使用者帳號、密碼

-b/--cookie                           cookie

Hbase的访问方式包括:

1、Native Java API:最常规和高效的访问方式;

2、HBase Shell:HBase的命令行工具,最简单的接口,适合HBase管理使用;

3、Thrift Gateway:利用Thrift序列化技术,支持C++,PHP,Python等多种语言,适合其他异构系统在线访问HBase表数据;

4、REST Gateway:支持REST 风格的Http API访问HBase, 解除了语言限制;

5、MapReduce:直接使用MapReduce作业处理Hbase数据;

6、使用Pig/hive处理Hbase数据。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值