Hadoop|Hadoop——练习1(统计单词个数)

1、启动Hadoop

cd /opt
cd hadoop
./sbin/start-all.sh
jps
Hadoop|Hadoop——练习1(统计单词个数)
文章图片

2、创建一个txt,存入英文单词
vi blue
i(输入)——>est键(退出)——wq(保存)
3、使用 put 操作将“blue”文件上传到 HDFS 的根目录
hadoop fs -put blue /blue
4、使用 jar 操作运行 Hadoop 中自带的 jar 进行单词计数
cd hadoop/share/hadoop/mapreduce/
hadoop jar hadoop-mapreduce-examples-2.7.1.jar wordcount /blue /out
Hadoop|Hadoop——练习1(统计单词个数)
文章图片

5、使用 cat 查看统计结果
hadoop fs -cat /out/part-r-00000
Hadoop|Hadoop——练习1(统计单词个数)
文章图片

Hadoop|Hadoop——练习1(统计单词个数)
文章图片
Hadoop|Hadoop——练习1(统计单词个数)
文章图片

*戳爷版BLUE歌词
Love It's hard I know All your lIghts are red but I'm green to Go Used to see you hIgh now you're only low All your lIghts are red but I'm green to Go I want you I'll colour me blue Anything It takes to make you stay Only seeing myself When I'm loOKing up at you I want you I'll colour me blue Anything It takes to make you stay Only seeing myself When I'm loOKing up at you I can't say no though the lIghts are on There's nobody home Swore I'd never lose control Then I fell in love wIth a heart that beats so slow I want you I'll colour me blue Anything It takes to make you stay Only seeing myself When I'm loOKing up at you I want you I'll colour me blue Anything It takes to make you stay Only seeing myself When I'm loOKing up at you I know you're seeing black and whIte So I'll paint you a clear-blue sky WIthout you I am colour-blind It's raining every tIme I open my eyes I know you're seeing black and whIte So I'll paint you a clear-blue sky WIthout you I am colour-blind It's raining every tIme I open my eyes I want you I'll colour me blue Only seeing myself When I'm loOKing up at you When I'm loOKing up at you I want you I'll colour me blue Anything It takes to make you stay Only seeing myself When I'm loOKing up at you When I'm loOKing up at you I want you I'll colour me blue Anything It takes to make you stay Only seeing myself When I'm loOKing up at you I want you I'll colour me blue Anything It takes to make you stay

7、错误:重复上上面的操作,创建一个新的hello.txt,发现不能统计单词数目
Hadoop|Hadoop——练习1(统计单词个数)
文章图片

解决办法:将out改成out1
结果:
Hadoop|Hadoop——练习1(统计单词个数)
文章图片

Hadoop|Hadoop——练习1(统计单词个数)
文章图片

【Hadoop|Hadoop——练习1(统计单词个数)】

    推荐阅读