HBase环境搭建有三种方式:1.本地模式:只需要一个节点(只有HMaster,没有HRegionServer),不需要集成ZooKeeper,数据存储在本地文件系统上;2.伪分布模式:只需要一个节点(HMaster和HRegionServer在同一个节点上),需要集成ZooKeeper,数据存储在HDFS上;3.全分布模式:至少需要3个节点(一个HMaster节点和至少2个HRegionServer节点),需要集成ZooKeeper,数据存储在HDFS上。本节先来介绍HBase本地模式的环境搭建过程。
本节用到的安装介质:
hbase-2.0.1-bin.tar.gz 提取码:h04f
1.下载HBase安装包
可以从上面的安装介质链接中下载HBase安装包,或者去HBase官网下载最新HBase安装包,然后使用WInSCP工具将下载好的安装包上传至/root/tools目录下。
[root@localhost ~]# cd /root/tools/
[root@localhost tools]# ls
hbase-2.0.1-bin.tar.gz
2.解压HBase到安装目录
将HBase安装包解压至安装目录/root/trainings/
[root@localhost tools]# tar -zxvf hbase-2.0.1-bin.tar.gz -C /root/trainings/
3.配置HBase环境变量
将HBase加入到环境变量PATH中
[root@localhost tools]# cd /root/trainings/hbase-2.0.1/
[root@localhost hbase-2.0.1]# pwd
/root/trainings/hbase-2.0.1
[root@localhost hbase-2.0.1]# vim /root/.bash_profile
HBASE_HOME=/root/trainings/hbase-2.0.1
export HBASE_HOME
PATH=$HBASE_HOME/bin:$PATH
export PATH
[root@localhost hbase-2.0.1]# source /root/.bash_profile
4.配置HBase配置文件
在本地新建一个目录用来存储HBase的数据:
[root@localhost ~]# cd /root/trainings/hbase-2.0.1/
[root@localhost hbase-2.0.1]# mkdir data
进入$HBASE_HOME/conf目录,配置下面的配置文件:
[root@localhost conf]# pwd
/root/trainings/hbase-2.0.1/conf[root@localhost conf]# vim hbase-env.sh
# The java implementation to use. Java 1.8+ required.
# export JAVA_HOME=/usr/java/jdk1.8.0/
export JAVA_HOME=/root/trainings/jdk1.8.0_144[root@localhost conf]# vim hbase-site.xml
<configuration>
<property>
<name>hbase.rootdir</name>
<value>file:///root/trainings/hbase-2.0.1/data</value>
</property>
</configuration>
注意:这里需要Java的版本在1.8以上。
5.启动HBase
[root@localhost ~ ]# start-hbase.sh
running master, logging to /root/trainings/hbase-2.0.1/logs/hbase-root-master-localhost.out
[root@localhost ~ ]# jps
2785 Jps
2500 HMaster
可以看到,HBase本地模式启动之后只有一个HMaster进程,没有RegionServer进程。
可以在网页上监控HBase的状态信息:端口号16010
6.使用HBase
使用hbase shell命令可以进入HBase命令行模式:
[root@localhost ~]# hbase shell
2018-07-14 16:18:37,650 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.
Version 2.0.1, r987f7b6d37c2fcacc942cc66e5c5122aba8fdfbe, Wed Jun 13 12:03:55 PDT 2018
Took 0.0016 seconds
hbase(main):001:0> create 'tblStudent','Info','Grade'
Created table tblStudent
Took 1.0760 seconds
=> Hbase::Table - tblStudent
hbase(main):002:0> put 'tblStudent','stu001','Info:name','Tom'
Took 22.2864 seconds
hbase(main):003:0> put 'tblStudent','stu001','Info:age','25'
Took 0.0198 seconds
hbase(main):004:0> put 'tblStudent','stu001','Grade:chinese','88'
Took 0.0033 seconds
hbase(main):005:0> put 'tblStudent','stu001','Grade:math','90'
Took 0.0027 seconds
hbase(main):006:0> put 'tblStudent','stu002','Info:name','Jack'
Took 0.0089 seconds
hbase(main):007:0> put 'tblStudent','stu002','Info:age','23'
Took 0.0051 seconds
hbase(main):008:0> put 'tblStudent','stu002','Grade:english','78'
Took 0.0024 seconds
hbase(main):009:0> put 'tblStudent','stu002','Grade:math','60'
Took 0.0045 seconds
hbase(main):010:0> scan 'tblStudent'
ROW COLUMN+CELL
stu001 column=Grade:chinese, timestamp=1531556679082, value=88
stu001 column=Grade:math, timestamp=1531556693871, value=90
stu001 column=Info:age, timestamp=1531556656589, value=25
stu001 column=Info:name, timestamp=1531556621022, value=Tom
stu002 column=Grade:english, timestamp=1531556746645, value=78
stu002 column=Grade:math, timestamp=1531556756247, value=60
stu002 column=Info:age, timestamp=1531556725911, value=23
stu002 column=Info:name, timestamp=1531556712295, value=Jack
2 row(s)
Took 0.0257 seconds
hbase(main):011:0> quit
使用quit命令退出HBase命令行环境。
查看/root/trainings/hbase-2.0.1/data目录下生成的数据:
[root@localhost ~]# ls /root/trainings/hbase-2.0.1/data
archive corrupt data hbase.id hbase.version MasterProcWALs mobdir oldWALs staging WALs
[root@localhost data]# ls /root/trainings/hbase-2.0.1/data/default
tblStudent
[root@localhost data]# tree /root/trainings/hbase-2.0.1/data/default/tblStudent/
default/tblStudent/
└── 78bb809e4ea66d7d47ec6d9bb5c63c30
├── Grade
│ └── 110017baa5654f36b7611557cb29ffbf
├── Info
│ └── 101ea5ab6f0a404d8848da615c505f54
└── recovered.edits
└── 15.seqid
4 directories, 3 files
7.停止HBase
[root@localhost ~]# stop-hbase.sh
stopping hbase..........
[root@localhost ~]# jps
4366 Jps
本节介绍了HBase本地模式的环境搭建过程!祝你玩得愉快!