一、准备
hbase 与 hadoop 对应版本:
https://hbase.apache.org/book.html#basic.prerequisites
1.下载安装 jdk-8u341-linux-x64.tar.gz
2.下载安装 hadoop-2.10.2.tar.gz
3.下载 hbase-2.4.17-bin.tar.gz
二、安装 hbase
1.解压
把 hbase-2.4.17-bin.tar.gz 解压到 /opt/ 目录下
tar -xf hbase-2.4.17-bin.tar.gz -C /opt/
2.修改配置文件
修改 hbase-env.sh
export JAVA_HOME=/opt/jdk1.8.0_341/
export HBASE_CLASSPATH=/opt/hadoop-2.10.2/etc/hadoop/
export HBASE_MANAGES_ZK=true
修改 hbase-site.xml
hbase.rootdir 的值与 hadoop 配置文件 core-site.xml 中的 fs.default.name 保持一致,然后再加上 /hbase
<configuration>
<property>
<name>hbase.rootdir</name>
<value>hdfs://node0001:9000/hbase</value>
</property>
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
</configuration>
三、启动 hbase
1.启动 hadoop
root@node0001:/opt/hadoop-2.10.2# ./sbin/start-dfs.sh
Starting namenodes on [node0001]
node0001: starting namenode, logging to /opt/hadoop-2.10.2/logs/hadoop-root-namenode-node0001.out
node0001: starting datanode, logging to /opt/hadoop-2.10.2/logs/hadoop-root-datanode-node0001.out
Starting secondary namenodes [node0001]
node0001: starting secondarynamenode, logging to /opt/hadoop-2.10.2/logs/hadoop-root-secondarynamenode-node0001.out
使用 jps 查看启动的进程
root@node0001:/opt/jdk1.8.0_341/bin# ./jps
10050 NameNode
10183 DataNode
10362 SecondaryNameNode
10494 Jps
2.启动 hive
root@node0001:/opt/hbase-2.4.17# bin/start-hbase.sh
127.0.0.1: running zookeeper, logging to /opt/hbase-2.4.17/bin/../logs/hbase-root-zookeeper-node0001.out
running master, logging to /opt/hbase-2.4.17/bin/../logs/hbase--master-node0001.out
: running regionserver, logging to /opt/hbase-2.4.17/bin/../logs/hbase--regionserver-node0001.out
使用 jps 查看启动的进程
root@node0001:/opt/jdk1.8.0_341/bin# ./jps
10050 NameNode
10930 HMaster
11076 HRegionServer
10183 DataNode
10792 HQuorumPeer
11370 Jps
10362 SecondaryNameNode
四、使用 hbase
- 创表:
create 'table', 'column_family_1','column_family_2','column_family_3'...
- 关闭中:
disable 'table'
- 使用中:
enable 'table'
,表创建成功后,默认状态是 enable - 删除表:
drop 'table'
,删除表之前需先设置表为“关闭中 - 查看所有表:
list
- 查看表结构:
describe 'table'
- 插入与更新数据:
put 'table', 'row key', 'column_family:column', 'value'
root@node0001:/opt/hbase-2.4.17# ./bin/hbase shell
2023-10-26 21:08:29,669 WARN [main] util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
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.17, r7fd096f39b4284da9a71da3ce67c48d259ffa79a, Fri Mar 31 18:10:45 UTC 2023
Took 0.0010 seconds
hbase:001:0> create 'hbase_test','column_family_1', 'column_family_2', 'column_family_3'
Created table hbase_test
Took 0.9141 seconds
=> Hbase::Table - hbase_test
hbase:002:0> list
TABLE
hbase_test
1 row(s)
Took 0.0206 seconds
=> ["hbase_test"]
hbase:003:0> describe 'hbase_test'
Table hbase_test is ENABLED
hbase_test
COLUMN FAMILIES DESCRIPTION
{NAME => 'column_family_1', 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'}
{NAME => 'column_family_2', 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'}
{NAME => 'column_family_3', 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'}
3 row(s)
Quota is disabled
Took 0.0909 seconds
hbase:004:0> put 'hbase_test','key_1','column_family_1:column_1','value1'
Took 0.0637 seconds
hbase:005:0> put 'hbase_test','key_1','column_family_1:column_2','value2'
Took 0.0040 seconds
hbase:006:0> get 'hbase_test','key_1'
COLUMN CELL
column_family_1:column_1 timestamp=2023-10-26T21:09:12.926, value=value1
column_family_1:column_2 timestamp=2023-10-26T21:09:25.516, value=value2
1 row(s)
Took 0.0235 seconds
hbase:007:0> scan 'hbase_test'
ROW COLUMN+CELL
key_1 column=column_family_1:column_1, timestamp=2023-10-26T21:09:12.926, value=value1
key_1 column=column_family_1:column_2, timestamp=2023-10-26T21:09:25.516, value=value2
1 row(s)
Took 0.0076 seconds
hbase:008:0> exit