Hadoop中自带的hadoop-mapreduce-examples-2.7.6.jar含有一些事例,本文将用wordcount实现词频统计。具体步骤如下:
1. 启动Hadoop
切换到Hadoop安装目录下的sbin目录下执行./start-all.sh命令
或执行./start-dfs.sh和./start-yarn.sh两条命令
2. 在集群中创建目录inputdata_w
hdfs dfs -mkdir /inputdata_w
3. 将Hadoop安装目录下的LICENSE.txt、README.txt、NOTICE.txt文件上传到集群
hdfs dfs -put ../LICENSE.txt /inputdata_w
hdfs dfs -put ../README.txt /inputdata_w
hdfs dfs -put ../NOTICE.txt /inputdata_w
4. 使用hadoop-mapreduce-examples-2.7.6.jar对上传的数据进行词频统计
hadoop jar ../share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.6.jar wordcount /inputdata_w
/output/wordcountout01
5. 查看统计结果
hdfs dfs -cat /output/wordcountout01/part-r-00000