使用Python访问Phoenix

本文详细介绍了如何进行需求分析,包括Phoenix的原理和应用,Thrift的操作,以及Python如何连接和操作HBase。涉及实验流程,如开启HBase、ZooKeeper和Hadoop集群,创建Phoenix表,Python编程访问HBase等步骤。
摘要由CSDN通过智能技术生成

需求分析

理解Phoenix的原理及应用场景,理解Thrift的原理及操作,掌握Python如何访问操作HBase。

系统实现

实验流程分析:

开启HBase集群

在Phoenix上创建表

启动Thrift服务

实现Python访问HBase

关闭启动的服务

开启HBase集群:

开启ZooKeeper集群

 在master,slave1和slave2上分别打开Zookeeper集群

 查看Zookeeper的运行状态

开启Hadoop集群

 在master上开启Hadoop集群

启动HBase集群

 在master上启动HBase集群

在Phoenix上创建表:

启动Phoenix服务

执行!table指令,出现如下的表

创建Phoenix表

创建一个Phoenix表,表名为population,具体指令如下:

create table if not exists population(
state char(2) not null,
city varchar not null,
population bigint constraint my_pk primary key(state,city)
);                               

向表中插入数据

向population表插入数据,具体指令如下:

查询表中插入数据

使用seletc命令查询population表中数据

数据如下

启动Thrift服务:

启动HBase Thrift服务

在master服务器启动Thrift服务,具体指令如下:

进入HBase Shell客户端

在任意一台服务器上进入HBase Shell客户端,具体指令如下:

查看HBase表

表中数据如下

实现Python访问HBase:

编写Python程序

在master服务器输入以下指令,打开文件

输入以下代码

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('master', 9090)
transport = TTransport.TBufferedTransport(transport)
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = Hbase.Client(protocol)
transport.open()
result = client.getRow('POPULATION','CALos Angeles')
print(result)

运行Python程序

输入以下指令运行程序

结果如下

关闭启动的服务

关闭Thrift服务

在master上输入下图指令

退出Phoenix服务

在master的第一个终端退出Poenix服务

关闭HBase集群

在master上关闭HBase集群

关闭Hadoop集群

在master上关闭Hadoop集群

关闭ZooKeeper集群

在三个服务器上都关闭ZooKeeper集群

  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值