HBase表结构设计--练习篇

本文介绍了HBase表结构的设计及基本操作,包括创建表、查看表结构、数据增删改查等,并记录了实操过程中的常见问题及解决办法。

HBase表结构设计--练习篇

一、表结构操作

1.建立一个表scores,有两个列族grad和course

[hadoop@weekend01 ~]$ hbase shell

hbase(main):006:0> create 'scores','grade','course'

0 row(s) in 0.4120 seconds

=> Hbase::Table - scores

2.查看Hbase中的所有表

hbase(main):007:0> list

TABLE

hbase_student

my_data

new_scores

scores

student

user

6 row(s) in 0.0150 seconds

=> ["hbase_student", "my_data", "new_scores", "scores", "student", "user"]

3.查看scores表结构

hbase(main):008:0> desc 'scores'

Table scores is ENABLED

scores

COLUMN FAMILIES DESCRIPTION

{NAME => 'course', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICAT

ION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', T

TL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY

=> 'false', BLOCKCACHE => 'true'}

{NAME => 'grade', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATI

ON_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TT

L => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY =

> 'false', BLOCKCACHE => 'true'}

2 row(s) in 0.0550 seconds

4.查询表scores是否存在

hbase(main):009:0> exists 'scores'

Table scores does exist

0 row(s) in 0.0180 seconds

5.判断表scores是否enable

hbase(main):010:0> is_enabled 'scores'

true

0 row(s) in 0.0160 seconds

6.判断表scores是否disable

hbase(main):011:0> is_disabled 'scores'

false

0 row(s) in 0.0210 seconds

7.使表scores不可用

hbase(main):012:0> disable 'scores'

0 row(s) in 1.3380 seconds

8.恢复表scores可用

hbase(main):013:0> enable 'scores'

0 row(s) in 0.5680 seconds

9.增加一个school列族

hbase(main):002:0> alter 'scores',{NAME=>'school',VERSIONS=>3}

Updating all regions with the new schema...

0/1 regions updated.

1/1 regions updated.

Done.

0 row(s) in 2.3390 seconds

10.删除一个school列族

hbase(main):005:0> alter 'scores',{NAME=>'school',METHOD=>'delete'}

Updating all regions with the new schema...

0/1 regions updated.

1/1 regions updated.

Done.

0 row(s) in 2.1970 seconds

11.删除表scores

操作步骤:先禁用表,再删除表

hbase(main):004:0> disable 'scores' #先将scores表改为offline状态

0 row(s) in 1.3100 seconds

hbase(main):005:0> drop 'scores' #再删除表

0 row(s) in 0.2250 seconds

二、DML操作(数据操纵)

1.添加scores数据

其scores表数据如下:

Tom grade: 5

Tom course:math 97

Tom course:art 87

Tom course:english 80

Jim grade: 4

Jim course:chinese 89

Jim course:english 80

hbase(main):006:0> put 'scores','Tom','grade:','5'

0 row(s) in 0.1810 seconds

hbase(main):007:0> put 'scores','Tom','course:math','97'

0 row(s) in 0.0200 seconds

hbase(main):009:0> put 'scores','Tom','course:art','87'

0 row(s) in 0.0150 seconds

hbase(main):010:0> put 'scores','Tom','course:english','80'

0 row(s) in 0.0070 seconds

hbase(main):012:0> put 'scores','Jim','grade:','5'

0 row(s) in 0.0080 seconds

hbase(main):013:0> put 'scores','Jim','course:chinese','89'

0 row(s) in 0.0110 seconds

hbase(main):014:0> put 'scores','Jim','course:english','80'

0 row(s) in 0.0070 seconds

2.查看数据

a.全表scores扫描

hbase(main):015:0> scan 'scores'

ROW COLUMN+CELL

Jim column=course:chinese, timestamp=1464871444954, value=89

Jim column=course:english, timestamp=1464871467549, value=80

Jim column=grade:, timestamp=1464871414324, value=5

Tom column=course:art, timestamp=1464871299895, value=87

