大数据实验总结(六)--搭建Mapreduce(YARN)环境,运行Wordcount示例

本文档详细介绍了如何搭建MapReduce(YARN)环境,并通过运行Wordcount示例进行测试。首先,修改yarn-site.xml配置文件,然后启动HDFS和YARN服务。接着,创建HDFS上的input和output目录,上传测试文件并运行Wordcount程序。在运行过程中,注意每次运行前要清理输出目录,避免FileAlreadyExistsException错误。最后,成功运行并查看了输出结果。

搭建Mapreduce(YARN)环境

  • 修改yarn-site.xml文件:
cd /usr/local/hadoop/etc/hadoop/
vim yarn-site.xml

如图:
在这里插入图片描述
具体内容:

<!-- Site specific YARN configuration properties -->
<configuration>
  <property>
    <name>yarn.resourcemanager.hostname</name>
    <value>master</value>
  </property>
<property>
    <name>yarn.nodemanager.aux-services</name>
    <value>mapreduce_shuffle</value>
  </property>
<property>
<name>yarn.nodemanager.aux-services.mapreduce_shuffle.class </name>
<value>org.apache.hadoop.mapred.ShuffleHandler</value>
</property>
</configuration>


在这里插入图片描述
其中名称yarn.resourcemanager.hostname指的是ResourceManager机器所在的节点位置;名称yarn.nodemanager.aux-services在hadoop2.2.0版本中是mapreduce_shuffle.

测试YARN环境

  • 启动hdfs
    start-dfs.sh
  • 启动hdfs
    Start-yarn.sh
    使用浏览器打开页面:
http://master:8088/
或http://192.168.50.100:8088/

在这里插入图片描述

测试Mapreduce环境(运行Wordcount示例)

find /usr/local/hadoop -name *example*.jar
 //查找示例程序,目录名需根据自己环境适当调整。

在这里插入图片描述
在这里插入图片描述

  • 在HDFS上创建input目录
    hdfs dfs -mkdir input
  • 在HDFS上创建output目录
    hdfs dfs -mkdir output
  • 创建运行示例文档CountWord.txt并进行编写:
    在这里插入图片描述

例:


helol
123
hello world
hello java
hello html
hello css
hello c
hello c#
hello world
hello css
hello c
hello c#
hello world
hello css
hello css
hello css
hello c
hello c#
hello world

hello c
hello c#
hello world
hello c
hello c#
hello world
hello css
hello c
hello c#
hello world
hello css
hello c

  • 将CountWord.txt上传到HDFS中input目录下:
hdfs dfs -put CountWord.txt /input
  • 查看:
    hdfs dfs -ls /input
    在这里插入图片描述
  • 运行Wordcount示例程序:
    输入为:/input/CountWord.txt ,运行结果输出目录为: /output
hadoop jar /usr/local/hadoop/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.3.jar wordcount /input/CountWord.txt  /output

出现错误(FileAlreadyExistsException: Output directory hdfs://master:9000/output already exist

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值