1、官方grep案例
1)在hadoop-2.8.2文件下面创建一个input文件夹
[victor@node1 hadoop-2.8.2]$ pwd
/opt/module/hadoop-2.8.2
[victor@node1 hadoop-2.8.2]$ mkdir input
2)将hadoop的xml配置文件复制到input
[victor@node1 hadoop-2.8.2]$ pwd
/opt/module/hadoop-2.8.2
[victor@node1 hadoop-2.8.2]$ cp -r etc/hadoop/*.xml input/
3)执行share目录下的mapreduce程序
[victor@node1 hadoop-2.8.2]$ bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.8.2.jar grep input output 'dfs[a-z.]+'
[victor@node1 hadoop-2.8.2]$ cat output/*
1 dfsadmin
注意:output 不存在,不用提前创建
2、官方wordcount案例
1)在hadoop-2.8.2文件下面创建一个wcinput文件夹
[victor@node1 hadoop-2.8.2]$ pwd
/opt/module/hadoop-2.8.2
[victor@node1 hadoop-2.8.2]$ mkdir wcinput
2)在wcinput文件下创建一个wc.input文件
[victor@node1 hadoop-2.8.2]$ cd wcinput/
[victor@node1 wcinput]$ > wc.input
[victor@node1 wcinput]$ ls
wc.input
3)编辑wc.input文件
[victor@node1 wcinput]$ vi wc.input
hadoop hdfs yarn mapreduce
dfs hdfs hdfs yarn English victor
spark haha
ip id id nat ict mat cctv cctv
保存退出 :wq
4)执行案列
[victor@node1 wcinput]$ cd ../
[victor@node1 hadoop-2.8.2]$ pwd
/opt/module/hadoop-2.8.2
#[victor@node1 hadoop-2.8.2]$ bin/hadoop fs -put wcinput/ /user/victor/wcinput
[victor@node1 hadoop-2.8.2]$ bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.8.2.jar wordcount wcinput wcoutput
注意:wcoutput 不存在,不用提前创建,本地模式不用上传到hdfs上
5)查看结果
[victor@node1 hadoop-2.8.2]$ cat wcoutput/*
English 1
cctv 2
dfs 1
hadoop 1
haha 1
hdfs 3
ict 1
id 2
ip 1
mapreduce 1
mat 1
nat 1
victor 1
yarn 2
spark 1