一. 启动YARN并运行MapReduce程序
1.配置一下JAVA_HOME
export JAVA_HOME=/opt/module/jdk1.8.0_144
2.配置yarn-site.xml
<property>
<name>yarn.nodemanager.aux-servicesname>
<value>mapreduce_shufflevalue>
property>
<property>
<name>yarn.resourcemanager.hostnamename>
<value>hadoop02value>
property>
3.配置:mapred-env.sh
配置: (对mapred-site.xml.template重新命名为) mapred-site.xml
[atguigu@hadoop02 hadoop]$ mv mapred-site.xml.template mapred-site.xml
[atguigu@hadoop02 hadoop]$ vi mapred-site.xml
<property>
<name>mapreduce.framework.namename>
<value>yarnvalue>
property>
4.启动集群
启动前必须保证NameNode和DataNode已经启动
启动ResourceManager
[atguigu@hadoop02 hadoop-2.7.2]$ sbin/yarn-daemon.sh start resourcemanager
5.启动NodeManager
[atguigu@hadoop02 hadoop-2.7.2]$ sbin/yarn-daemon.sh start nodemanager
6.在YARN的浏览器页面查看 http://hadoop101:8088/cluster
删除文件系统上的output文件
[atguigu@hadoop02 hadoop-2.7.2]$ bin/hdfs dfs -rm -R /user/liujh/output
7.执行MapReduce程序
[atguigu@hadoop02 hadoop-2.7.2]$ bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.2.jar wordcount /user/atguigu/input /user/atguigu/output
8.查看运行结果
[liujh@hadoop101 hadoop-2.7.2]$ bin/hdfs dfs -cat /user/liujh/output/*
二. Hadoop配置历史服务器
[root@hadoop02 hadoop]# vi mapred-site.xml
在该文件里面增加如下配置
<property>
<name>mapreduce.jobhistory.addressname>
<value>hadoop02:10020value>
property>
<property>
<name>mapreduce.jobhistory.webapp.addressname>
<value>hadoop02:19888value>
property>
[root@ehadoop02 hadoop-2.7.2]# sbin/mr-jobhistory-daemon.sh start historyserver
[root@hadoop02 hadoop-2.7.2]# jps
三. Hadoop配置日志的聚集
日志聚集概念:应用运行完成以后,将程序运行日志信息上传到HDFS系统上。
日志聚集功能好处:可以方便的查看到程序运行详情,方便开发调试。
注意: 开启日志聚集功能,需要重新启动NodeManager 、ResourceManager和HistoryManager。
1.配置yarn-site.xml
vi yarn-site.xml
在该文件里面增加如下配置。
<property>
<name>yarn.log-aggregation-enablename>
<value>truevalue>
property>
<property>
<name>yarn.log-aggregation.retain-secondsname>
<value>604800value>
property>
2.关闭NodeManager 、ResourceManager和HistoryManager
sbin/yarn-daemon.sh stop resourcemanager
sbin/yarn-daemon.sh stop nodemanager
sbin/mr-jobhistory-daemon.sh stop historyserver
3.启动NodeManager 、ResourceManager和HistoryManager
sbin/yarn-daemon.sh start resourcemanager
sbin/yarn-daemon.sh start nodemanager
sbin/mr-jobhistory-daemon.sh start historyserver
4.删除HDFS上已经存在的输出文件
bin/hdfs dfs -rm -R /user/root/output
5.执行WordCount程序
bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.2.jar wordcount /user/root/input/ /user/root/output