HBase的 官网 内容还是挺多的,下载安装包还是使用 清华大学开源软件镜像站 会快一些 ⚡️ 本文的安装文件为:hbase-2.4.5-bin.tar.gz
1.前置条件
HBase 是一个构建在 Hadoop 文件系统之上的面向列的数据库管理系统。运行时不仅需要 Hadoop 还依赖 JDK 环境,HBase 2.0+ 以上版本不再支持 JDK 1.7 ,需要JDK 1.8+【1.8永远嘀神 👍】
# 只贴出版本信息
[root@tcloud ~]# hadoop version
Hadoop 3.1.3
[root@tcloud ~]# java -version
java version "1.8.0_251"
2.模式说明
- standalone模式下,所有守护进程都运行在一个 jvm 进程/实例中;
- 伪分布模式下,HBase 仍然在单个主机上运行,但是每个守护进程 (HMaster,HRegionServer 和 ZooKeeper) 则分别作为一个单独的进程运行。
说明:两种模式的部署对于开发测试来说区别不大【这里部署standalone模式】。
3.安装配置
# 1.解压并移动到/usr/local/hbase下
tar -zxvf hbase-2.4.5-bin.tar.g
mv ./hbase-2.4.5/ /usr/local/hbase/
# 2.配置环境变量
vim /etc/profile.d/my_env.sh
# 添加
export HBASE_HOME=/usr/local/hbase
export PATH=$HBASE_HOME/bin:$PATH
# 使得配置的环境变量立即生效:
# 首先是要赋权限【只操作一次就行】
chmod +x /etc/profile.d/my_env.sh
source /etc/profile.d/my_env.sh
# 验证一下
echo $HBASE_HOME # 显示/usr/local/hbase表示成功
# 3.修改配置文件 hbase-env.sh
vim /usr/local/hbase/conf/hbase-env.sh
# 配置 JAVA_HOME
export JAVA_HOME=/usr/local/java/
# Tell HBase whether it should manage it's own instance of ZooKeeper or not.
# export HBASE_MANAGES_ZK=true
# 如果使用外置的zookeeper服务可以设置成false【云服务器内存吃紧 没有使用外置的】
export HBASE_MANAGES_ZK=false
# 4.添加数据文件夹【放哪里可以自己定】
mkdir /usr/local/hbase/rootdir
# 5.修改配置文件 hbase-site.xml
vim /usr/local/hbase/conf/hbase-site.xml
<configuration>
<!--自带的3个配置 本次部署不用修改-->
<property>
<name>hbase.cluster.distributed</name>
<value>false</value>
</property>
<property>
<name>hbase.tmp.dir</name>
<value>./tmp</value>
</property>
<property>
<name>hbase.unsafe.stream.capability.enforce</name>
<value>false</value>
</property>
<!--新增配置-->
<property>
<name>hbase.rootdir</name>
<!--指定HBase数据存储路径为HDFS上的hbase目录-->
<!--<value>hdfs://tcloud:8020/hbase</value>-->
<!--也可以设置成本地文件系统-->
<value>file:///usr/local/hbase/rootdir</value>
</property>
<!--不调整zookeeper的配置参数 此项也可以不进行配置-->
<property>
<name>hbase.zookeeper.property.dataDir</name>
<value>/home/zookeeper/hbaseDir</value>
</property>
</configuration>
- hbase.rootdir : 配置 hbase 数据的存储路径;
- hbase.zookeeper.property.dataDir : 配置 zookeeper 数据的存储路径;
- hbase.unsafe.stream.capability.enforce : 使用本地文件系统存储,不使用 HDFS 的情况下需要禁用此配置,设置为 false。
# 6.修改 regionservers 指定 region servers 的地址
vim /usr/local/hbase/conf/regionservers
# 原始配置为localhost 如果配置过ip映射 这里可以不修改
tcloud
4.启动验证
[root@tcloud ~]# start-hbase.sh
# 无关日志信息不再贴出
running master, logging to /usr/local/hbase/logs/hbase-root-master-tcloud.out
# 使用jps 查看是否有 HMaster
[root@tcloud ~]# jps
26258 SecondaryNameNode
26019 DataNode
25862 NameNode
4921 HMaster
5386 Jps
也可以通过ip:16010/访问Hbase的web页面文章来源:https://www.toymoban.com/news/detail-847734.html
文章来源地址https://www.toymoban.com/news/detail-847734.html
5.简单测试
[root@tcloud ~]# 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.5, r03b8c0cf426cbae3284225b73040ec574d5bac34, Tue Jul 27 09:44:16 PDT 2021
Took 0.0021 seconds
hbase:001:0>
# (1)创建列族信息
hbase:001:0> create 'student','info'
Created table student
Took 2.2369 seconds
=> Hbase::Table - student
# (2)录入数据
hbase:002:0> put 'student','1','info:name','yuanzhengme'
Took 0.4601 seconds
hbase:003:0> put 'student','1','info:gender','F'
Took 0.0267 seconds
hbase:004:0> put 'student','1','info:age','20'
Took 0.0328 seconds
# (3)查询数据
## get命令
hbase:005:0> get 'student','1'
COLUMN CELL
info:age timestamp=2021-09-14T14:24:01.964, value=20
info:gender timestamp=2021-09-14T14:23:59.357, value=F
info:name timestamp=2021-09-14T14:23:52.578, value=yuanzhengme
1 row(s)
Took 0.3296 seconds
## scan命令
hbase:006:0> scan 'student'
ROW COLUMN+CELL
1 column=info:age, timestamp=2021-09-14T14:24:01.964, value=20
1 column=info:gender, timestamp=2021-09-14T14:23:59.357, value=F
1 column=info:name, timestamp=2021-09-14T14:23:52.578, value=yuanzhengme
1 row(s)
Took 0.0647 seconds
# (4)删除数据
## delete
hbase:007:0> delete 'student','1','info:age'
Took 0.0541 seconds
hbase:008:0> get 'student','1'
COLUMN CELL
info:gender timestamp=2021-09-14T14:23:59.357, value=F
info:name timestamp=2021-09-14T14:23:52.578, value=yuanzhengme
1 row(s)
Took 0.2272 seconds
## deleteall
hbase:009:0> deleteall 'student','1'
Took 3.0058 seconds
hbase:010:0> get 'student','1'
COLUMN CELL
0 row(s)
Took 0.0302 seconds
# (5)删除表 删除表要先disable再drop
hbase:011:0> disable 'student'
Took 2.1733 seconds
hbase:012:0> drop 'student'
Took 0.7922 seconds
# (6)查询表的历史版本
hbase:013:0> create 'teacher', { NAME=> 'username', VERSIONS=> 5 }
Created table teacher
Took 0.8262 seconds
=> Hbase::Table - teacher
## 这里不再贴出 Took xxx seconds
hbase:014:0> put 'teacher','1','username','yuanzhengme'
hbase:015:0> put 'teacher','1','username','yuanzhengm'
hbase:016:0> put 'teacher','1','username','yuanzheng'
hbase:017:0> put 'teacher','1','username','yuanzhen'
hbase:018:0> put 'teacher','1','username','yuanzhe'
hbase:019:0> put 'teacher','1','username','yuanzh'
hbase:020:0> put 'teacher','1','username','yuanz'
hbase:021:0> put 'teacher','1','username','yuan'
## 简单查询 只显示最新数据
hbase:022:0> get 'teacher','1'
COLUMN CELL
username: timestamp=2021-09-14T14:47:03.841, value=yuan
1 row(s)
Took 0.9945 seconds
## 查询版本
hbase:023:0> get 'teacher', '1', { COLUMN=>'username', VERSIONS=>5 }
COLUMN CELL
username: timestamp=2021-09-14T14:47:03.841, value=yuan
username: timestamp=2021-09-14T14:47:02.285, value=yuanz
username: timestamp=2021-09-14T14:47:02.154, value=yuanzh
username: timestamp=2021-09-14T14:47:02.103, value=yuanzhe
username: timestamp=2021-09-14T14:47:02.026, value=yuanzhen
1 row(s)
Took 0.0193 seconds
## 查询版本【超出表设置的版本是无效的】
hbase:024:0> get 'teacher', '1', { COLUMN=> 'username', VERSIONS=> 6 }
COLUMN CELL
username: timestamp=2021-09-14T14:47:03.841, value=yuan
username: timestamp=2021-09-14T14:47:02.285, value=yuanz
username: timestamp=2021-09-14T14:47:02.154, value=yuanzh
username: timestamp=2021-09-14T14:47:02.103, value=yuanzhe
username: timestamp=2021-09-14T14:47:02.026, value=yuanzhen
1 row(s)
Took 0.0189 seconds
## 查询版本【可以查询少于设置的版本数】
hbase:025:0> get 'teacher', '1', { COLUMN=> 'username', VERSIONS=> 4 }
COLUMN CELL
username: timestamp=2021-09-14T14:47:03.841, value=yuan
username: timestamp=2021-09-14T14:47:02.285, value=yuanz
username: timestamp=2021-09-14T14:47:02.154, value=yuanzh
username: timestamp=2021-09-14T14:47:02.103, value=yuanzhe
1 row(s)
Took 0.3921 seconds
# (7)退出
hbase:026:0> exit
到了这里,关于HBase【部署 01】CentOS 7.5 部署 hbase-2.4.5 单机版standalone模式(详细安装+配置+增删改查测试脚本)(附开源镜像站地址)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!