1 HBase安装
1.1 HBase基本原理
见PPT。
1.2 HBase安装
1 解压
[root@cent71 module]# tar -zxf hbase-1.3.2-bin.tar.gz -C /opt/software/
2 修改hbase-env.sh文件:
export JAVA_HOME=/opt/software/jdk1.8.0_152
export HBASE_MANAGES_ZK=false
3 修改hbase-site.xml文件:
<!-- 指定hbase的数据文件储存在hdfs上的路径,就是regionServer的共享目录 -->
<property>
<name>hbase.rootdir</name>
<value>hdfs://master:9000/hbase</value>
</property>
<!-- 指定hbase的运行模式为分布式模式,false就是单机模式,true就是分布集群模式 -->
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
<!-- 指定zookeeper的地址 -->
<property>
<name>hbase.zookeeper.quorum</name>
<value>master:2181,slave1:2181,slave2:2181</value>
</property>
4 修改regionservers:
cent71
cent72
cent73
5 软连接hadoop配置文件到hbase:
[root@cent71 conf]# ln -s /opt/software/hadoop-2.7.0/etc/hadoop/core-site.xml /opt/software/hbase-1.3.2/conf/core-site.xml
[root@cent71 conf]# ln -s /opt/software/hadoop-2.7.0/etc/hadoop/hdfs-site.xml /opt/software/hbase-1.3.2/conf/hdfs-site.xml
6 发动到其他节点:
[root@cent71 software]# `scp -r hbase-1.3.2/ cent72:/opt/software/`
[root@cent71 software]# `scp -r hbase-1.3.2/ cent73:/opt/software/`
7 启动Hadoop和zookeeper:
8 启动hbase:
9 必须是在master active的情况下启动
[root@cent71 software]# start-hbase.sh
10 查看状态:
jps
http://cent71:16010
1.3 HBase基本操作
HBase Shell是HBase的命令行工具,可以通过它对HBase进行操作,以下指令进入Shell界面:(如果没有配置环境变量,需要在hbase安装路径下输入bin/hbase shell)
[root@cent71 software]# hbase shell
1 显示所有表
hbase(main):001:0> list
TABLE
0 row(s) in 0.2550 seconds
=> []
2 创建表
create ‘表名’,’列族名1’,’列族名2’
hbase(main):002:0> create 'stu','score','info'
0 row(s) in 1.4820 seconds
=> Hbase::Table - stu
3 查询数据
scan ‘表名’
hbase(main):006:0> scan 'stu'
ROW COLUMN+CELL
1001 column=score:math, timestamp=1589251159526, value=90
1 row(s) in 0.0450 seconds
4 增加数据put
put ‘表名’,’行键’,’列族名:列名’,’值’
hbase(main):005:0> put 'stu','1001','score:math','90'
0 row(s) in 0.1240 seconds
5 删除数据delete
delete ‘表名’,’行键’,’列族名:列名’
hbase(main):013:0> delete 'stu','1001','score:math'
0 row(s) in 0.0310 seconds
6 修改数据put
hbase(main):015:0> put 'stu','1001','score:hadoop','80'
0 row(s) in 0.0110 seconds
7 删除表disable->drop
删除表时需要先disable,再进行drop
hbase(main):017:0> disable 'stu'
0 row(s) in 2.2710 seconds
hbase(main):018:0> drop 'stu'
0 row(s) in 1.2420 seconds
删除表时需要先disable,再进行drop
hbase(main):017:0> disable 'stu'
0 row(s) in 2.2710 seconds
hbase(main):018:0> drop 'stu'
0 row(s) in 1.2420 seconds