windows系统通过eclipse远程MapReduce服务器
来源:互联网 发布:ios 元数据丢失 编辑:程序博客网 时间:2024/06/06 15:48
本文主要介绍在windows系统中通过eclipse编写MapReduce程序,远程访问Hadoop服务器。前提是Linux服务器中已经部署成功hadoop环境。
windows中安装hadoop
将hadoop-2.7.1.tar.gz文件解压到windows硬盘中(如:C:\Program Files\hadoop-2.7.1)。
将hadoop2.7.1_win_bin文件夹中hadoop.dll和winutils.exe复制到上述安装目录的bin路径下。
hadoop2.7.1_win_bin下载地址http://pan.baidu.com/s/1qYK6EZE 密码:cmsd
配置环境变量:将hadoop的bin目录配置到系统环境变量中。
eclipse中建立MapReduce程序
- 新建java project(注意不是MapReduce Project),将hadoop目录及子目录的jar添加到build path中。
- 新建MapReduce程序(如:WordCount)
package com.mr.test;import java.io.IOException;import java.util.StringTokenizer;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.Partitioner;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.mapreduce.lib.partition.HashPartitioner;import org.apache.hadoop.util.GenericOptionsParser;public class WordCount { public static class TokenizerMapper extends Mapper<Object, Text, Text, IntWritable> { private final static IntWritable one = new IntWritable(1); private Text word = new Text(); public void map(Object key, Text value, Context context) throws IOException, InterruptedException { StringTokenizer itr = new StringTokenizer(value.toString()); while (itr.hasMoreTokens()) { word.set(itr.nextToken()); context.write(word, one); } } } public static class WordCountPartitioner extends Partitioner<Text, IntWritable> { @Override public int getPartition(Text arg0, IntWritable arg1, int arg2) { // TODO Auto-generated method stub char ch = arg0.toString().charAt(0); if (ch > 'J') { return 0; } else { return 1; } } } public static class IntSumReducer extends Reducer<Text, IntWritable, Text, IntWritable> { private IntWritable result = new IntWritable(); public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException { int sum = 0; for (IntWritable val : values) { sum += val.get(); } result.set(sum); context.write(key, result); } } public static void main(String[] args) throws Exception { System.setProperty("hadoop.home.dir", "C:\\Program Files\\hadoop-2.7.1"); Configuration conf = new Configuration(); String[] otherArgs = new GenericOptionsParser(conf, args) .getRemainingArgs(); if (otherArgs.length != 2) { System.err.println("Usage: wordcount <in> <out>"); System.exit(2); } Job job = new Job(conf, "word count"); job.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, new Path(otherArgs[0])); FileOutputFormat.setOutputPath(job, new Path(otherArgs[1])); job.setNumReduceTasks(2); job.setPartitionerClass(WordCountPartitioner.class); System.exit(job.waitForCompletion(true) ? 0 : 1); }}
3 Run As Configution配置远程服务器的HDFS输入路径及输出路径
4 执行成功。
阅读全文
1 0
- windows系统通过eclipse远程MapReduce服务器
- windows 实现本地Eclipse远程调试MapReduce
- 浪潮服务器通过BMC远程安装系统
- windows下eclipse远程调试hadoop2.7.2,debug mapreduce
- windows下eclipse远程提交hadoop 2.5.2 Mapreduce任务
- windows下eclipse远程操作hadoop集群执行mapreduce
- eclipse远程调试mapreduce程序
- 在 Eclipse 中通过 SSH 密钥登录远程服务器
- windows通过VNC访问远程ubuntu14.04 server服务器
- windows 系统远程访问windows 服务器,进行文件传输
- 使用Windows系统远程连接Windows server服务器
- 使用Windows系统远程连接Windows server服务器
- windows下通过eclipse进行远程执行出错:Permission denied:
- 通过Windows的远程桌面连接远程Ubuntu系统
- windows通过 VNC 远程连接树莓派3 (raspbian系统)
- Win系统下用Eclipse中运行远程hadoop MapReduce程序出现Permission denied错误
- 使用OS X系统远程连接Windows Server服务器
- 怎么在windows系统中远程控制服务器
- React Native在Windows下的安装及环境配置(Android)
- Wavio Sequence UVA
- django模型层
- 数据结构与算法分析 ——回溯算法之收费公路重建问题
- SD卡与fatfs文件系统(2)
- windows系统通过eclipse远程MapReduce服务器
- git学习笔记(三)
- Struts2 同ajax发送多个id到后台,进行批量删除
- parity
- hdu 1078 FatMouse and Cheese【dfs+dp】
- 31对象2---string
- SD卡与fatfs文件系统(3)
- Linux C 字符串输入函数 gets()、fgets()、scanf() 详解
- 关于缓存的那些传说