【大数据学习篇3】HDFS命令操作与MR单词统计

来源哔哩哔哩   2023-05-13 11:14:12

#在/目录创建一个为test名字的文件夹

[hd@master bin]$ hdfs dfs -mkdir /test


【资料图】

#查看/目录

[hd@master bin]$ hdfs dfs -ls 

Found 1 items

drwxr-xr-x   - hd supergroup          0 2020-02-27 01:02 /test

#创建一个本地的txt文件

[hd@master ~]$ echo "abc123def456" > hello.txt 

#把创建的文件上传到hdfs

[hd@master ~]$ hdfs dfs -put hello.txt  / 

#在hdfs查看上传的文件

[hd@slave02 ~]$ hdfs dfs -cat /hello.txt

abc123def456

#下载hdfs文件到本地的linux当前目录

[hd@slave02 ~]$ ll

total 0

drwxrwxr-x. 4 hd hd 30 Feb 26 23:08 apps

#下载hdfs文件到当前目录

[hd@slave02 ~]$ hdfs dfs -get /hello.txt .

[hd@slave02 ~]$ ll

total 4

drwxrwxr-x. 4 hd hd 30 Feb 26 23:08 apps

-rw-r--r--. 1 hd hd 13 Feb 27 01:13 hello.txt

[hd@slave02 ~]$ 

[hd@slave02 ~]$ cat hello.txt 

abc123def456

MapReduct执行单词统计的程序

#创建文件

[hd@master ~]$ vi words.txt

Hello World Bye World

Hello Hadoop Bye Hadoop

Bye Hadoop Hello Hadoop

#上传文件

[hd@master ~]$ hdfs dfs -mkdir /word

[hd@master ~]$ hdfs dfs -put words.txt /word

#执行单词统计的样例

[hd@master hadoop]$ hadoop jar /home/hd/apps/hadoop/share/hadoop/mapreduce/hadoop-mapreduce-examples-3.0.0.jar wordcount /word/words.txt /out

热门推荐

猜你喜欢