Tom column=course:english, timestamp=1464871325997, value=80

Tom column=course:math, timestamp=1464871198158, value=97

Tom column=grade:, timestamp=1464871151963, value=5

2 row(s) in 0.1160 secondsb.查看表scores中Jim的一行的数据

c.查看一个单元格的数据

hbase(main):016:0> get 'scores','Tom',{COLUMN=>'course:math'}

COLUMN CELL

course:math timestamp=1464871198158, value=97

1 row(s) in 0.0900 seconds

d.查看一个course列族的数据

hbase(main):017:0> scan 'scores',{COLUMN=>'course'}

ROW COLUMN+CELL

Jim column=course:chinese, timestamp=1464871444954, value=89

Jim column=course:english, timestamp=1464871467549, value=80

Tom column=course:art, timestamp=1464871299895, value=87

Tom column=course:english, timestamp=1464871325997, value=80

Tom column=course:math, timestamp=1464871198158, value=97

2 row(s) in 0.0170 seconds

e.查看表scores中的course:english列的数据

hbase(main):019:0> scan 'scores',{COLUMN=>'course:english'}

ROW COLUMN+CELL

Jim column=course:english, timestamp=1464871467549, value=80

Tom column=course:english, timestamp=1464871325997, value=80

2 row(s) in 0.0260 seconds

f.统计表scores的行数

hbase(main):020:0> count 'scores'

2 row(s) in 0.0890 seconds

=> 2

3.修改数据

a.修改scores表中的Tom的math值为100

hbase(main):021:0> put 'scores','Tom','course:math','100'

0 row(s) in 0.0140 seconds

b.修改scores表中列族course的VERSIONS=>3

hbase(main):022:0> alter 'scores',{NAME=>'course',VERSION=>3}

Unknown argument ignored for column family course: 1.8.7

Updating all regions with the new schema...

0/1 regions updated.

1/1 regions updated.

Done.

0 row(s) in 2.2190 seconds

再进行修改cores表中的Tom的math值为100

hbase(main):023:0> put 'scores','Tom','course:math','100'

0 row(s) in 0.0490 seconds

再按VERSIONS=>3查看该表中course:math的值

hbase(main):025:0> get 'scores','Tom',{COLUMN=>'course:math',VERSIONS=>3}

COLUMN CELL

course:math timestamp=1464872264511, value=100

4.删除数据

a.删除scores表Jim的course:chinese的值

hbase(main):027:0> delete 'scores','Jim','course:chinese'

0 row(s) in 0.0310 seconds

b.删除scores表Tom的course:english的值

hbase(main):029:0> delete 'scores','Tom','course:english'

0 row(s) in 0.0080 seconds

c.删除scores表Tom一行

hbase(main):032:0> deleteall 'scores','Tom'

0 row(s) in 0.4160 seconds

d.清空scores表中的内容

hbase(main):031:0> truncate 'scores'

Truncating 'scores' table (it may take a while):

- Disabling table...

- Truncating table...

0 row(s) in 1.5000 seconds

疑难小结:刚开始玩HBase看着文档还不是那么难,真做起来麻烦事还真多,刚开始一直报这个错,没有头绪,百度半天

hbase(main):001:0> list

TABLE

ERROR: Can't get master address from ZooKeeper; znode data == null

这东西让我改好多文件,还是不行,无奈又重新配置了一遍,同学有遇到一样的情况,说是myid文件与zookeeper配置文件中的指定id不一致导致的但是我检查过了是一样的主机名IP地址id号都是对应的,zookeeper启动正常,进程正常,还有就是HBase进程启动异常,在主节点上启动之后,只有主节点有HMaster进程另外weekend05、06上有HRegionServer进程weekend07上没有,无解了。。。按照步骤重来一遍好了,但还是没有明白哪里出了问题。

posted on 2017-07-27 19:04 Lucky_7 阅读(...) 评论(...) 编辑 收藏

