1.官方案例1 统计符合的个数
1)创建在 hadoop-2.7.2 文件下面创建一个 input 文件夹
[atguigu@hadoop101 hadoop-2.7.2]$mkdir input
2)将 hadoop 的 xml 配置文件复制到 input
[atguigu@hadoop101 hadoop-2.7.2]$cp etc/hadoop/*.xml input
3)执行 share 目录下的 mapreduce 程序
[atguigu@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)查看输出结果
[atguigu@hadoop101 hadoop-2.7.2]$ cd output/ [atguigu@hadoop101 output]$ cat part-r-000000
2.官方案例2——wordcount记一下单词出现了多少次
1)创建在 hadoop-2.7.2 文件下面创建一个 wcinput 文件夹
[atguigu@hadoop101 hadoop-2.7.2]$mkdir wcinput
2)在 wcinput 文件下创建一个 wc.input 文件
[atguigu@hadoop101 hadoop-2.7.2]$cd wcinput
[atguigu@hadoop101 wcinput]$touch wc.input
3)编辑 wc.input 文件
[atguigu@hadoop101 wcinput]$vim wc.input
在文件中输入如下内容
hadoop yarn
hadoop mapreduce
atguigu
atguigu
保存退出::wq
4)回到 hadoop 目录/opt/module/hadoop-2.7.2
5)执行程序:
[atguigu@hadoop101 hadoop-2.7.2]$ hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.2.jar wordcount wcinput wcoutput
6)查看结果:
[atguigu@hadoop101 hadoop-2.7.2]$cat wcoutput/part-r-00000
atguigu 2
hadoop 2
mapreduce 1
yarn 1