1.下载eclipse插件
此插件只是方便我们在eclipse上查看hdfs集群上的数据而已。
1.1 下载对应版本的 hadoop-eclipse-plugin-XXX.jar
并将其复制到eclipse下的plugin的目录下,最后重启eclipse。
完成后会看到eclipse的
Window-->Show View-->Other
窗口
多了这么个东西
1.2配置hadoop location参数
2.下载hadoop在windows平台编译后的包
若你有linux的hadoop包,则还需要将linux版的lib和bin目录替换成windows平台编译的版本,其bin目录下一定得有winutils.exe这个文件
2.1 下载完成后得配置环境变量参数
HADOOP_HOME:
注意 HADOOP_HOME是在系统变量里配置
PATH:
完成之后在windows命令行中输入hadoop,出现如下提示则表明安装成功
3.测试效果
将本地hadoop目录下的 etc/log4j.properties文件放置于eclipse工程src下。
我测试的程序是气温最高最低值的统计。
3.1通过eclipse查看hdfs集群状态
切换到mapreduce模式
看直接查看
3.2测试用eclipse往集群上提交程序
1)读取/climate/input/ 下的所有数据 将最后结果输出到/climate/output/下
2)编写好Mapper、Reducer继承类 和Driver类的main方法
Driver代码
public static void main(String[] args) throws Exception{
Configuration conf = new Configuration();
Job job = Job.getInstance(conf);
job.setJarByClass(ClimateTemperature.class);
job.setMapperClass(ClimateTemperatureMapper.class);
job.setReducerClass(ClimateTemperatureReducer.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(IntWritable.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(ClimateBean.class);
Path outPath = new Path(args[1]);
FileSystem fs = FileSystem.get(conf);
if(fs.exists(outPath )){
fs.delete(outPath, true);
}
FileInputFormat.setInputPaths(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, outPath);
boolean res = job.waitForCompletion(true);
System.exit(res?0:1);
}
3)配置main方法接收参数
4)直接run main
远程提交成功!
3.3测试用eclipse直接跑本地程序
1)首先将java文件导出成普通jar包到E盘,再在G盘新建climate/input 并把数据手动放入至此文件夹
2)而后修改main方法里的某些参数
3)配置main方法接收参数
4)直接run main方法
本地运行成功!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)