《hadoop经典教程》PPT课件.ppt_第1页
《hadoop经典教程》PPT课件.ppt_第2页
《hadoop经典教程》PPT课件.ppt_第3页
《hadoop经典教程》PPT课件.ppt_第4页
《hadoop经典教程》PPT课件.ppt_第5页
已阅读5页,还剩14页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Hadoop使用,outline,云计算概念Hadoop使用Mapreduce详解,1云计算概念,概念狭义云计算是指IT基础设施的交付和使用模式,通过网络以按需、易扩展的方式获得所需的资源(硬件、平台、软件)。广义云计算是指服务的交付和使用模式,通过网络以按需、易扩展的方式获得所需的服务。这种服务可以是IT和软件、互联网相关的,也可以是任意其他的服务。三层模型Saas:morePaas:hadoopIaas:openstack,2019/11/19,googlevshadoop,2Hadoop使用,编写map和reduce函数运行测试命令行运行eclipse运行查看结果,2019/11/19,map,publicstaticclassTokenizerMapperextendsMapperprivatefinalstaticIntWritableone=newIntWritable(1);privateTextword=newText();publicvoidmap(Objectkey,Textvalue,Contextcontext)throwsIOException,InterruptedExceptionStringTokenizeritr=newStringTokenizer(value.toString();while(itr.hasMoreTokens()word.set(itr.nextToken();context.write(word,one);/设置keyvalue说明:map的输出key、value和reduce的输入key、value要一致,见上面红色部分,reduce,publicstaticclassIntSumReducerextendsReducerprivateIntWritableresult=newIntWritable();publicvoidreduce(Textkey,Iterablevalues,Contextcontext)throwsIOException,InterruptedExceptionintsum=0;for(IntWritableval:values)sum+=val.get();/聚集操作result.set(sum);context.write(key,result);说明:map的输出key、value和reduce的输入key、value要一致,见上面红色部分,2019/11/19,Job配置,publicstaticvoidmain(Stringargs)throwsExceptionConfigurationconf=newConfiguration();StringotherArgs=newGenericOptionsParser(conf,args).getRemainingArgs();if(otherArgs.length!=2)System.err.println(Usage:wordcount);System.exit(2);Jobjob=newJob(conf,wordcount);/jobnamejob.setJarByClass(WordCount.class);job.setMapperClass(TokenizerMapper.class);job.setCombinerClass(IntSumReducer.class);job.setReducerClass(IntSumReducer.class);job.setOutputKeyClass(Text.class);job.setOutputValueClass(IntWritable.class);FileInputFormat.addInputPath(job,newPath(otherArgs0);/fileinputFileOutputFormat.setOutputPath(job,newPath(otherArgs1);/fileoutputSystem.exit(job.waitForCompletion(true)?0:1);,2019/11/19,2Hadoop使用,编写map和reduce函数运行测试命令行运行eclipse运行查看结果,命令行运行,打包mapreduce函数,wordcount.jar设类名WordCount进入hadoop安装目录$bin/hadoopjar本地jar包目录类名hdfs输入文件目录hdfs输入文件目录例子:$bin/hadoopjar/home/deke/wordcount.jarWordCounthdfs输入文件目录hdfs输入文件目录,2019/11/19,2Hadoop使用,编写map和reduce函数运行测试命令行运行eclipse运行查看结果,Eclipse配置,1.下载eclipse2.将hadoop文件夹下的contrib/eclipse-plugin/hadoop-*-eclipse-plugin.jar拷贝到eclipse文件夹下的/plugins文件夹里3.启动Eclipse4.设置Hadoop安装文件夹的路径Window-Preferences,见下一页,Eclipse配置,2Hadoop使用,编写map和reduce函数运行测试命令行运行eclipse运行查看结果61:50030/jobtracker.jsp61:50070/dfshealth.jsp,3Mapreduce详解,程序流程例子1,3Mapreduce详解,程序流程例子2,直接访问hdfs文件接口,1程序如果我们只需要访问文件系统,而不需要对文件中的数据进行处理,那么只需要使用下面的访问hdfs的接口就行了。而不需要编写mapreduce函数Stringdir=/user/nz/btc/pvint;/theinputdirectoryConfigurationconf=newConfiguration();/getconfFileSystemfs=FileSystem.get(conf);Pathpath=newPath(dir);/getthedirectoryFileStatusstat=fs.getFileStatus(path);/getdirectoryFileStatusfilelist=fs.listStatus(path);/getfilelistfor(FileStatuslist:filelist)Stringfilename=list.getPath().getName();System.out.println(result:+filename);,2019/11/19,直接访问hdfs文件接口,2命令行上传文件到hdfs:bin/hadoopfs-copyFromLocal本地文件/目录hdfs文件目录下载到本地:bin/hadoopfs-copyToLocalhdfs文件目录本地文件/目录,2019/11/19,参考文献,JefferyDean,SanjayGhemawat.:MapReduce:Simplifieddataprocessingonlargeclusters.OSDI,SanFrancisco,CA,20

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论