Hadoop单词统计

1. 本地创建文本文件

[root@s166 fantj]# mkdir input
[root@s166 fantj]# cd input/
[root@s166 input]# echo "hello fantj" > file1.txt
[root@s166 input]# echo "hello hadoop" > file2.txt
[root@s166 input]# echo "hello mapreduce" > file3.txt
[root@s166 input]# ls
file1.txt  file2.txt  file3.txt

2. 将文件上传到hadoop

[root@s166 input]# hadoop fs -mkdir /wordcount
[root@s166 input]# hadoop fs -ls /
Found 1 items
drwxr-xr-x   - root supergroup          0 2018-07-27 07:51 /wordcount
[root@s166 input]# cd ..
[root@s166 fantj]# ls
download  hadoop  input  jdk
[root@s166 fantj]# hadoop fs -put input/* /wordcount
[root@s166 fantj]# hadoop fs -ls /wordcount
Found 3 items
-rw-r--r--   3 root supergroup         12 2018-07-27 07:52 /wordcount/file1.txt
-rw-r--r--   3 root supergroup         13 2018-07-27 07:52 /wordcount/file2.txt
-rw-r--r--   3 root supergroup         16 2018-07-27 07:52 /wordcount/file3.txt

3. 启用hadoop自带单词统计进行处理

[root@s166 fantj]# cd /home/fantj/hadoop/share/hadoop/
[root@s166 hadoop]# ls
common  hdfs  httpfs  kms  mapreduce  tools  yarn
[root@s166 hadoop]# cd mapreduce/
[root@s166 mapreduce]# ls
hadoop-mapreduce-client-app-2.7.0.jar     hadoop-mapreduce-client-hs-plugins-2.7.0.jar       hadoop-mapreduce-examples-2.7.0.jar
hadoop-mapreduce-client-common-2.7.0.jar  hadoop-mapreduce-client-jobclient-2.7.0.jar        lib
hadoop-mapreduce-client-core-2.7.0.jar    hadoop-mapreduce-client-jobclient-2.7.0-tests.jar  lib-examples
hadoop-mapreduce-client-hs-2.7.0.jar      hadoop-mapreduce-client-shuffle-2.7.0.jar          sources
[root@s166 mapreduce]# hadoop jar hadoop-mapreduce-examples-2.7.0.jar wordcount /wordcount /print

查看结果

[root@s166 mapreduce]# hadoop fs -ls /print
Found 2 items
-rw-r--r--   3 root supergroup          0 2018-07-27 07:55 /print/_SUCCESS
-rw-r--r--   3 root supergroup         37 2018-07-27 07:55 /print/part-r-00000
[root@s166 mapreduce]# hadoop fs -cat /print/part-r-00000
fantj   1
hadoop  1
hello   3
mapreduce   1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值