hbase-env.sh
export JAVA_HOME=/opt/modules/jdk1.7.0_79
export HBASE_MANAGES_ZK=false
这里我关闭HBase自带的zk,使用自己配置好的zookeeper
hbase-site.xml
hbase.rootdir
hdfs://cdaisuke:8020/hbase
hbase.cluster.distributed
true
hbase.zookeeper.quorum
cdaisuke,slave01,slave02
hbase.rootdir配置web访问页面,这里路径中的主机名写成你选为master的主机,端口号默认8020
hbase.zookeeper.quorum将所有zookeeper集群中的主机加入
regionservers
regionserver服务器名称
集群内机器名全写入
启动服务
先启动hadoop
再启动ZK
启动master
$ bin/hbase-daemon.sh start master
所有region启动
$ bin/hbase-daemon.sh start regionserver
可以通过master主机名:60010端口的形式访问HBasemaster控制台
jps查看服务启动情况
[hadoop@cdaisuke hbase-0.98.6-hadoop2]$ jps
6145 JobHistoryServer
97292 HRegionServer
5452 NameNode
97985 HMaster
77100 QuorumPeerMain
5924 NodeManager
98113 Jps
5577 DataNode
--------------------------------
[hadoop@slave01 hbase-0.98.6-hadoop2]$ jps
5098 NameNode
5192 DataNode
5526 ResourceManager
64286 QuorumPeerMain
82923 HRegionServer
83216 Jps
5338 NodeManager
--------------------------------
[hadoop@slave02 hbase-0.98.6-hadoop2]$ jps
5244 NodeManager
82179 HRegionServer
64137 QuorumPeerMain
82732 Jps
5127 DataNode
启动hbase shell服务
$ bin/hbase shell
ctrl+backspace是命令行删除键
显示当前有哪些数据表
hbase(main):001:0> list
创建表(表名、列簇名)
hbase(main):002:0> create 'emp','info'
插入记录
=> Hbase::Table - emp
hbase(main):003:0> put 'emp','10001','info:name','zhangsan'
0 row(s) in 0.2700 seconds
hbase(main):005:0> put 'emp','10001','info:age','25'
0 row(s) in 0.0090 seconds
查看表内容
hbase(main):007:0> scan 'emp'
ROW COLUMN+CELL
10001 column=info:age\x0A, timestamp=1535366074361, value=
25
10001 column=info:name, timestamp=1535365976485, value=zha
ngsan
1 row(s) in 0.0580 seconds
更新表数据
hbase(main):008:0> put 'emp','10001','info:name','lisi'
0 row(s) in 0.0110 seconds
查看表结构
hbase(main):011:0> describe 'emp'
DESCRIPTION ENABLED
'emp', {NAME => 'info', DATA_BLOCK_ENCODING = true
> 'NONE', BLOOMFILTER => 'ROW', REPLICATION_S
COPE => '0', VERSIONS => '1', COMPRESSION =>
'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER'
, KEEP_DELETED_CELLS => 'false', BLOCKSIZE =>
'65536', IN_MEMORY => 'false', BLOCKCACHE =>
'true'}
1 row(s) in 0.0360 seconds
查看指定数据
hbase(main):043:0> get 'emp','10001'
COLUMN CELL
info:age timestamp=1535368050074, value=25
info:name timestamp=1535368025465, value=zhangsan
2 row(s) in 0.0100 seconds
删除数据
hbase(main):044:0> delete 'emp','10001','info:age'
0 row(s) in 0.0130 seconds
hbase(main):045:0> get 'emp','10001'
COLUMN CELL
info:name timestamp=1535368025465, value=zhangsan
1 row(s) in 0.0090 seconds
----------------------------------------------
hbase(main):051:0> deleteall 'emp','10001'
0 row(s) in 0.0140 seconds
hbase(main):052:0> scan 'emp'
ROW COLUMN+CELL
10002 column=info:name, timestamp=1535367518087, value=kam
iya
1 row(s) in 0.0120 seconds
清空表
hbase(main):053:0> truncate 'emp'
Truncating 'emp' table (it may take a while):
- Disabling table...
- Dropping table...
- Creating table...
0 row(s) in 1.5830 seconds
hbase(main):054:0> scan 'emp'
ROW COLUMN+CELL
0 row(s) in 0.0220 seconds
删除表
hbase(main):055:0> disable 'emp'
0 row(s) in 1.3530 seconds
hbase(main):057:0> drop 'emp'
0 row(s) in 0.1750 seconds
hbase(main):058:0> list
TABLE
0 row(s) in 0.0130 seconds
=> []
先disable再drop
统计有多少行数据
hbase(main):067:0> count 'user'
1 row(s) in 0.0180 seconds
=> 1
退出
hbase(main):087:0> exit
----
插入
----
create 'user','info'
put 'user','001','info:name','kamiya'
put 'user','001','info:age','43'
put 'user','001','info:sex','male'
put 'user','002','info:name','daisuke'
put 'user','002','info:age','40'
put 'user','002','info:sex','male'
put 'user','003','info:name','caiwenqi'
put 'user','003','info:age','21'
put 'user','003','info:sex','female'
----
统计
----
hbase(main):080:0> count 'user'
3 row(s) in 0.0110 seconds
=> 3
----
查找(STARTROW和STOPROW必须大写)
----
规定起始
scan 'user',{STARTROW=>'002'}
hbase(main):083:0> scan 'user',{STARTROW=>'002'}
ROW COLUMN+CELL
002 column=info:age, timestamp=1535369285786, value=40
002 column=info:name, timestamp=1535369282839, value=dai
suke
002 column=info:sex, timestamp=1535369288278, value=male
003 column=info:age, timestamp=1535369606902, value=21
003 column=info:name, timestamp=1535369615383, value=cai
wenqi
003 column=info:sex, timestamp=1535369610193, value=fema
le
2 row(s) in 0.0260 seconds
---------------------------
包头不包尾
scan 'user',{STARTROW=>'001',STOPROW=>'003'}
hbase(main):086:0> scan 'user',{STARTROW=>'001',STOPROW=>'003'}
ROW COLUMN+CELL
001 column=info:age, timestamp=1535369190114, value=43
001 column=info:name, timestamp=1535369160218, value=kam
iya
001 column=info:sex, timestamp=1535369225444, value=male
002 column=info:age, timestamp=1535369285786, value=40
002 column=info:name, timestamp=1535369282839, value=dai
suke
002 column=info:sex, timestamp=1535369288278, value=male
2 row(s) in 0.0170 seconds