软件及环境:
虚拟机:VirtualBox
操作系统(在VirtualBox上安装的):ubuntu-16.04
软件:hbase-1.2.4 、 jdk1.8.0_111
具体操作步骤:
一、下载、解压缩HBase
1、ctrl+alt+T 打开ubuntu系统的终端界面,使用sudo wget 命令下载HBase:
命令: wget mirrors.cnnic.cn/apache/hbase/1.2.4/hbase-1.2.4-bin.tar.gz

2、解压缩下载的打包压缩HBase 文件
命令:tar xzf hbase-1.2.4-bin.tar.gz

二、配置HBase
1、修改hbase环境配置:进入hbase目录下的conf目录,然后编辑目录下的hbase-env.sh文件,在文件中找到export JAVA_HOME语句,设置JAVA_HOME(我的jdk版本为1.8,安装的目录为/newdisk/jdk1.8.0_111):export JAVA_HOME=/newdisk/jdk1.8.0_111


2、修改HBase的主配置文件hbsae-site.xml:在单实例HBase运行环境下,主要是修改指定HBase和ZooKeeper的写数据目录。
HBase数据保存目录为:file:/home/ubuntu/usr/tmp/hbase
Zookeeper的数据保存目录为:/home/ubuntu/usr/tmp/zookeeper

3、为更方便使用hbase命令,可以进行环境变量的配置,将hbase的启动、关闭等脚本写入系统环境变量中。
1)、转换目录到根目录下:cd /;使用sudo vi ~/.bashrc 命令,输入密码

2)、在.bashrc文件的末尾加上下面的语句:
export HBASE_HOME=/home/ubuntu/hbase-1.2.4
export HBASE_CONF_DIR=$HBASE_HOME/conf
export HBASE_CLASS_PATH=$HBASE_CONF_DIR
export PATH=$PATH:$HBASE_HOME/bin

添加完成后保存退出:“:wq”。
3)、使用source ~/.bashrc命令语句使修改的 .bashrc文件立即生效。并使用hbase version 命令测试是否修改.bashrc文件成功,如能显示HBase正确的版本则说明修改成功。

三、启动与停止HBase
1、启动HBase:start-hbase.sh
运行start-hbase.sh命令之前,确保/etc/hosts配置正确(保证127.0.0.1和localhost对应,保证127.0.0.1和主机名对应):cd / -> vi etc/hosts ,查看hosts的内容:


如果localhost对应的不是127.0.0.1,则使用ssh localhost命令之后,再次对etc.hosts文件进行查看。
2、停止HBase:stop-hbase.sh

四、HBase Shell
(一)、进入HBase的shell环境:start-hbase.sh -> hbase shell

(二)、hbase shell 命令
1.表的管理
1)、查看有哪些表:list

2)、创建表:create
语法:create <table> ,{NAME => <family> , VERSIONS => <VERSIONS>}
示例:创建表”test“,family name:f1 f2, 版本数均为2;
create 'test',{NAME => 'f1',VERSIONS =>2},{NAME =>'f2',VERSIONS => 2}

3)、删除表:disable <table> -> drop <table>
示例:删除表test

4)、查看表的结构:describe <table>

2、表数据的增删改查
1)、添加数据:put <table>,<rowkey>,<family:column>,<value>,<timestamp>
示例:如下插入三条数据。其中 't1'是表名, 'row1'是键名,'cf:a'中的cf是列族,a是列族下的属性名,'value1'是属性对应的值。

2)、查询数据记录
a. 查询某行记录:get <table>,<rowkey>,[<family:column>,......]

b. 扫描表:scan <table>

c. 查询表中的数据行数:count <table>

3)、删除数据
a. 删除行中的某个列值:delete <table>,<rowkey>,<family:column>

b. 删除行:deleteall <table>,<rowkey>,<family:column>

c、删除表中的所有数据:truncate <table>

(三)、退出HBase的shell环境:quit

网友评论