单机环境下伪分布式集群环境搭建请参考:http://blog.csdn.net/xiaoyi52/article/details/43528563。
本文将介绍第一个hadoop程序具体怎么运行。
运行环境为ubuntu14.04+eclipse+hadoop2.2.0。
本文运行第一个程序出自参考资料1,部分细节根据实际情况修改,说明如下:
1.hadoop插件根据对应的版本下载,如本文使用hadoop2.2.0,下载的也是2.2.0版本的插件。
2.hadoop2.2.0自带的WorldCount在$HADOOP_HOME/share/hadoop/mapreduce/sourceshadoop-mapreduce-examples-2.2.0-sources.jar包中。
3.两个版本的例子具体代码略有不同,将当前版本的代码拷贝到eclipse中之后,直接运行会报错,找不到输入文件。此时需要添加两行代码,也是参考文章中特意说明过的地方。不过此处修改如下(标红的部分):
Configuration conf = new Configuration();
conf.set("fs.default.name","hdfs://localhost:9000");
String[] ars=new String[]{"input","output"};
String[] otherArgs = new GenericOptionsParser(conf, ars).getRemainingArgs();
if (otherArgs.length != 2) {
System.err.println("Usage: wordcount <in> <out>");
System.exit(2);
}
此处conf是读的是hadoop配置文件,其中fs的位置需要重新显示指明(参考资料2)。
修改之后即可运行,输出结果可以通过浏览器查看,地址如下http://localhost:50070/dfshealth.jsp;也可通过eclipse中hdfs文件系统查看。
参考资料
[1]http://www.cnblogs.com/xia520pi/archive/2012/05/20/2510723.html
[2]http://blog.csdn.net/duguduchong/article/details/8712733