实验三刘馨雨.docx

上传人:b****2 文档编号:2941167 上传时间:2023-05-05 格式:DOCX 页数:13 大小:1.74MB
下载 相关 举报
实验三刘馨雨.docx_第1页
第1页 / 共13页
实验三刘馨雨.docx_第2页
第2页 / 共13页
实验三刘馨雨.docx_第3页
第3页 / 共13页
实验三刘馨雨.docx_第4页
第4页 / 共13页
实验三刘馨雨.docx_第5页
第5页 / 共13页
实验三刘馨雨.docx_第6页
第6页 / 共13页
实验三刘馨雨.docx_第7页
第7页 / 共13页
实验三刘馨雨.docx_第8页
第8页 / 共13页
实验三刘馨雨.docx_第9页
第9页 / 共13页
实验三刘馨雨.docx_第10页
第10页 / 共13页
实验三刘馨雨.docx_第11页
第11页 / 共13页
实验三刘馨雨.docx_第12页
第12页 / 共13页
实验三刘馨雨.docx_第13页
第13页 / 共13页
亲,该文档总共13页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

实验三刘馨雨.docx

《实验三刘馨雨.docx》由会员分享,可在线阅读,更多相关《实验三刘馨雨.docx(13页珍藏版)》请在冰点文库上搜索。

实验三刘馨雨.docx

实验三刘馨雨

 

《大数据处理技术》

实验报告

题目:

HBase操作

院系:

计算机科学与工程学院

班级:

170408

*******

学号:

********

实验三HBase操作

一、实验目的

1.理解HBase在Hadoop体系结构中的角色;

2.熟练使用HBase操作常用的Shell命令;

3.熟悉HBase操作常用的JavaAPI。

二、实验环境

1.ubuntu16.04

2.JDK1.8

3.Hadoop2.10

4.JavaIDE:

Eclipse3.8.1-8

5.HBase1.4.12

三、实验内容和要求

Student学生表

name

score

English

Math

Computer

zhangsan

69

86

77

lisi

55

100

88

1.根据上面给出的表格,用HbaseShell模式设计student学生表格。

a)设计完后,用scan指令浏览表的相关信息,给出截图。

b)查询zhangsan的Computer成绩。

给出截图。

c)修改lisi的Math成绩,改为95。

给出截图。

2.根据上面已经设计出的student,用HbaseAPI编程。

a)添加数据:

English:

45Math:

89Computer:

100

scofield

45

89

100

b)获取scofield的English成绩信息

 

四、实验过程及截图

全程参考此教程:

1.在官网下载HBase安装包,找到合适的版本,等待一个小时。

2.解压安装包,命令如下:

sudotar-zxf/home/liu/HBase/hbase-1.4.12-bin.tar.gz-C/home/liu/HBase

将压缩后的文件改名为hbase

3.更改权限:

sudochmod666/home/liu/HBase/hbase(用了这个命令解锁后的文件缺失)

正确命令:

sudochmoda+w/home/liu/HBase/hbase-1.4.12

sudochmoda+w/home/liu/HBase/hbase-1.4.12/lib

4.配置环境变量

sudogedit/etc/profile

exportJAVA_HOME=/home/liu/文档/Java/jdk1.8.0_161

exportJRE_HOME=$JAVA_HOME/jre

exportHADOOP_HOME=/home/liu/Hadoop/hadoop

exportHBASE_HOME=/home/liu/HBase/hbase

exportCLASSPATH=.:

$JAVA_HOME/lib:

$JRE_HOME/lib:

$HBASE_HOME/lib:

$CLASSPATH

5.编辑完成后,再执行source命令使上述配置在当前终端立即生效,命令如下:

source/etc/profile

6.配置/home/liu/HBase/hbase/conf/hbase-env.sh。

exportJAVA_HOME=/home/liu/文档/Java/jdk1.8.0_161

exportHBASE_CLASSPATH=/home/liu/Hadoop/hadoop/conf

exportHBASE_MANAGES_ZK=true

 

7.配置/home/liu/HBase/hbase/conf/hbase-site.xml。

hbase.rootdir

hdfs:

//localhost:

9000/hbase

hbase.cluster.distributed

true

8.确保hadoop启动成功,这里虚拟机再不用之后一直挂起,没重启过,所以hadoop已经启动。

若没启动,进入hadoop文件夹下,执行命令:

./sbin/start-dfs.sh

9.切换目录至hbase文件夹下,再启动HBase。

命令如下:

bin/start-hbase.sh

用jps命令查看下,比较幸运,hbase一次启动成功了。

10.完成题目。

进入Shell界面:

bin/hbaseshell

student学生表

name

score

English

Math

Computer

zhangsan

69

86

77

lisi

55

100

88

(1)根据上面给出的表格,用HbaseShell模式设计student学生表格。

