Hbase的安装与配置

1.下载HBase二进制文件:

资料链接:(可惜阿里云限制不能上传)

链接:https://pan.baidu.com/s/1hQ4hvY-v8SQAYB-WaoWZeg?pwd=16bd
提取码:16bd

2.将文件解压上传到/usr/local

1
2
tar -zxvf hbase-1.4.12-bin.tar.gz
sudo mv /hbase-1.4.12 /usr/local

3.配置hbase-env.sh和hbase-site.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
hbase-site.xml:
<configuration>
<property>         
<name>hbase.rootdir</name>
<value>hdfs://localhost:9000/hbase</value>
</property>
<property>
<name>hbase.tmp.dir</name>
<value>/usr/local/hbase-1.4.12/tmp</value>
<property>
<name>hbase.zookeeper.property.dataDir</name>
<value>/usr/local/hbase-1.4.12/zookeeper/data</value>
</property>
</property>
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
<property>
<name>hbase.zookeeper.quorum</name>
<value>localhost</value>
</property>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
</configuration>

4.配置环境变量

1
2
export HBASE_HOME=/usr/local/hbase-1.4.12
export PATH=$PATH:$HBASE_HOME/bin

5.启动hbase

1
2
3
start-all.sh
start-hbase.sh
hbase shell

6.常用命令

1
2
3
list 查看有哪些表
create 'yejunchen','info' 建表
describe 'yejunchen' 查看
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#禁用表
disable '表名'
#删表
drop '表名'
#查看表是否存在
exsits '表名'

#增加列族
alter '表名','列族名'
#删除列族
alter '表名',{NAME=>'列族名',METHOD=>'delete'}
#更改列族储存版本的限制
alter '表明',{NAME=>'列族名',VERSIONS=>3}

#插入数据
put '表名','行键','列族','值'
put 'student','2021900342','info:age','20'
put 'student','2021900342','info:sex','male'
put 'student','2021900342','info:name','yejunchen'
put 'student','2021900300','info:age','20'
put 'student','2021900300','info:height','170'

put 'yejunchen_result','1','info:xibu','9.1'
put yejunchen_result','1','info:xibu','9.1'
#查表
scan '表名'
scan 'yejunchen_result','1'
get '表名','行键'
get '表名','行键','列族'
get 'student','2021900342','info:name'
#条件查询
scan '表名',FILTER=>"ValueFilter"(=,"xx:value")
scan 'student',FILTER=>"ValueFilter(=,'binary:20')"
scan 'student',FILTER=>"ValueFilter(=,'substring:ye')"

scan 'student',{COLUMNS=>"info:age",FILTER=>"ValueFilter(=,'binary:20')"}
#删除
delete '表名','行键','列族'
delete 'student','2021900300','info:height'