hadoop本地运行的两个案例。官方Grep案例、官方WordCount案例。

时间:2022-07-23
本文章向大家介绍hadoop本地运行的两个案例。官方Grep案例、官方WordCount案例。,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

作者丨BossXiang

在前两篇文章已经把虚拟机环境和jdk、hadoop安装好了,下面我们来看看,hadoop本地运行的两个案例。官方Grep案例、官方WordCount案例。

1

官方Grep案例

1.创建在hadoop-2.7.2文件下面创建一个input文件夹
[hadoop@hadoop101 hadoop-2.7.2]$ mkdir input
2.将Hadoop的xml配置文件复制到input
[hadoop@hadoop101 hadoop-2.7.2]$ cp etc/hadoop/*.xml input
3.执行share目录下的MapReduce程序
[hadoop@hadoop101 hadoop-2.7.2]$ bin/hadoop jar
share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.2.jar
grep input output 'dfs[a-z.]+'
4.查看输出结果
[hadoop@hadoop101 hadoop-2.7.2]$ cat output/part-r-00000

2

官方WordCount案例

1.创建在hadoop-2.7.2文件下面创建一个wcinput文件夹

[hadoop@hadoop101 hadoop-2.7.2]$ mkdir wcinput

2.在wcinput文件下创建一个wc.input文件

[hadoop@hadoop101 hadoop-2.7.2]$ cd wcinput
[hadoop@hadoop101 hadoop-2.7.2]$ touch wc.input

3.编辑wc.input文件

[hadoop@hadoop101 hadoop-2.7.2]$ vi wc.input

在文件中输入如下内容

xianglin yuanyun baibaihe
linlin chen lixiaolu
chen chen liuyifei jiangsuying
xiang chenyuanyuan
chenyuangyuan

保存退出::wq

4.回到Hadoop目录/opt/module/hadoop-2.7.2

[hadoop@hadoop101 wcinput]$ cd
/opt/module/hadoop-2.7.2/

5.执行程序

hadoop jar
[hadoop@hadoop101 wcinput]$
share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.2.jar
wordcount wcinput wcoutput

6.查看结果

[hadoop@hadoop101 hadoop-2.7.2]$ cat wcoutput/part-r-00000