3.hadoop之本地模式

1 官方GREP案例

​ By default, Hadoop is configured to run in a non-distributed mode, as a single Java process. This is useful for debugging.

​ The following example copies the unpacked conf directory to use as input and then finds and displays every match of the given regular expression. Output is written to the given output directory.

#创建文件夹:存放源文件
mkdir input
#复制一部分文件为数据源
cp etc/hadoop/*.xml input
#执行hadoop-mapreduce-examples-2.7.2.jar grep来对数据源进行计算。统计dfs开头的单词
bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.2.jar grep input output 'dfs[a-z.]+'
#打印输出
cat output/*

image-20201229182445779

问题1:如果输出目录已经存在,会抛出异常

image-20201229182535165

解决方式:删除输出目录,重新跑

2 官方WordCount案例

统计单词的个数。

1 创建一个文件夹wcinput

mkdir wcinput

2 创建文件源文件并添加信息

#创建文件
touch word.txt

#添加文件内容
hadoop yarn
hadoop mapreduce
atguigu
atguigu

3 执行wordCoount程序

bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.2.jar wordcount wcinput/ wcoutput

4 查看结果

cat wcoutput/part-r-00000

image-20201229183648138

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值