Hadoop-05-Hadoop集群 集群WordCount 超详细 真正的分布式计算 上传HDFS MapReduce计算 YRAN查看任务 上传计算下载查看

PS:小知识点, yarn 应该写为: YARN,通常使用大写的 “YARN” 来指代 “Yet Another Resource Negotiator”

章节内容

上一节完成:

  • Hadoop分发
  • 单节点启动 NameNode初始化 DataNode启动
  • YRAN启动 ResourceManager NodeManager
  • 集群启动 HDFS启动 YRAN集群启动
  • 各种启停相关的内容

本节内容较为简单,但是需要基于前面的内容!!!

背景介绍

这里是三台公网云服务器,每台 2C4G,搭建一个Hadoop的学习环境,供我学习。
之前已经在 VM 虚拟机上搭建过一次,但是没留下笔记,这次趁着前几天薅羊毛的3台机器,赶紧尝试在公网上搭建体验一下。

注意,如果你和我一样,打算用公网部署,那一定要做好防火墙策略,避免不必要的麻烦!!!
请大家都以学习为目的,也请不要对我的服务进行嗅探或者攻击!!!

但是有一台公网服务器我还运行着别的服务,比如前几天发的:autodl-keeper 自己写的小工具,防止AutoDL机器过期的。还跑着别的Web服务,所以只能挤出一台 2C2G 的机器。那我的配置如下了:

  • 2C4G 编号 h121
  • 2C4G 编号 h122
  • 2C2G 编号 h123

在这里插入图片描述
请确保上一节内容全部完毕和跑通!!!

HDFS

创建文件夹

h121节点上进行操作:

hdfs dfs -mkdir -p /test/input

上传文件

hdfs dfs -put /opt/wzk/test.txt /test/input

下载文件

hdfs dfs -get /test/input/test.txt

在这里插入图片描述

WordCount

创建文件夹

hdfs dfs -mkdir /wcinput

创建文件

在本地创建一个文件

vim /opt/wzk/wordcount.txt

写入如下的内容(当然你也可以是自己的内容)

Hadoop is an open-source framework that allows for the distributed processing of large data sets across clusters of computers using simple programming models.
It is designed to scale up from single servers to thousands of machines, each offering local computation and storage.
The Hadoop framework application works in an environment that provides distributed storage and computation across many computers.
Hadoop is designed to scale up from single servers to thousands of machines, each offering local computation and storage.
The Hadoop Distributed File System (HDFS) is the primary storage system used by Hadoop applications.
HDFS stores large files (typically in the range of gigabytes to terabytes) across multiple machines.
Hadoop’s HDFS is designed to store very large files, and it has many features that are designed to support the storage of larg
e files.
For example, HDFS splits files into large blocks and distributes them across machines in a cluster.
The Hadoop framework transparently provides both reliability and data motion to applications.
Hadoop implements a computational paradigm named MapReduce, where the application is divided into many small fragments of work, each of which may be executed or re-executed on any node in the cluster.

上传文件

hdfs dfs -put /opt/wzk/wordcount.txt /wcinput

观察文件情况
在这里插入图片描述
可以看到文件已经上传了
在这里插入图片描述

运行实例

cd /opt/servers/hadoop-2.9.2

注意下面的指令,不要写错了:

hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.9.2.jar wordcount /wcinput /wcoutput

此时运行之后,任务会被提交到给集群运行,需要耐心的等待一会儿。
在这里插入图片描述

查看结果

这里可以查看到此时的HDFS的结果:
在这里插入图片描述
我们点击查看 wcoutput文件夹的内容:
在这里插入图片描述

命令查看

hdfs dfs -cat /wcoutput/part-r-00000

我们可以看到最终的计算结果,符合我们的预期:
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值