win7 eclipse调用虚拟机ubuntu部署的hadoop2.2.0伪分布(1)

2023-12-08 16:38

本文主要是介绍win7 eclipse调用虚拟机ubuntu部署的hadoop2.2.0伪分布(1),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

所用软件下载网址:链接:http://pan.baidu.com/s/1bn4IIQF密码:ramg

win7环境下jdk下载路径(/jdk/jdk-7u71-windows-i586.exe)

eclipse下载路径(/eclipse/eclipse-jee-indigo-SR2-win32.zip)

hadoop插件下载路径(/hadoop/eclipse插件/hadoop2x-eclipse-plugin.zip)

此片文章原文链接:http://www.linuxidc.com/Linux/2014-09/106148p2.htm,

注:

(1)本人使用的是/home/tom/hadoop-2.2.0,/usr/mywind/hadoop路径替换为/home/tom/hadoop-2.2.0即可

(2)创建用户此文用的是a01513,替换为tom即可

(3)IP地址自行修改

1、基于Eclipse的Hadoop2.x开发环境配置

关于JDK及ECLIPSE的安装我就不再介绍了,相信能玩Hadoop的人对这种配置都已经再熟悉不过了,如果实在不懂建议到谷歌百度去搜索一下教程。假设你已经把Hadoop的Eclipse插件下载下来了,然后解压把jar文件放到Eclipse的plugins文件夹里面:

 

重启Eclipse即可。

然后我们再安装Hadoop到Win7下,在这不再详细说明,跟安装JDK大同小异,在这个例子中我安装到了E:\hadoop。

启动Eclipse,点击菜单栏的【Windows/窗口】→【Preferences/首选项】→【Hadoop Map/Reduce】,把Hadoop Installation Directory设置成开发机上的Hadoop主目录:

 

点击OK。

开发环境配置完成,下面我们可以新建一个测试Hadoop项目,右键【NEW/新建】→【Others、其他】,选择Map/Reduce Project

 

输入项目名称点击【Finish/完成】:

 

创建完成后可以看到如下目录:

 

然后在SRC下建立下面包及类:

 

以下是代码内容:

