hbase安装
0. 简介
HBase是一个分布式的、面向列的开源数据库,源于google的一篇论文《bigtable:一个结构化数据的分布式存储系统》。HBase是Google Bigtable的开源实现,它利用Hadoop HDFS作为其文件存储系统,利用Hadoop MapReduce来处理HBase中的海量数据,利用Zookeeper作为协同服务。
hbase安装相对简单,就是把其整合hadoop
1.解压
tar -zxvf hbase-1.0.0-bin.tar.gz
sudo mv hbase-1.0.0 /opt/hbase
cd /opt
sudo chmod -R 775 hbase
sudo chown -R coco:coco: hbase
2.修改环境变量
sudo vim /opt/hbase/conf/hbase-env.sh
修改$JAVA_HOME为jdk安装目录
3.修改hbase-site.xml
添加:
<configuration>
<property>
<name>hbase.rootdir</name>
<value>hdfs://localhost:9000/hbase</value>
</property>
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
</configuration>
4.启动hbase
start-hbase.sh
5.进入hbase shell
hbase shell
6.查看进程
通过jps,应该会看到一共有9个进程,分别如下:
3616 NodeManager
3008 NameNode
6945 HQuorumPeer
7010 HMaster
3302 SecondaryNameNode
3128 DataNode
7128 HRegionServer
3496 ResourceManager
7209 Jps
进程号不一定是这些
如果在启动后用list命令出现错误:ERROR: Can't get master address from ZooKeeper; znode data == null
请一定要记得hadoop的服务是否已经启动了,所以一定要先启动hadoop服务,才能启动HBASE。
7. HBase shell的基本用法
hbase提供了一个shell的终端给用户交互。通过执行 help get 可以看到命令的帮助信息。
(1) 建立一个表格scores 具有两个列族grad 和courese
hbase(main):001:0> create'scores','grade', 'course'
0 row(s) in 0.4780 seconds
(2) 查看当前HBase中具有哪些表
hbase(main):002:0> list
TABLE
scores
1 row(s) in 0.0270 seconds
(3) 查看表的构造
hbase(main):004:0> describe'scores'
DESCRIPTION ENABLED
{NAME => 'scores', FAMILIES => [{NAME =>'course', BLOOMFILTER => 'NONE', REPLICATION_SCOPE =>'0', true
COMPRESSION => 'NONE', VERSIONS =>'3', TTL => '2147483647', BLOCKSIZE =>'65536', IN_MEMORY => 'fal
se', BLOCKCACHE => 'true'}, {NAME => 'grade', BLOOMFILTER => 'NONE', REPLICATION_SCOPE => '0', COMPR
ESSION => 'NONE', VERSIONS => '3', TTL => '2147483647', BLOCKSIZE =>'65536', IN_MEMORY => 'false',
BLOCKCACHE => 'true'}]}
1 row(s) in 0.0390 seconds
(4) 加入一行数据,行名称为zkb 列族grad的列名为”” 值位5
hbase(main):006:0> put'scores','zkb','grade:','5'
0 row(s) in 0.0420 seconds
(5) 给zkb这一行的数据的列族course添加一列<math,97>
hbase(main):007:0> put'scores','zkb','course:math','97'
0 row(s) in 0.0270 seconds
(6) 给zkb这一行的数据的列族course添加一列<art,87>
hbase(main):008:0> put'scores','zkb','course:art','87'
0 row(s) in 0.0260 seconds
(7) 加入一行数据,行名称为baoniu 列族grad的列名为”” 值为4
hbase(main):009:0> put'scores','baoniu','grade:','4'
0 row(s) in 0.0260 seconds
(8) 给baoniu这一行的数据的列族course添加一列<math,89>
hbase(main):010:0> put'scores','baoniu','course:math','89'
0 row(s) in 0.0270 seconds
(9) 给Jerry这一行的数据的列族course添加一列<art,80>
hbase(main):011:0> put'scores','baoniu','course:art','80'
0 row(s) in 0.0270 seconds
(10) 查看scores表中zkb的相关数据
hbase(main):012:0> get'scores','zkb'
COLUMN CELL
course:art timestamp=1316100110921, value=87
course:math timestamp=1316100025944, value=97
grade: timestamp=1316099975625, value=5
3 row(s) in 0.0480 seconds
(11) 查看scores表中所有数据
注意:scan命令可以指定startrow,stoprow来scan多个row,例如:scan 'user_test',{COLUMNS =>'info:username',LIMIT =>10, STARTROW => 'test',STOPROW=>'test2'}
hbase(main):013:0> scan'scores'
ROW COLUMN+CELL
baoniu column=course:art, timestamp=1316100293784, value=80
baoniu column=course:math, timestamp=1316100234410, value=89
baoniu column=grade:, timestamp=1316100178609, value=4
zkb column=course:art, timestamp=1316100110921, value=87
zkb column=course:math, timestamp=1316100025944, value=97
zkb column=grade:, timestamp=1316099975625, value=5
2 row(s) in 0.0470 seconds
(12) 查看scores表中所有数据courses列族的所有数据
hbase(main):017:0> scan'scores',{COLUMNS => 'course'}
ROW COLUMN+CELL
baoniu column=course:art, timestamp=1316100293784, value=80
baoniu column=course:math, timestamp=1316100234410, value=89
zkb column=course:art, timestamp=1316100110921, value=87
zkb column=course:math, timestamp=1316100025944, value=97
2 row(s) in 0.0350 seconds
(13) 删除scores表
hbase(main):024:0> disable'scores'
0 row(s) in 0.0330 seconds
hbase(main):025:0> drop'scores'
0 row(s) in 1.0840 seconds
总结下,hbase shell常用的操作命令有create,describe,disable,drop,list,scan,put,get,delete,deleteall,count,status等,通过help可以看到详细的用法。
转载于:https://www.cnblogs.com/PursuitOnly/p/5010352.html