首先保证 zookeeper 集群的正常部署,并启动之。
[fickler@hadoop102 zookeeper-3.5.7]$ bin/zkServer.sh start
[fickler@hadoop103 zookeeper-3.5.7]$ bin/zkServer.sh start
[fickler@hadoop104 zookeeper-3.5.7]$ bin/zkServer.sh start
Hadoop 集群的正常部署并启动
[fickler@hadoop102 hadoop-3.1.3]$ sbin/start-dfs.sh
[fickler@hadoop103 hadoop-3.1.3]$ sbin/start-yarn.sh
[fickler@hadoop102 software]$ tar -zxvf hbase-2.4.11-bin.tar.gz -C /opt/module/
[fickler@hadoop102 module]$ mv /opt/module/hbase-2.4.11 /opt/module/hbase
[fickler@hadoop102 hbase]$ sudo vim /etc/profile.d/my_env.sh
添加
#HBASE_HOME
export HBASE_HOME=/opt/module/hbase
export PATH=$PATH:$HBASE_HOME/bin
[fickler@hadoop102 hbase]$ source /etc/profile.d/my_env.sh
export HBASE_MANAGES_ZK=false
<configuration>
<property>
<name>hbase.zookeeper.quorumname>
<value>hadoop102,hadoop103,hadoop104value>
<description>The directory shared by RegionServers.
description>
property>
<property>
<name>hbase.rootdirname>
<value>hdfs://hadoop102:8020/hbasevalue>
<description>The directory shared by RegionServers.
description>
property>
<property>
<name>hbase.cluster.distributedname>
<value>truevalue>
property>
configuration>
hadoop102
hadoop103
hadoop104
mv /opt/module/hbase/lib/client-facing-thirdparty/slf4j-reload4j-1.7.33.jar /opt/module/hbase/lib/client-facing-thirdparty/slf4j-reload4j-1.7.33.jar.bak
[fickler@hadoop102 module]$ xsync hbase/
[fickler@hadoop102 hbase]$ bin/hbase-daemon.sh start master
[fickler@hadoop102 hbase]$ bin/hbase-daemon.sh start regionserver
[fickler@hadoop102 hbase]$ bin/start-hbase.sh
[fickler@hadoop102 hbase]$ bin/stop-hbase.sh
启动成功后,可以通过 “host:port” 的方式来访问 HBase 管理页面:
http://hadoop102:16010/master-status

[fickler@hadoop102 hbase]$ bin/hbase shell
HBase Shell
Use "help" to get list of supported commands.
Use "exit" to quit this interactive shell.
For Reference, please visit: http://hbase.apache.org/2.0/book.html#shell
Version 2.4.11, r7e672a0da0586e6b7449310815182695bc6ae193, Tue Mar 15 10:31:00 PDT 2022
Took 0.0012 seconds
hbase:001:0> help

hbase:003:0> help 'create_namespace'
Create namespace; pass namespace name,
and optionally a dictionary of namespace configuration.
Examples:
hbase> create_namespace 'ns1'
hbase> create_namespace 'ns1', {'PROPERTY_NAME'=>'PROPERTY_VALUE'}
hbase:004:0> create_namespace 'bigdata'
Took 0.4769 seconds
hbase:005:0> list_namespace
NAMESPACE
bigdata
default
hbase
3 row(s)
Took 0.0385 seconds
hbase:006:0> create 'bigdata:student',{NAME => 'info', VERSIONS => 5},{NAME => 'msg'}
Created table bigdata:student
Took 0.6619 seconds
=> Hbase::Table - bigdata:student
如果创建表格只有一个列族,没有列族属性,可以简写。
如果不写命令空间,使用默认的命名空间 default。
hbase:009:0> create 'student1','info'
hbase:007:0> list
TABLE
bigdata:student
1 row(s)
Took 0.0204 seconds
=> ["bigdata:student"]
describe:查看一个表的详情
hbase:009:0> describe 'bigdata:student'
Table bigdata:student is ENABLED
bigdata:student
COLUMN FAMILIES DESCRIPTION
{NAME => 'info', BLOOMFILTER => 'ROW', IN_MEMORY => 'false', VERSIONS => '5', KEEP_DELETED_CELLS => 'FALSE',
DATA_BLOCK_ENCODING => 'NONE', COMPRESSION => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', BLOCKCACHE =>
'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}
{NAME => 'msg', BLOOMFILTER => 'ROW', IN_MEMORY => 'false', VERSIONS => '1', KEEP_DELETED_CELLS => 'FALSE',
DATA_BLOCK_ENCODING => 'NONE', COMPRESSION => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', BLOCKCACHE => '
true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}
2 row(s)
Quota is disabled
Took 0.0627 seconds
hbase:011:0> alter 'bigdata:student', {NAME => 'f1', VERSIONS => 3}
Updating all regions with the new schema...
1/1 regions updated.
Done.
Took 1.6905 seconds
(2)删除信息使用特殊的语法
hbase:012:0> alter 'bigdata:student', NAME => 'f1', METHOD => 'delete'
Updating all regions with the new schema...
1/1 regions updated.
Done.
Took 1.6771 seconds
hbase:013:0> alter 'bigdata:student', 'delete' => 'f1'
Updating all regions with the new schema...
1/1 regions updated.
Done.
Took 1.6505 seconds
hbase:014:0> disable 'bigdata:student'
Took 0.3361 seconds
hbase:015:0> drop 'bigdata:student'
Took 0.3525 seconds
hbase:021:0> put 'bigdata:student1','1001','info:name','zhangsan'
Took 0.0295 seconds
hbase:022:0> put 'bigdata:student1','1001','info:name','lisi'
Took 0.0060 seconds
hbase:023:0> put 'bigdata:student1','1001','info:age','18'
Took 0.0051 seconds
如果重复写入相同 rowKey,相同列的数据,会写入多个版本进行覆盖。
hbase:025:0> get 'bigdata:student1','1001'
COLUMN CELL
info:age timestamp=2022-10-24T16:35:09.847, value=18
info:name timestamp=2022-10-24T16:34:59.769, value=lisi
1 row(s)
Took 0.0389 seconds
也可以修改读取 cell 的版本数,默认读取一个,最多能读取当前列族设置的维护版本数。
hbase:026:0> get 'bigdata:student1','1001',{COLUMN => 'info:name',VERSIONS => 6}
COLUMN CELL
info:name timestamp=2022-10-24T16:34:59.769, value=lisi
info:name timestamp=2022-10-24T16:34:49.077, value=zhangsan
1 row(s)
Took 0.0136 second
scan 是扫描数据,能读取多行数据,不建议扫描过多的数据,推荐使用 startRow 和 stopRow 来控制读取的数据,默认范围左闭右开。
hbase:027:0> scan 'bigdata:student1',{STARTROW => '1001',STOPROW => '1002'}
ROW COLUMN+CELL
1001 column=info:age, timestamp=2022-10-24T16:35:09.847, value=18
1001 column=info:name, timestamp=2022-10-24T16:34:59.769, value=lisi
1 row(s)
Took 0.0156 seconds
hbase:028:0> delete 'bigdata:student1','1001','info:name'
Took 0.0081 seconds
deleteall 表示删除所有版本的数据,即为当前行当前列的多个 cell。(执行命令会标记数据为要删除,不会直接将数据彻底删除,删除数据只在特定时期清理磁盘时进行)
hbase:029:0> deleteall 'bigdata:student1','1001','info:name'
Took 0.0052 seconds