P3
HBase安装与配置¶
-
下载镜像
wget https://mirrors.nju.edu.cn/apache/hbase/2.5.5/
-
解压安装包
tar xzvf hbase-2.5.5-bin.tar.gz
-
重命名
mv ~/hbase-2.5.5 ~/hbas
-
修改
hbase-env.sh
export JAVA_HOME=/usr/lib/jvm/default-java
#export HBASE_MANAGES_ZK=false
- 修改
hbase-env.sh
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
<property>
<name>hbase.rootdir</name>
<value>hdfs://192.168.35.129:9000/hbase</value>
</property>
<property>
<name>hbase.tmp.dir</name>
<value>./tmp</value>
</property>
<property>
<name>hbase.unsafe.stream.capability.enforce</name>
<value>false</value>
</property>
<property>
<name>hbase.zookeeper.quorum</name>
<value>localhost</value>
</property>
<property>
<name>hbase.master.port</name>
<value>16000</value>
</property>
<property>
<name>hbase.master.info.port</name>
<value>16010</value>
</property>
<property>
<name>hbase.zookeeper.property.clientPort</name>
<value>2181</value>
</property>
-
启动Hadoop及hbase
start-hbase.sh
-
jps查看运行状态
-
web查看
-
hdfs查看
问题及解决¶
-
hbase连接hdfs失败,不会自动创建文件夹
-
显示指出hdfs地址
<property>
<name>hbase.rootdir</name>
<value>hdfs://192.168.35.129:9000/hbase</value>
</property>
-
zookerper不启动
-
export HBASE_MANAGES_ZK=false
应该删去,还是得为true -
hbase web打不开
-
手动指定端口
<property>
<name>hbase.master.port</name>
<value>16000</value>
</property>
<property>
<name>hbase.master.info.port</name>
<value>16010</value>
</property>
Shell编程¶
- 进入shell
hbase shell
设计并创建表¶
- 学生表
- 创建表
create 'student', 'stuInfo'
-
插入信息(学号作为行键)
put 'student', '2120001', 'stuInfo:S_Name', 'Li Lei' put 'student', '2120001', 'stuInfo:S_Sex', 'male' put 'student', '2120001', 'stuInfo:S_Age', '20' put 'student', '2120002', 'stuInfo:S_Name', 'Han Meimei' put 'student', '2120002', 'stuInfo:S_Sex', 'female' put 'student', '2120002', 'stuInfo:S_Age', '21' put 'student', '2120003', 'stuInfo:S_Name', 'Zhang Li' put 'student', '2120003', 'stuInfo:S_Sex', 'female' put 'student', '2120003', 'stuInfo:S_Age', '20' put 'student', '2120004', 'stuInfo:S_Name', 'Li Ming' put 'student', '2120004', 'stuInfo:S_Sex', 'male' put 'student', '2120004', 'stuInfo:S_Age', '19'
-
查看
-
课程表
-
创建表
put 'course', '220001', 'couInfo:C_No', '220001' put 'course', '220001', 'couInfo:C_Name', 'Math' put 'course', '220001', 'couInfo:C_Credit', '4.0' put 'course', '220002', 'couInfo:C_No', '220002' put 'course', '220002', 'couInfo:C_Name', 'English' put 'course', '220002', 'couInfo:C_Credit', '3.0' put 'course', '220003', 'couInfo:C_No', '220003' put 'course', '220003', 'couInfo:C_Name', 'BigData' put 'course', '220003', 'couInfo:C_Credit', '4.0'
-
结果
-
选课表
- 这张表是学生和选课信息的交叉信息,使用符合行键
studentid_classid
-
创建
put 'cs', '2120001_220001', 'csInfo:SC_Sno', '2120001' put 'cs', '2120001_220001', 'csInfo:SC_Cno', '220001' put 'cs', '2120001_220001', 'csInfo:SC_Score', '90' put 'cs', '2120001_220002', 'csInfo:SC_Sno', '2120001' put 'cs', '2120001_220002', 'csInfo:SC_Cno', '220002' put 'cs', '2120001_220002', 'csInfo:SC_Score', '85' put 'cs', '2120001_220003', 'csInfo:SC_Sno', '2120001' put 'cs', '2120001_220003', 'csInfo:SC_Cno', '220003' put 'cs', '2120001_220003', 'csInfo:SC_Score', '75' put 'cs', '2120002_220001', 'csInfo:SC_Sno', '2120002' put 'cs', '2120002_220001', 'csInfo:SC_Cno', '220001' put 'cs', '2120002_220001', 'csInfo:SC_Score', '85' put 'cs', '2120002_220002', 'csInfo:SC_Sno', '2120002' put 'cs', '2120002_220002', 'csInfo:SC_Cno', '220002' put 'cs', '2120002_220002', 'csInfo:SC_Score', '88' put 'cs', '2120003_220001', 'csInfo:SC_Sno', '2120003' put 'cs', '2120003_220001', 'csInfo:SC_Cno', '220001' put 'cs', '2120003_220001', 'csInfo:SC_Score', '95' put 'cs', '2120003_220002', 'csInfo:SC_Sno', '2120003' put 'cs', '2120003_220002', 'csInfo:SC_Cno', '220002' put 'cs', '2120003_220002', 'csInfo:SC_Score', '88' put 'cs', '2120003_220003', 'csInfo:SC_Sno', '2120003' put 'cs', '2120003_220003', 'csInfo:SC_Cno', '220003' put 'cs', '2120003_220003', 'csInfo:SC_Score', '92' put 'cs', '2120004_220001', 'csInfo:SC_Sno', '2120004' put 'cs', '2120004_220001', 'csInfo:SC_Cno', '220001' put 'cs', '2120004_220001', 'csInfo:SC_Score', '85' put 'cs', '2120004_220003', 'csInfo:SC_Sno', '2120004' put 'cs', '2120004_220003', 'csInfo:SC_Cno', '220003' put 'cs', '2120004_220003', 'csInfo:SC_Score', '90'
-
查看
查询选修BigData的学生的成绩¶
- 查询BigData课程id
scan 'course', {COLUMNS => ['couInfo:C_No', 'couInfo:C_Name'], FILTER => "SingleColumnValueFilter('couInfo', 'C_Name', =, 'binary:BigData')"}
- 只有当
couInfo:C_Name
的值等于"BigData"时,返回couInfo:C_No
和couInfo:C_Name
列的值. - 得到结果22003
- 查询成绩
scan 'cs', {COLUMNS => ['csInfo:SC_Cno', 'csInfo:SC_Score'], FILTER => "SingleColumnValueFilter('csInfo', 'SC_Cno', =, 'binary:220003')"}
- 得到全部三位同学的成绩
增加电子邮件¶
-
添加语句
put 'student','2120001','stuInfo:S_Email','lilei@163.com' put 'student','2120002','stuInfo:S_Email','hmm@qq.com' put 'student','2120003','stuInfo:S_Email','zl@foxmail.com' put 'student','2120004','stuInfo:S_Email','lm@qq.com'
-
结果查看
查询Li Lei的电子邮件¶
- 查询
scan 'student', {COLUMNS => ['stuInfo:S_Name', 'stuInfo:S_Email'], FILTER => "SingleColumnValueFilter('stuInfo', 'S_Name', =, 'binary:Li Lei')"}
- 结果
WebUI查看¶
删除所创建的表¶
disable 'student'
drop 'student'
disable 'course'
drop 'course'
disable 'cs'
drop 'cs'
-
查看
遇到的问题¶
-
hbase shell无法正常使用,出现错误
Hbase shell is giving error - ""ERROR: org.apache.hadoop.hbase.ipc.ServerNotRunningYetException: Server is not running yet""
-
在配置文件中添加
xml <property> <name>hbase.wal.provider</name> <value>filesystem</value> </property>