create'student','name','score'

put'student','zhangsan','score:

English','69'

put'student','zhangsan','score:

Math','86'

put'student','zhangsan','score:

Computer','77'

put'student','lisi','score:

English','55'

put'student','lisi','score:

Math','100'

put'student','lisi','score:

Computer','88'

(2)设计完后,用scan指令浏览表的相关信息,给出截图。

scan'student'

(3)查询zhangsan的Computer成绩。

给出截图。

get'student','zhangsan',{COLUMN=>'score:

Computer'}

(4)修改lisi的Math成绩,改为95。

给出截图。

put'student','lisi','score:

Math','95'

get'student','lisi',{COLUMN=>'score:

Math'}

 

(5)根据上面已经设计出的student,用HbaseAPI编程。

添加数据:

English:

45Math:

89Computer:

100

scofield

45

89

100

导入所需jar包,右击项目HBaseExample,选中最下方Properties->选中右侧菜单栏中的JavaBuildPath->中间Libraries->右方AddExternalJARS...

这里只需要导入hbase安装目录中的lib文件中的所有jar包。

运行项目后,scan‘student’检查。

 

(6)获取scofield的English成绩信息。

源代码:

importorg.apache.hadoop.conf.Configuration;

importorg.apache.hadoop.hbase.*;

importorg.apache.hadoop.hbase.client.*;

importorg.apache.hadoop.hbase.util.Bytes;

importjava.io.IOException;

publicclassHBaseExample{

publicstaticConfigurationconfiguration;

publicstaticConnectionconnection;

publicstaticAdminadmin;

publicstaticvoidmain(String[]args)throwsIOException{

BasicConfigurator.configure();//自动快速地使用缺省Log4j环境

insertRow("student","scofield","score","English","45");

insertRow("student","scofield","score","Math","89");

insertRow("student","scofield","score","Computer","100");

getData("student","scofield","score","English");

}

//建立连接

publicstaticvoidinit(){

configuration=HBaseConfiguration.create();

configuration.set("hbase.rootdir","hdfs:

//localhost:

9000/hbase");

try{

connection=ConnectionFactory.createConnection(configuration);

admin=connection.getAdmin();

}catch(IOExceptione){

e.printStackTrace();

}

}

//关闭连接

publicstaticvoidclose(){

try{

if(admin!

=null){

admin.close();

}

if(null!

=connection){

connection.close();

}

}catch(IOExceptione){

e.printStackTrace();

}

}

publicstaticvoidinsertRow(StringtableName,StringrowKey,StringcolFamily,Stringcol,Stringval)throwsIOException{

init();

Tabletable=connection.getTable(TableName.valueOf(tableName));

Putput=newPut(rowKey.getBytes());

put.addColumn(colFamily.getBytes(),col.getBytes(),val.getBytes());

table.put(put);

table.close();

close();

}

publicstaticvoidgetData(StringtableName,StringrowKey,StringcolFamily,Stringcol)throwsIOException{

init();

Tabletable=connection.getTable(TableName.valueOf(tableName));

Getget=newGet(rowKey.getBytes());

get.addColumn(colFamily.getBytes(),col.getBytes());

Resultresult=table.get(get);

System.out.println(result);

showCell(result);

table.close();

close();

}

publicstaticvoidshowCell(Resultresult){

Cell[]cells=result.rawCells();

for(Cellcell:

cells){

System.out.println("RowName:

"+newString(CellUtil.cloneRow(cell))+"");

System.out.println("Timetamp:

"+cell.getTimestamp()+"");

System.out.println("columnFamily:

"+newString(CellUtil.cloneFamily(cell))+"");

System.out.println("rowName:

"+newString(CellUtil.cloneQualifier(cell))+"");

System.out.println("value:

"+newString(CellUtil.cloneValue(cell))+"");

}

}

}

 

五、实验心得与体会

理解了HBase在Hadoop体系结构中的角色,熟练使用HBase操作常用的Shell命令,熟悉HBase操作常用的JavaAPI。

碰到的问题:

log4j:

WARNNoappenderscouldbefoundforlogger(org.apache.hadoop.metrics2.lib.MutableMetricsFactory).

log4j:

WARNPleaseinitializethelog4jsystemproperly.

log4j:

WARNSeehttp:

//logging.apache.org/log4j/1.2/faq.html#noconfigformoreinfo.

解决方法:

自动快速地使用缺省Log4j环境。

将下面方法插入到入口点Main方法处,是一个快速的系统配置。

作用是与log4j.properties快速关联起来,自动快速地使用缺省Log4j环境。

BasicConfigurator.configure();//自动快速地使用缺省Log4j环境

这样就百分之百可以解决log4j的报错问题了。

原文链接:

 

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 表格模板 > 合同协议

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2