赞
踩
以提交wordcount为例——hadoop自带的例子程序
启动HDFS和yarn
$HADOOP_HOME/sbin/start-dfs.sh
$HADOOP_HOME/sbin/start-yarn.sh
数据准备
进入$HADOOP_HOME目录
cd $HADOOP_HOME
创建数据文件
vim input1.txt
输入如下内容
- hello bigdata 2017
- hello bigdata 2018
- hello bigdata 2019
- hello bigdata 2020
- hello ynnu 2017
- hello ynnu 2018
- hello ynnu 2019
- hello ynnu 2020
使用同样的方式创建文件input2.txt
HDFS上创建目录
在HDFS根目录下创建文件夹test
hdfs dfs -mkdir /test
在 /test目录下创建文件夹input
hdfs dfs -mkdir /test/input
上传数据
将input1.txt拷贝到HDFS集群的 /test/input
hdfs dfs -copyFromLocal input1.txt /test/input
将input2.txt拷贝到HDFS集群的 /test/input
hdfs dfs -copyFromLocal input2.txt /test/input
查看HDFS的文件
hdfs dfs -ls /test/input
通过浏览器查看
先进入HDFS的web监控界面(通过浏览器搜索 http://10.103.105.62:50070), 点击菜单“Utilities”,再点击菜单“Browse the file system”,选择目录“test”,再选择目录”input”
执行程序
进入$HADOOP_HOME目录
cd $HADOOP_HOME
执行以下命令:
hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.6.jar wordcount /test/input /test/output
/*-2.7.6为hadoop的版本号,要和自己的版本对应
此处wordcount为程序名称
/test/input为HDFS上输入数据的存储路径为
此处/test/output为结果保存路径,一个不存在的路径,否则程序会报错!*/
下图描述了程序执行过程中的相关性能计数器。在File System Counters记录了文件读写的字节数;Job Counters中记录了Task任务和Reduce任务的个数(此处分别为2和1);Map-Reduce Framework中记录了Map任务和Reduce任务操作的记录数和字节数。
查看计算结果
查看结果目录
hdfs dfs -ls /test/output
查看最终结果
hdfs dfs -cat /test/output/part-r-00000
程序创建了目录/test/output,并且最终输出结果保存在文件part-r-00000中。一个结果文件,意味着只有一个Reduce任务
在Yarn中查看程序信息
在浏览器中搜索 http://10.103.105.62:8088即可查看结果
所有在集群执行的MapReduce程序,其消耗的资源相关的信息都可以在Yarn监控界面查看,这些信息有助于集群管理和程序性能优化
关闭HDFS和yarn
stop-yarn.sh
stop-dfs.sh
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。