<think>好的,我现在需要处理用户关于在头歌实验3-1中部署HBase的请求。首先,用户提到他们想了解如何在大数据平台上部署HBase的实验指导或教程,特别是头歌实验3-1的相关内容。我需要根据用户提供的引用信息,结合现有的知识,生成一个结构清晰的回答,附带相关问题。 首先,我得确认用户提供的引用内容是否与HBase部署相关。引用[2]提到HDFS和HBase在教育数据存储中的作用,引用[4]则涉及Java大数据工具链的优化,这可能包括HBase。用户需要具体的部署步骤,所以需要整理出部署HBase的常规流程,结合实验环境的特点进行调整。 接下来,我需要考虑如何结构化回答。用户希望步骤清晰,帮助逐步解决问题。通常,HBase的部署依赖于Hadoop和ZooKeeper,因此需要先确认这些前提条件是否满足。然后分步骤安装配置HBase,包括配置文件修改、启动服务、验证等。此外,实验环境中可能需要注意网络配置、权限设置等问题。 然后,我要检查是否有遗漏的步骤或常见的错误点。例如,HBase的配置文件如hbase-site.xml和regionservers的正确配置,环境变量设置,以及如何通过HBase Shell验证安装。同时,可能还需要提到分布式模式与单机模式的区别,特别是在实验环境中可能使用的模式。 还要考虑引用文献的应用。引用[3]提到个性化学习支持,可能实验指导需要包含详细的步骤和问题排查,以帮助学生自主完成实验。引用[4]提到开源社区的工具链完善,可能涉及到使用最新版本的HBase或相关工具。 用户可能遇到的问题包括端口冲突、依赖服务未启动、配置文件错误等,需要在注意事项中提及。此外,实验完成后,建议学生进行基本操作练习,如创建、插入数据等,以巩固理解。 最后,生成的相关问题需要围绕HBase部署的扩展内容,例如与Hadoop集成、性能优化、数据备份等,以及在大数据实验室中的应用场景,结合引用内容中的教育数据存储和分析。 需要确保所有学公式和代码块格式正确,使用中文回答,结构清晰,自然地插入引用标记。同时,避免使用Markdown格式,但根据用户提供的系统级指令,代码块需要用反引号包裹,标明语言。</think>以下是为头歌实验3-1设计HBase部署教程,结合大数据实验室建设需求和教育数据存储技术[^2][^4]: ### 实验3-1 HBase部署教程 #### 一、实验环境准备 1. **基础环境** - 操作系统:Linux(建议CentOS 7+) - 依赖组件:已安装JDK 8+、Hadoop 3.x(需先启动HDFS)[^2] - 网络配置:确保节点间SSH免密登录 2. **组件下载** ```bash wget https://archive.apache.org/dist/hbase/2.4.13/hbase-2.4.13-bin.tar.gz tar -zxvf hbase-2.4.13-bin.tar.gz ``` #### 二、HBase配置 1. **核心配置文件** 修改`conf/hbase-site.xml`: ```xml <configuration> <property> <name>hbase.rootdir</name> <value>hdfs://namenode:9000/hbase</value> </property> <property> <name>hbase.cluster.distributed</name> <value>true</value> </property> <property> <name>hbase.zookeeper.quorum</name> <value>zk-node1,zk-node2,zk-node3</value> </property> </configuration> ``` 2. **节点配置** 编辑`conf/regionservers`添加RegionServer节点: ``` datanode1 datanode2 datanode3 ``` #### 三、服务启动与验证 1. **启动命令** ```bash # 启动HBase(需先启动Hadoop和ZooKeeper) bin/start-hbase.sh # 启动HBase Shell bin/hbase shell ``` 2. **基础操作验证** ```hbase create 'test_table', 'cf' put 'test_table', 'row1', 'cf:value', 'Hello HBase' scan 'test_table' ``` #### 四、实验注意事项 1. 端口冲突检查:HBase Master默认使用16010端口,RegionServer使用16201端口 2. 分布式模式下需确保ZooKeeper集群已正常运行 3. 通过`http://<master-node>:16010`可访问Web UI
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值