搭建Mapreduce(YARN)环境,运行Wordcount示例
搭建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

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

被折叠的 条评论
为什么被折叠?



