前提步骤安装Hadoop,安装步骤: https://www.jianshu.com/p/2ce9775aeb6e
单节点案例官方文档地址:http://hadoop.apache.org/docs/r3.1.2/
![](https://upload-images.jianshu.io/upload_images/18296616-9323f7f73ee194b5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
单节点的案例
![](https://upload-images.jianshu.io/upload_images/18296616-0b8754343c815862.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
可以看到有三项,本地单节点,伪分布式,完全分布式三中
![](https://upload-images.jianshu.io/upload_images/18296616-cec88112952f4e94.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
案例1
本地单节点操作:准备数据源,示例input为我们要处理的数据源,不要提前创建output
执行examples的示例:过滤input,按照正则,将过滤到的数据输出到output中
正则:以dfs开头以a-z任意一个字符结尾的数据
$mkdir input
$cp etc/hadoop/*.xml input
$bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-3.1.2.jar grep input output 'dfs[a-z.]+'
![](https://upload-images.jianshu.io/upload_images/18296616-6d3da45ea6166164.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
$cat output/*
![](https://upload-images.jianshu.io/upload_images/18296616-4126c4dc657c9fd5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
查看执行生成的文件:
![](https://upload-images.jianshu.io/upload_images/18296616-090d2962d4af9a10.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
正则解释:以dfs开头以a-z任意一个字符结尾的数据
![](https://upload-images.jianshu.io/upload_images/18296616-3c24d0bccc1d51d9.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
案例2
Wordcount案例
数据源内容:
hadoop yarn
hadoop mapreduce
shaozhiqi
shaozhiqi
目标:统计相同单词的个数
[shaozhiqi@hadoop101 hadoop-3.1.2]$ mkdir wcinput
[shaozhiqi@hadoop101 hadoop-3.1.2]$ ls
bin etc include input lib libexec LICENSE.txt NOTICE.txt output README.txt sbin share wcinput
[shaozhiqi@hadoop101 hadoop-3.1.2]$ cd wcinput/
[shaozhiqi@hadoop101 wcinput]$ vim wc.input
[shaozhiqi@hadoop101 hadoop-3.1.2]$ hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-3.1.2.jar wordcount wcinput/ wcoutput
结果:
![](https://upload-images.jianshu.io/upload_images/18296616-afa7a2d5636622bb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)