9.24 hbase学习记录
载
进入hbase下载页面,选择与hadoop版本相兼容的hbase版本。在这个页面使用ctrl+f搜索"S", 然后下面有一个表就是hbase与hadoop版本对应关系:

我这里使用的hadoop版本是2.8.5,使用的hbase版本是2.1.1。
新建一个/usr/hbase目录,然后下载hbase。

安装
使用tar xzvf hbase-XXX命令解压hbase的包。解压完后,进入到解压好的hbase目录中,编辑conf/hbase-site.xml,该文件时主要的hbase配置文件,配置hbase的数据存储目录,这个配置文件中,在官方文档提及到
You do not need to create the HBase data directory. HBase will do this for you. If you create the directory, HBase will attempt to do a migration, which is not what you want.
大概意思是,我们不需要去创建hbase的数据目录,hbase会自己建一个目录来保存数据,如果我们自定义了目录,那么hbase把数据进行迁移过来,这会导致性能以及时间上的一些损耗。
配置
配置JAVA_HOME
首先找到java的安装路径。然后使用vim /etc/profile命令打开profile文件,然后指定JAVA_HOME:

配置hbase-site.xml
因为我之前已经安装了hadoop,已经有hdfs了,所以,这里的hbase.rootdir配置就要指向我的hadoop的hdfs目录,我是配置的core-site.xml中fs.defaultFS配置:

我的hbase-site.xml配置如下:
<configuration>
<property>
<name>hbase.rootdir</name>
<value>hdfs://localhost:9000/hbase</value>
</property>
<property>
<name>hbase.zookeeper.property.dataDir</name>
<value>/usr/hadoop/hbase/zookeeper</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>
</configuration>
hbase.rootdir指定hbase数据存储的地方hbase.zookeeper.property.dataDirzookeeper也需要存储一些文件,该地方是指定zookeeper存储数据的地方
启动测试
运行hbase
运行bin/start-hbase.sh,如果运行成功,使用jps命令可看到HMaster进程启动成功:

另外访问<yourip>:16010能看到HBase的管理页面:

使用hbase shell
进入到hbase的安装目录下,使用bin/hbase shell启动hbase:

看到:
hbase(main):001:0>
表示hbase已经启动成功,可以直接使用hbase命令操作了。
create <table> <column family>命令
create 'test', 'cf'表示创建一张test的表,column family为cf,创建表的时候table和column family缺一不可。

list <table>确认某个表是否存在

describe <table>查看表的详细信息,包括默认值。

put <table> <row> <column family> <value>put值到某个表中
因为HBase使用table/row/column family来确定值的唯一性,所以在put值时,这些信息也是缺一不可的。

scan <table>查看某个表中的数据

get <table> <row>获取某个表某行的数据

disable <table>禁用表

如果需要删除表或更改表的设置,需要先使用该命令禁用表,禁用后也可以使用enable <table>来启用表。
enable <table>启用表

drop <table>删除表

最后退出HBase Shell: quit


浙公网安备 33010602011771号