126电影网,机械公敌下载,房屋贷款计算器最新2013
目录
@
hadoop所用安装包和配置文件等我找到最方便使用的方式再上传到博客,如果有需要也欢迎找我分享。
在windows下,
我用的是破解版的文件,不需要安装,直接解压到d盘下
我的电脑——>属性——>高级系统设置——>环境变量——>系统变量——>编辑path,增加 %hadoop_home%\bin ——>新建一个变量名为 hadoop_home,变量值为 hadoop安装路径的系统变量——>确定操作——>完成
找到系统变量,编辑path
加上 %hadoop_home%\bin即可
确定之后,新建一个系统变量
然后依次确定刚才的操作,配置环境变量工作完成。
路径:c:\windows\system32
先在本地电脑写一个txt文件,内容随便输入,
如:
(检测这里将程序复制过去就可以,先不用理解,后续学习)
package com.oracle.demo.mr; import org.apache.hadoop.fs.path; import org.apache.hadoop.io.intwritable; import org.apache.hadoop.io.longwritable; import org.apache.hadoop.io.text; import org.apache.hadoop.mapreduce.job; import org.apache.hadoop.mapreduce.mapper; import org.apache.hadoop.mapreduce.reducer; import org.apache.hadoop.mapreduce.lib.input.fileinputformat; import org.apache.hadoop.mapreduce.lib.output.fileoutputformat; import java.io.ioexception; public class wordcount { public class wcmapper extends mapper<longwritable,text,text,intwritable> { @override protected void map(longwritable key, text value, context context) throws ioexception, interruptedexception { string line = value.tostring(); string[] strs = line.split(" "); for (string s:strs){ text outkey = new text(s); intwritable outvalue = new intwritable(1); context.write(outkey,outvalue); } } } public class wcreduce extends reducer<text,intwritable,text,intwritable> { @override protected void reduce(text key, iterable<intwritable> values, context context) throws ioexception, interruptedexception { int count = 0; for (intwritable n:values){ count += n.get(); } context.write(key,new intwritable(count)); } } public static void main(string[] args) throws ioexception, classnotfoundexception, interruptedexception { job job = job.getinstance(); job.setmapoutputkeyclass(text.class); job.setmapoutputvalueclass(intwritable.class); job.setmapoutputkeyclass(text.class); job.setmapoutputvalueclass(intwritable.class); job.setmapperclass(com.oracle.demo.mr.wcmapper.class); job.setreducerclass(com.oracle.demo.mr.wcreduce.class); fileinputformat.setinputpaths(job,new path("e:\\bigdata\\input.txt")); fileoutputformat.setoutputpath(job,new path("e:\\bigdata\\output")); job.waitforcompletion(true); } }
注意:
运行之后控制台显示:
。。。
。。。
表示运行成功,没有错误
结果是:
此刻,表示hadoop安装成功,大功告成了。
exception in thread "main" org.apache.hadoop.mapred.filealreadyexistsexception: output directory file:/e:/bigdata/output already exists
如何解决:之前运行的输出文件删除即可。
这篇博客是我自己安装完之后写出来的,如果过程中有什么疏漏或者疑问,欢迎和我交流。安装过程中也许会遇到一些自己解决不了的错误,不要急躁,慢慢找方法解决就好了,希望你能成为一个优秀的程序员。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
去 HBase,Kylin on Parquet 性能表现如何?
如何找到Hive提交的SQL相对应的Yarn程序的applicationId
如何在 HBase Shell 命令行正常查看十六进制编码的中文?哈哈~
HBase Filter 过滤器之 Comparator 原理及源码学习
安装 Hadoop 2.9.1 on Windows 10 64 bit (最全步骤整理)
网友评论