windows 开发mapreduce程序的配置
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了windows 开发mapreduce程序的配置,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3641字,纯文字阅读大概需要6分钟。
内容图文
![windows 开发mapreduce程序的配置](/upload/InfoBanner/zyjiaocheng/923/9c92d96898044913a5717a4a08bc6013.jpg)
第一:下载所有hadoop二进制包
第二:将所有的jar 做成user libary
第三:设置二个环境变量
HADOOP_HOME=D:\hadoop-2.7.6
HADOOP_USER_NAME=hdfs
package com.jsptpd.test1314; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.IntWritable; 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 org.apache.hadoop.util.GenericOptionsParser; import java.io.IOException; import java.util.StringTokenizer; public class WordCount { private static String PATH_TO_CORE_SITE_XML = "D:\\workspace_scala1\\test1314\\conf\\core-site.xml"; private static String PATH_TO_YARN_SITE_XML = "D:\\workspace_scala1\\test1314\\conf\\yarn-site.xml"; private static String PATH_TO_MAP_SITE_XML = "D:\\workspace_scala1\\test1314\\conf\\mapred-site.xml"; private static String PATH_TO_HDFS_SITE_XML = "D:\\workspace_scala1\\test1314\\conf\\hdfs-site.xml"; public static void main(String[] args) throws Exception { //设置hadoop运行用户 System.setProperty("HADOOP_USER_NAME", "hdfs"); //获取默认配置信息 Configuration conf = new Configuration(); //conf.addResource(new Path(PATH_TO_HDFS_SITE_XML)); //增加hadoop的配置信息 conf.addResource(new Path(PATH_TO_CORE_SITE_XML)); //重新加载mapreduce配置包 conf.set("mapreduce.application.framework.path", "file:///D:/mapreduce.tar.gz"); //conf.addResource(new Path(PATH_TO_YARN_SITE_XML)); //conf.addResource(new Path(PATH_TO_MAP_SITE_XML)); String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs(); if (otherArgs.length != 2) { System.err.println("Usage: wordcount"); System.exit(2); } Job job = Job.getInstance(conf); job.setJobName("WordCount"); job.setJarByClass(WordCount.class); job.setMapperClass(TokenizerMapper.class); job.setReducerClass(IntSumReducer.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(IntWritable.class); FileInputFormat.addInputPath(job, new Path(otherArgs[0])); FileOutputFormat.setOutputPath(job, new Path(otherArgs[1])); System.exit(job.waitForCompletion(true) ? 0 : 1); } public static class TokenizerMapper extends Mapper{ private final static IntWritable one = new IntWritable(1); private Text word = new Text(); @Override public void map(Object key, Text value, Context context) throws IOException, InterruptedException { //System.out.println(value.toString()); String cleanLine = value.toString().toLowerCase().replaceAll("[_|$#<>\\^=\\[\\]\\*\\\\,;,.\\-:()?!\"']", " "); System.out.println(cleanLine); StringTokenizer itr = new StringTokenizer(cleanLine," ",true); while (itr.hasMoreTokens()) { word.set(itr.nextToken().trim()); context.write(word, one); } } } public static class IntSumReducer extends Reducer{ private IntWritable result = new IntWritable(); public void reduce(Text key, Iterablevalues, Context context) throws IOException, InterruptedException { int sum = 0; for (IntWritable val : values) { sum += val.get(); } result.set(sum); context.write(key, result); } } }
第四:配置windos二制包:
只需要配置core-sit.xml
io.map.index.interval
内容总结
以上是互联网集市为您收集整理的windows 开发mapreduce程序的配置全部内容,希望文章能够帮你解决windows 开发mapreduce程序的配置所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。