Big data entry foundation five: HDFS write data process, and implement mapreduce to count the same words in the text! (Item 1)

HDFS write data flow:

  Create hdfs Java project , create User Library hdfslib

  hadoop-2.6.5\share\hadoop\hdfs\hadoop-hdfs-2.6.5.jar

  hadoop-2.6.5\share\hadoop\hdfs\lib\全选

  hadoop-2.6.5\share\hadoop\common\hadoop-common-2.6.5.jar

  hadoop-2.6.5\share\hadoop\common\lib\全选

  Java project introduces User Library hdfslib

 

The overall working process of the mapreduce framework:

  hdfs creates wordcount/input directory hdfs dfs -mkdir -p /wordcount/input

  Create a.txt text vi a.txt

i love you angelababy
i love you liuyifei
i love you tangyan
i love you zhaoliying
i love you fanbingbing
i love you gaoshumaliya
i love you java
i love you scala
a.txt

  Copy 10 copies of a.txt

cp a.txt a.txt.2
cp a.txt a.txt.3
cp a.txt a.txt.4
cp a.txt a.txt.5
cp a.txt a.txt.6
cp a.txt a.txt.7
cp a.txt a.txt.8
cp a.txt a.txt.9
cp a.txt a.txt.10
10 copies

The overall working process of the mapreduce framework

hdfs creates wordcount/input directory hdfs dfs -mkdir -p /wordcount/input

Create a.txt text vi a.txt

i love you angelababy

i love you liuyifei

i love you tangyan

i love you zhaoliying

i love you fanbingbing

i love you gaoshumaliya

i love you java

i love you scala

Copy 10 copies of a.txt

cp a.txt a.txt.2

cp a.txt a.txt.3

cp a.txt a.txt.4

cp a.txt a.txt.5

cp a.txt a.txt.6

cp a.txt a.txt.7

cp a.txt a.txt.8

cp a.txt a.txt.9

cp a.txt a.txt.10

Upload 10 copies of a.txt to hdfs wordcount/input directory hadoop fs -put a.* /wordcount/input

 

Mapreduce programming example wordcount---- writing of mapper

Create mapreduce Java project , create User Library mrlib

hadoop-2.6.5\share\hadoop\mapreduce\全部

hadoop-2.6.5\share\hadoop\mapreduce\lib\全部

hadoop-2.6.5\share\hadoop\yarn\全部

hadoop-2.6.5\share\hadoop\yarn\lib\全部

Java project introduces User Library hdfslib mrlib

Write the WordCountMapper class

 

Mapreduce programming example wordcount----reducer writing

Write the WordCountReducer class

 

Mapreduce programming example wordcount----job submits the writing of the client program

Write the jobClient class

The previous command returns the status code echo $?

ls

echo $?

0

true

echo $?

0

false

echo $?

1

dirr

echo $?

127

service iptables xxxooo

echo $?

2

mapreduce Java工程Exportwordcount.jar

 

mapreduce编程实例wordcount----程序提交运行的过程

上传d盘根目录wordcount.jarcentos001~目录 sftp> put d:/wordcount.jar

执行wordcount.jar hadoop jar wordcount.jar com.dohit.hadoop.JobClient

查看yarn运行状态 172.17.1.28:8088

查看output目录执行结果 hadoop fs -cat /wordcount/output/part-r-00001

创建b.txt文本 vi b.txt

a

b

c

d

e

f

g

g

i

j

k

l

m

n h k j

上传b.txthdfs wordcount/input目录 hadoop fs -put b.txt /wordcount/input

执行wordcount.jar hadoop jar wordcount.jar com.dohit.hadoop.JobClient

删除output目录 hadoop fs -rm -r /wordcount/output

查看yarn运行状态 172.17.1.28:8088

查看output目录执行结果 hadoop fs -cat /wordcount/output/part-r-00001

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324815980&siteId=291194637