TestMapper.javapackage com.my.hadoop.mapper;import java.io.IOException;import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.Mapper;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reporter;public class TestMapper extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> {private static final int MISSING = 9999;private static final Log LOG = LogFactory.getLog(TestMapper.class);public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output,Reporter reporter)throws IOException {String line = value.toString();String year = line.substring(15, 19);int airTemperature;if (line.charAt(87) == '+') { // parseInt doesn't like leading plus signsairTemperature = Integer.parseInt(line.substring(88, 92));} else {airTemperature = Integer.parseInt(line.substring(87, 92));}LOG.info("loki:"+airTemperature);String quality = line.substring(92, 93);LOG.info("loki2:"+quality);if (airTemperature != MISSING && quality.matches("[012459]")) {LOG.info("loki3:"+quality);output.collect(new Text(year), new IntWritable(airTemperature));}}}TestReducer.javapackage com.my.hadoop.reducer;import java.io.IOException;
import java.util.Iterator;import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reporter;
import org.apache.hadoop.mapred.Reducer;public class TestReducer extends MapReduceBase implements Reducer<Text, IntWritable, Text, IntWritable> {@Overridepublic void reduce(Text key, Iterator<IntWritable> values, OutputCollector<Text, IntWritable> output,Reporter reporter)throws IOException{int maxValue = Integer.MIN_VALUE;while (values.hasNext()) {maxValue = Math.max(maxValue, values.next().get());}output.collect(key, new IntWritable(maxValue));}}TestHadoop.javapackage com.my.hadoop.test.main;import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.FileInputFormat;
import org.apache.hadoop.mapred.FileOutputFormat;
import org.apache.hadoop.mapred.JobClient;
import org.apache.hadoop.mapred.JobConf;import com.my.hadoop.mapper.TestMapper;
import com.my.hadoop.reducer.TestReducer;public class TestHadoop {public static void main(String[] args) throws Exception{if (args.length != 2) {System.err.println("Usage: MaxTemperature <input path> <output path>");System.exit(-1);}JobConf job = new JobConf(TestHadoop.class);job.setJobName("Max temperature");FileInputFormat.addInputPath(job, new Path(args[0]));FileOutputFormat.setOutputPath(job, new Path(args[1]));job.setMapperClass(TestMapper.class);job.setReducerClass(TestReducer.class);job.setOutputKeyClass(Text.class);job.setOutputValueClass(IntWritable.class);JobClient.runJob(job);}}

为了方便对于Hadoop的HDFS文件系统操作,我们可以在Eclipse下面的Map/Reduce Locations窗口与Hadoop建立连接,直接右键新建Hadoop连接即可:

连接配置如下:

其中,Location name可任意填写,Mapreduce Master中Host为resourcemanager机器ip,Port为resourcemanager接受任务的端口号,即yarn-site.xml文件中yarn.resourcemanager.scheduler.address配置项中端口号。DFS Master中的Host为namenode机器ip,Port为core-site.xml文件中fs.defaultFS配置项中端口号。

然后点击完成即可,新建完成后,我们可以在左侧目录中看到HDFS的文件系统目录:

这里不仅可以显示目录结构,还可以对文件及目录进行删除、新增等操作,非常方便。

当上面的工作都做好之后,就可以把这个项目导出来了(导成jar文件放到Hadoop服务器上运行):

点击完成,然后把这个testt.jar文件上传到Hadoop服务器(192.168.8.184)上,目录(其实可以放到其他目录,你自己喜欢)是:

/usr/mywind/hadoop/share/hadoop/mapreduce

如下图:

 

2、运行Hadoop程序及查看运行日志

当上面的工作准备好了之后,我们运行自己写的Hadoop程序很简单:

$ hadoop  jar  /usr/mywind/hadoop/share/hadoop/mapreduce/testt.jar com.my.hadoop.test.main.TestHadoop  input  output

注意这是output文件夹名称不能重复哦,假如你执行了一次,在HDFS文件系统下面会自动生成一个output文件夹,第二次运行时,要么把output文件夹先删除($ hdfs dfs -rmr /user/a01513/output),要么把命令中的output改成其他名称如output1、output2等等。

如果看到以下输出结果,证明你的运行成功了:

a01513@hadoop :~$ hadoop jar /usr/mywind/hadoop/share/hadoop/mapreduce/testt.jar                                                                              com.my.hadoop.test.main.TestHadoop input output
14/09/02 11:14:03 INFO client.RMProxy: Connecting to ResourceManager at /0.0.0.0                                                                            :8032
14/09/02 11:14:04 INFO client.RMProxy: Connecting to ResourceManager at /0.0.0.0                                                                            :8032
14/09/02 11:14:04 WARN mapreduce.JobSubmitter: Hadoop command-line option parsin                                                                            g not performed. Implement the Tool interface and execute your application with                                                                              ToolRunner to remedy this.
14/09/02 11:14:04 INFO mapred.FileInputFormat: Total input paths to process : 1
14/09/02 11:14:04 INFO mapreduce.JobSubmitter: number of splits:2
14/09/02 11:14:05 INFO mapreduce.JobSubmitter: Submitting tokens for job: job_14                                                                            09386620927_0015
14/09/02 11:14:05 INFO impl.YarnClientImpl: Submitted application application_14                                                                            09386620927_0015
14/09/02 11:14:05 INFO mapreduce.Job: The url to track the job: http://hadoop:80                                                                            88/proxy/application_1409386620927_0015/
14/09/02 11:14:05 INFO mapreduce.Job: Running job: job_1409386620927_0015
14/09/02 11:14:12 INFO mapreduce.Job: Job job_1409386620927_0015 running in uber mode : false
14/09/02 11:14:12 INFO mapreduce.Job:  map 0% reduce 0%
14/09/02 11:14:21 INFO mapreduce.Job:  map 100% reduce 0%
14/09/02 11:14:28 INFO mapreduce.Job:  map 100% reduce 100%
14/09/02 11:14:28 INFO mapreduce.Job: Job job_1409386620927_0015 completed successfully
14/09/02 11:14:29 INFO mapreduce.Job: Counters: 49File System CountersFILE: Number of bytes read=105FILE: Number of bytes written=289816FILE: Number of read operations=0FILE: Number of large read operations=0FILE: Number of write operations=0HDFS: Number of bytes read=1638HDFS: Number of bytes written=10HDFS: Number of read operations=9HDFS: Number of large read operations=0HDFS: Number of write operations=2Job CountersLaunched map tasks=2Launched reduce tasks=1Data-local map tasks=2Total time spent by all maps in occupied slots (ms)=14817Total time spent by all reduces in occupied slots (ms)=4500Total time spent by all map tasks (ms)=14817Total time spent by all reduce tasks (ms)=4500Total vcore-seconds taken by all map tasks=14817Total vcore-seconds taken by all reduce tasks=4500Total megabyte-seconds taken by all map tasks=15172608Total megabyte-seconds taken by all reduce tasks=4608000Map-Reduce FrameworkMap input records=9Map output records=9Map output bytes=81Map output materialized bytes=111Input split bytes=208Combine input records=0Combine output records=0Reduce input groups=1Reduce shuffle bytes=111Reduce input records=9Reduce output records=1Spilled Records=18Shuffled Maps =2Failed Shuffles=0Merged Map outputs=2GC time elapsed (ms)=115CPU time spent (ms)=1990Physical memory (bytes) snapshot=655314944Virtual memory (bytes) snapshot=2480295936Total committed heap usage (bytes)=466616320Shuffle ErrorsBAD_ID=0CONNECTION=0IO_ERROR=0WRONG_LENGTH=0WRONG_MAP=0WRONG_REDUCE=0File Input Format CountersBytes Read=1430File Output Format CountersBytes Written=10
a01513@hadoop :~$

我们可以到Eclipse查看输出的结果:

或者用命令行查看:

$ hdfs dfs -cat output/part-00000

假如你们发现运行后结果是为空的,可能到日志目录查找相应的log.info输出信息,log目录在:/usr/mywind/hadoop/logs/userlogs 下面。

 

 



这篇关于win7 eclipse调用虚拟机ubuntu部署的hadoop2.2.0伪分布(1)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/470580

相关文章

ubuntu如何部署Dify以及安装Docker? Dify安装部署指南

《ubuntu如何部署Dify以及安装Docker?Dify安装部署指南》Dify是一个开源的大模型应用开发平台,允许用户快速构建和部署基于大语言模型的应用,ubuntu如何部署Dify呢?详细请... Dify是个不错的开源LLM应用开发平台,提供从 Agent 构建到 AI workflow 编排、RA

ubuntu系统使用官方操作命令升级Dify指南

《ubuntu系统使用官方操作命令升级Dify指南》Dify支持自动化执行、日志记录和结果管理,适用于数据处理、模型训练和部署等场景,今天我们就来看看ubuntu系统中使用官方操作命令升级Dify的方... Dify 是一个基于 docker 的工作流管理工具,旨在简化机器学习和数据科学领域的多步骤工作流。

如何在Ubuntu上安装NVIDIA显卡驱动? Ubuntu安装英伟达显卡驱动教程

《如何在Ubuntu上安装NVIDIA显卡驱动?Ubuntu安装英伟达显卡驱动教程》Windows系统不同,Linux系统通常不会自动安装专有显卡驱动,今天我们就来看看Ubuntu系统安装英伟达显卡... 对于使用NVIDIA显卡的Ubuntu用户来说,正确安装显卡驱动是获得最佳图形性能的关键。与Windo

ubuntu16.04如何部署dify? 在Linux上安装部署Dify的技巧

《ubuntu16.04如何部署dify?在Linux上安装部署Dify的技巧》随着云计算和容器技术的快速发展,Docker已经成为现代软件开发和部署的重要工具之一,Dify作为一款优秀的云原生应用... Dify 是一个基于 docker 的工作流管理工具,旨在简化机器学习和数据科学领域的多步骤工作流。它

Nginx部署React项目时重定向循环问题的解决方案

《Nginx部署React项目时重定向循环问题的解决方案》Nginx在处理React项目请求时出现重定向循环,通常是由于`try_files`配置错误或`root`路径配置不当导致的,本文给大家详细介... 目录问题原因1. try_files 配置错误2. root 路径错误解决方法1. 检查 try_f

双系统电脑中把Ubuntu装进外接移动固态硬盘的全过程

《双系统电脑中把Ubuntu装进外接移动固态硬盘的全过程》:本文主要介绍如何在Windows11系统中使用VMware17创建虚拟机,并在虚拟机中安装Ubuntu22.04桌面版或Ubunt... 目录一、首先win11中安装vmware17二、磁盘分区三、保存四、使用虚拟机进行系统安装五、遇见的错误和解决

Java调用Python的四种方法小结

《Java调用Python的四种方法小结》在现代开发中,结合不同编程语言的优势往往能达到事半功倍的效果,本文将详细介绍四种在Java中调用Python的方法,并推荐一种最常用且实用的方法,希望对大家有... 目录一、在Java类中直接执行python语句二、在Java中直接调用Python脚本三、使用Run

Python如何调用指定路径的模块

《Python如何调用指定路径的模块》要在Python中调用指定路径的模块,可以使用sys.path.append,importlib.util.spec_from_file_location和exe... 目录一、sys.path.append() 方法1. 方法简介2. 使用示例3. 注意事项二、imp

CentOS和Ubuntu系统使用shell脚本创建用户和设置密码

《CentOS和Ubuntu系统使用shell脚本创建用户和设置密码》在Linux系统中,你可以使用useradd命令来创建新用户,使用echo和chpasswd命令来设置密码,本文写了一个shell... 在linux系统中,你可以使用useradd命令来创建新用户,使用echo和chpasswd命令来设

C#如何调用C++库

《C#如何调用C++库》:本文主要介绍C#如何调用C++库方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录方法一:使用P/Invoke1. 导出C++函数2. 定义P/Invoke签名3. 调用C++函数方法二:使用C++/CLI作为桥接1. 创建C++/CL