自学大数据第二节:HBase的安装以及使用

1.从hbase.apache.org下载HBase发布包: hbase-2.3.0-bin.tar.gz
2.解压安装包hbase-1.1.2-bin.tar.gz至路径 /usr/local
自学大数据第二节:HBase的安装以及使用
3.为方便以后,改名
自学大数据第二节:HBase的安装以及使用
4.添加环境变量
sudo gedit ~/.bashrc
自学大数据第二节:HBase的安装以及使用
source ~/.bashrc 生效

5.授权 sudo chown -R hadoop ./hbase

6.检验 不知道啥玩意,应该是好用的
自学大数据第二节:HBase的安装以及使用
7.配置 /usr/local/hbase/conf/hbase-env.sh
sudo gedit hbase/conf/hbase-env.sh 打开
加上这仨大兄弟
export JAVA_HOME=/usr/local/java/jdk1.8.0_161
export HBASE_CLASSPATH=/usr/local/hadoop/conf
export HBASE_MANAGES_ZK=true

8.配置/usr/local/hbase/conf/hbase-site.xml

sudo gedit hbase/conf/hbase-site.xml 打开
加上这个
//分布式模式

hbase.cluster.distributed
true

//存储位置

   hbase.rootdir
   hdfs://localhost:9000/hbase
 

9.启动 SSH 无密码登陆
自学大数据第二节:HBase的安装以及使用
启动Hadoop
./sbin/start-dfs.sh
(关闭 sbin/stop-all.sh)

JPS 发现缺少dataNode
原因是我格式化太多次了,这个博客解决问题了
https://blog.****.net/MASILEJFOAISEGJIAE/article/details/89250348
现在全员到齐
自学大数据第二节:HBase的安装以及使用
切换到 /usr/local/hbase
启动 hbase
bin/start-hbase.sh
jps 又加了几个新成员
自学大数据第二节:HBase的安装以及使用
bin/hbase shell

建表:
create ‘student’,‘StudentInfo’,‘TestScores’
查询(表结构):
describe ‘student’
插入:
put ‘student’,‘001’,‘StudentInfo:Name’,‘Tom’
put ‘student’,‘001’,‘StudentInfo:Age’,‘20’
put ‘student’,‘001’,‘StudentInfo:Sex’,‘Male’
put ‘student’,‘001’,‘TestScores:Database’,‘80’
put ‘student’,‘001’,‘TestScores:DataStructure’,‘75’
put ‘student’,‘001’,‘TestScores:Java’,‘75’
put ‘student’,‘001’,‘Hobby:Basketball’,‘VeryLike’
put ‘student’,‘001’,‘Hobby:Movie’,‘Like’
put ‘student’,‘002’,‘StudentInfo:Name’,‘Jerry’
put ‘student’,‘002’,‘StudentInfo:Age’,‘21’
put ‘student’,‘002’,‘StudentInfo:Sex’,‘Male’
put ‘student’,‘002’,‘TestScores:Database’,‘75’
put ‘student’,‘002’,‘TestScores:DataStructure’,‘75’
put ‘student’,‘002’,‘TestScores:Java’,‘70’
put ‘student’,‘002’,‘Hobby:Football’,‘VeryLike’
put ‘student’,‘002’,‘Hobby:Music’,‘Like’
查询(id):
get ‘student’,‘001’
查询全部:
scan ‘student’
删除:
delete ‘student’,‘95001’,‘Sname’
删除全部:
deleteall ‘student’,‘95001’
删除表:
disable ‘student’ 让表不可用
drop ‘student’ 删除表
删除列:
alter ‘student’, ‘delete’ => ‘hobby’
增加列:
alter ‘student’, ‘Hobby’

创建表指定版本:
create ‘teacher’,{NAME=>‘username’,VERSIONS=>5}

插入:
put ‘teacher’,‘91001’,‘username’,‘Mary’
put ‘teacher’,‘91001’,‘username’,‘Mary1’
put ‘teacher’,‘91001’,‘username’,‘Mary2’
put ‘teacher’,‘91001’,‘username’,‘Mary3’
put ‘teacher’,‘91001’,‘username’,‘Mary4’
put ‘teacher’,‘91001’,‘username’,‘Mary5’

查询历史数据:
get ‘teacher’,‘91001’,{COLUMN=>‘username’,VERSIONS=>5}

退出表:exit
停止hbse :bin/stop-hbase.sh

后续Java API 参照
https://www.cnblogs.com/wang-jx/p/9672072.html