0%

hbase单机版部署及简单测试

Centos7上部署单机版hbase

下载安装包

hbase

hbase官网

解压

tar -zxvf hbase-2.2.4.bin.tar.gz

配置hbase-env.sh

部署JDK,查看JAVA_HOME路径。

[root@node1 hbase]# echo $JAVA_HOME
/usr/local/bin/jdk1.8.0_112

配置conf/hbase-env.sh

...
# 配置java路径
export JAVA_HOME=/usr/local/bin/jdk1.8.0_112
# 配置是否使用自身Zookeeper
export HBASE_MANAGES_ZK=true
...

编辑conf/hbase-site.xml

<configuration>
    <property>
        <name>hbase.rootdir</name>
        <value>file:///root/hbase/rootdir</value>
        <description>The directory shared byregion servers.</description>
    </property>
    <property>
        <name>fs.defaultFS</name>
&nbsp;       <value>file:///root/hbase/dfs</value>
    </property>
    <!-- hbase的端口 -->
    <!-- <property>
        <name>hbase.zookeeper.property.clientPort</name>
        <value>2181</value>
        <description>Property from ZooKeeper'sconfig zoo.cfg. The port at which the clients will connect.
        </description>
    </property> -->
    <!--&nbsp; 超时时间 -->
    <!-- <property>
        <name>zookeeper.session.timeout</name>
        <value>120000</value>
    </property> -->
    <!--&nbsp; zookeeper 集群配置。如果是集群,则添加其它的主机地址 -->
    <!-- <property>
        <name>hbase.zookeeper.quorum</name>
        <value>localhost:2181</value>
    </property> -->
    <property>
        <name>hbase.tmp.dir</name>
        <value>/root/hbase/tmp</value>
    </property>
    <!-- <property>
        <name>hbase.cluster.distributed</name>
        <value>false</value>
    </property> -->
    <property>
        <name>hbase.zookeeper.property.dataDir</name>
        <value>/root/hbase/datadir</value>
    </property>
    <property>
        <name>zookeeper.znode.parent</name>
        <value>/hbase</value>
    </property>
</configuration>

启动

./bin/start-hbase.sh

Web UI

http://192.168.41.128:16010

进入shell命令行

./bin/hbase shell

简单测试

创建一个表,需要指明table nameColumnFamily name

hbase(main):002:0> create 'test', 'cf'
Created table test
Took 0.8251 seconds
=> Hbase::Table - test

确认

hbase(main):004:0> list 'test'
TABLE
test
1 row(s)
Took 0.0077 seconds
=> ["test"]

describe ‘test’

hbase(main):005:0> describe 'test'
Table test is ENABLED
test
COLUMN FAMILIES DESCRIPTION
{NAME => 'cf', VERSIONS => '1', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSION_BEHAVIOR => 'false', KEEP_DELETED_CELLS => 'FALSE', CACHE_DATA_ON_WRITE => 'false', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPL
ICATION_SCOPE => '0', BLOOMFILTER => 'ROW', CACHE_INDEX_ON_WRITE => 'false', IN_MEMORY => 'false', CACHE_BLOOMS_ON_WRITE => 'false', PREFETCH_BLOCKS_ON_OPEN => 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BLOCKSIZE => '65536'} 

1 row(s)

QUOTAS                                                                                                                                                                  0 row(s)
Took 0.2132 seconds 

写入数据

hbase(main):003:0> put 'test', 'row1', 'cf:a', 'value1'
0 row(s) in 0.0850 seconds

hbase(main):004:0> put 'test', 'row2', 'cf:b', 'value2'
0 row(s) in 0.0110 seconds

hbase(main):005:0> put 'test', 'row3', 'cf:c', 'value3'
0 row(s) in 0.0100 seconds

查看写入的数据

hbase(main):006:0> scan 'test'
ROW                                      COLUMN+CELL
 row1                                    column=cf:a, timestamp=1586504678931, value=value1
 row2                                    column=cf:b, timestamp=1586504712029, value=value2
 row3                                    column=cf:c, timestamp=1586504717104, value=value3
3 row(s) in 0.0230 seconds

获取一行数据

hbase(main):007:0> get 'test', 'row1'
COLUMN                                   CELL
 cf:a                                    timestamp=1586504678931, value=value1
1 row(s) in 0.0350 seconds

获取一个字段

hbase(main):007:0> get 'test', 'row1','cf:a'
COLUMN                                   CELL
 cf:a                                    timestamp=1586504678931, value=value1
1 row(s) in 0.0350 seconds

返回一个字段的多个版本值

默认Hbase列族最多保存一个版本的数据,可以通过下面命令修改,也可以使用HColumnDescriptor

alter 'test', NAME => 'cf', VERSIONS => 3

HBase 0.98.2开始,您可以通过在hbase-site.xml中设置hbase.column.max.version为所有新创建列保留的最大版本数指定一个全局默认值。

get 'test', 'row1', {COLUMN=>'cf:a',VERSIONS=>3}

禁用或者恢复表

hbase(main):008:0> disable 'test'
0 row(s) in 1.1820 seconds

hbase(main):009:0> enable 'test'
0 row(s) in 0.1770 seconds

添加一个列族

hbase(main):012:0> alter 'test',{NAME=>'haha'}
Updating all regions with the new schema...
1/1 regions updated.
Done.
Took 2.0149 seconds 
hbase(main):014:0> alter 'test',NAME=>'hehe'
Updating all regions with the new schema...
1/1 regions updated.
Done.
Took 1.9555 seconds 

删除一个列族

hbase(main):009:0> alter 'test',{NAME=>'haha',METHOD=>'delete'}
Updating all regions with the new schema...
1/1 regions updated.
Done.
Took 1.9296 seconds
hbase(main):013:0> alter 'test','delete'=>'haha'
Updating all regions with the new schema...
1/1 regions updated.
Done.
Took 1.8706 seconds 
# 添加一个列族,同时删除一个列族
hbase(main):011:0> alter 'test', {NAME => 'hehe'}, {NAME => 'myInfo', METHOD => 'delete'}
Updating all regions with the new schema...
1/1 regions updated.
Done.
Updating all regions with the new schema...
1/1 regions updated.
Done.
0 row(s) in 3.8260 seconds

清空表

hbase(main):013:0> truncate 'test'
Truncating 'test' table (it may take a while):
 - Disabling table...
 - Truncating table...
0 row(s) in 3.6760 seconds

删除表

删除表或者修改表的配置前,需要禁用表

hbase(main):011:0> drop 'test'
0 row(s) in 0.1370 seconds

退出Shell

quit 或者 Ctrl+D

停止Hbase

./bin/stop-hbase.sh