二、安装教程(单机版)
1,下载二进值包
(1)首次我们访问:https://archive.apache.org/dist/hbase,页面打开后点击 stable 链接(这里面为当前最稳定的版本)
(2)接着找到 hbase-2.2.4-bin.tar.gz 链接地址,然后在服务器上通过 wget 命令将其下载下来: 推荐使用hbase-2.2.4版本
wget https://archive.apache.org/dist/hbase/2.2.4/hbase-2.2.4-bin.tar.gz
(3)接着解压下载的文件:
tar xzvf hbase-2.2.4-bin.tar.gz
(4)然后将解压出来的文件夹移动到 /home 目录下:
mv hbase-2.2.4 /home/
(5)最后进入这个 HBase 文件夹:
cd /home/hbase-2.2.4/
2,修改配置
(1)由于 HBase 依赖 JAVA_HOME 环境变量,所以要导入 Java 环境变量。执行如下命令编辑 conf/hbase-env.sh 文
vim conf/hbase-env.sh
(2)取消 #export JAVA_HOME= 开头的注释,然后将其设置为 Java 安装路径: 在hbase-env.sh
(3)接着执行如下命令编辑 conf/hbase-site.xml,这是主要的 HBase 配置文件。
vi conf/hbase-site.xml
(4)默认情况下 <configuration></configuration> 节点里面是空的,我们在里面添加如下配置指定 hbase 和 ZooKeeper 数据写入的目录:
提示:这两个目录地址可以根据需求自由设置。另外,这两个文件夹无需事先创建,HBase 会自动创建好。也可以自己创建好
<!-- hbase存放数据目录 -->
<property>
<name>hbase.rootdir</name>
<value>file:///home/hbase-2.2.4/hbase</value>
</property>
<!-- ZooKeeper数据文件路径 -->
<property>
<name>hbase.zookeeper.property.dataDir</name>
<value>/home/hbase-2.2.4/zookeeper</value>
</property>
<property>
<name>hbase.master.ipc.address</name>
<value>0.0.0.0</value>
</property>
<property>
<name>hbase.regionserver.ipc.address</name>
<value>0.0.0.0</value>
</property>
<property>
<name>hbase.unsafe.stream.capability.enforce</name>
<value>false</value>
<description>
Controls whether HBase will check for stream capabilities (hflush/hsync).
Disable this if you intend to run on LocalFileSystem, denoted by a rootdir
with the 'file://' scheme, but be mindful of the NOTE below.
WARNING: Setting this to false blinds you to potential data loss and
inconsistent system state in the event of process and/or node failures. If
HBase is complaining of an inability to use hsync or hflush it's most
likely not a false positive.
</description>
</property>
注意ZooKeeper数据文件路径 要写 百度上很多教程没写 自带zookeeper没启动,报各种错
3,启动 HBase
(1)执行如下命令启动 HBase:
./bin/start-hbase.sh
(2)执行如下命令停止 HBase:
./bin/stop-hbase.sh
4,查看是否启动成功
(1)我们可以用 jps 命令查看 master
(2)或者也可以使用浏览器访问 HBase 的 Web UI,地址为 http://IP:16010
注意 这里云服务器 安全组 最好把2181,16000,16010,16020端口和系统防火墙开放端口 因为访问ui界面和java api调用不通报各种错。
附:使用 HBase 命令行工具测试
1,启动命令行工具
执行如下命令启动 HBase 的 shell
cd /home/hbase-2.2.4/
./bin/hbase shell
2,创建、查看表
(1)使用 create 命令创建一个新表(这里表名称为 test,列簇名为 cf)
create 'test', 'cf'
(2)使用 list
list
describe
describe 'test'
3,插入、查询数据
(1)要将数据放入表中,可以使用 put 命令,比如下面命令连续插入 3
put 'test', 'row1', 'cf:a', 'value1'
put 'test', 'row2', 'cf:b', 'value2'
put 'test', 'row3', 'cf:c', 'value3'
(2)使用 scan
scan 'test'
get
get 'test', 'row1'
4,禁用、删除表
(1)如果要删除表或更改其设置,以及在某些其他情况下,则需要先使用 disable
disable 'test'
(2)如果表被禁用,可以使用 enable
enable 'test'
(3)将表禁用后,我们就可以使用 drop
drop 'test'
ZooKeeper数据文件路径