博客
关于我
第2.1.3章 hadoop之eclipse远程调试hadoop
阅读量:307 次
发布时间:2019-03-01

本文共 1511 字,大约阅读时间需要 5 分钟。

Hadoop环境配置及WordCount示例

Eclipse配置

在Eclipse中进行Hadoop插件配置,首先将hadoop-common-project的winutils.exe复制到本地Hadoop的$HADOOP_HOME/bin目录,hadoop.dll则复制到%windir%\System32目录。启动Eclipse后,通过菜单选择“Window > Show View > Other > Map/Reduce Tools > Map/Reduce Locations”进行配置,完成后即可连接到远程DFS。

Windows环境配置

在Windows系统上设置Hadoop环境变量,通常不需要手动配置本地Hadoop即可使用。将winutils.exe和hadoop.dll分别放置在对应的路径下,确保环境变量HADOOP_HOME正确指向Hadoop安装目录。

WordCount示例运行

创建一个Maven项目,引入相关的Hadoop依赖。将core-site.xmlhdfs-site.xmlmapred-site.xmlyarn-site.xml文件复制到项目的src/main/resources目录。将WordCount源码导入项目,编译并将JAR打包为testWordCount.jar

在运行配置中,修改主类的代码,添加输入输出路径。例如,输入文件路径设置为hdfs://192.168.5.174:9000/user/hadoop/testdata/test.log,输出目录设为hdfs://192.168.5.174:9000/user/hadoop/testdata/output2。运行后,可在输出目录查看结果文件。

import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.fs.FileSystem;import org.apache.hadoop.fs.Path;import java.io.IOException;public class WordCountMain {    public static void main(String[] args) throws IOException {        String inputPath = "hdfs://192.168.5.174:9000/user/hadoop/testdata/test.log";        String outputPath = "hdfs://192.168.5.174:9000/user/hadoop/testdata/output2";                Configuration conf = new Configuration();        FileSystem fs = FileSystem.get(URI.create(inputPath), conf);                Path outputPath = new Path(outputPath);        if (!outputPath.exists(fs, new ProgressableIOException())) {            fs.mkdirs(fs, new Path(outputPath), fs.getPermission(), true);        }                // 类似于上述代码,添加其他操作逻辑    }}

转载地址:http://kawo.baihongyu.com/

你可能感兴趣的文章
nmap指纹识别要点以及又快又准之方法
查看>>
Nmap渗透测试指南之指纹识别与探测、伺机而动
查看>>
Nmap端口扫描工具Windows安装和命令大全(非常详细)零基础入门到精通,收藏这篇就够了
查看>>
NMAP网络扫描工具的安装与使用
查看>>
NMF(非负矩阵分解)
查看>>
nmon_x86_64_centos7工具如何使用
查看>>
NN&DL4.1 Deep L-layer neural network简介
查看>>
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.7 Parameters vs Hyperparameters
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
nnU-Net 终极指南
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>