Hadoop

学习来源:b站尚硅谷大数据Hadoop3.x
在这里插入图片描述

一、 Hadoop入门

1.1 概述

在这里插入图片描述
Hadoop:分布式系统基础架构,主要解决数据存储和海量数据的分析计算问题
在这里插入图片描述
HDFS:分布式存储
Mapreduce:分布式计算
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

1.2 组成

在这里插入图片描述

HDFS架构概述(数据存储)

在这里插入图片描述
在这里插入图片描述

YARN架构概述(资源调度)

在这里插入图片描述
在这里插入图片描述
ResourceManager主要作用:
1)处理客户端请求;2)监控NodeManager;3)启动或监控ApplicationMaster;4)资源的分配与调度。
NodeManager主要作用:
1)管理每个节点上的资源;2)处理来自ResourceManager的命令;3)处理来自ApplicationMaster的命令。
ApplicationMaster(AM)的主要作用:
1)负责数据切分;2)为应用程序申请资格;3),任务的监控与容错。
Container的主要作用:容器,里面封装了任务运行所需要的资源,如内存、CPU、磁盘、网络等

MapReduce概述(计算)

在这里插入图片描述
在这里插入图片描述

三者之间关系

在这里插入图片描述

1.3 大数据生态体系

在这里插入图片描述
在这里插入图片描述

1.4 Hadoop运行环境搭建

1.安装虚拟机VMware
3.安装linux(CentOS7)
4.虚拟机环境准备

进入root用户

su root

在root用户下,修改IP地址
5安装Xshell远程访问工具
6.虚拟机的准备
7.虚拟机克隆
8.JDK安装
9.hadoop安装

1.5 本地运行模式

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

1.6scp命令:数据完全拷贝

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

1.7rsync命令:远程同步(拷贝差异的内容)

在这里插入图片描述

1.8xsync命令:集群分发

在这里插入图片描述

常见面试题

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

二、HDFS

2.1HDFS概述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

2.2HDFS组成架构

在这里插入图片描述
在这里插入图片描述

2.3文件块大小

在这里插入图片描述

在这里插入图片描述

2.4HDFS的Shell操作

2.5HDFS的API

package com.djw.hdfs;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.*;
import org.apache.kerby.config.Conf;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;


public class HdfsClient {
    private FileSystem fileSystem;
    @Before
    public void init() throws URISyntaxException, IOException, InterruptedException {
        //连接的集群nn地址
        URI uri = new URI("hdfs://hadoop102:8020");
        //创建一个配置文件
        Configuration configuration = new Configuration();
        configuration.set("dfs.replication","2");
        //用户
        String user="djw";
        //获取客户端对象
        fileSystem = FileSystem.get(uri, configuration,user);
    }
    @After
    public void close() throws IOException {
        //关闭资源
        fileSystem.close();
    }
    @Test
    public void testmkdir() throws URISyntaxException, IOException, InterruptedException {
        //创建一个文件夹
        fileSystem.mkdirs(new Path("/xiyou/huaguoshan1"));
    }
    //文件上传
    @Test
    public void testput() throws IOException {
        //参数解读:参数一表示删除原数据,参数二表示是否允许覆盖,参数三表示原路径,参数四表示目的地路径
        fileSystem.copyFromLocalFile(false,true,new Path("E:\\BaiduWangPan\\sunwukong.txt"),
                new Path("hdfs://hadoop102/xiyou/huaguoshan"));
    }
    //文件下载
    @Test
    public void testget() throws IOException {
        //参数解读:参数一:是否删除原数据,参数二:原文件路径HDFS,参数三:目标地址路径windows,参数四:是否进行本地校验
        fileSystem.copyToLocalFile(false,new Path("hdfs://hadoop102/xiyou/huaguoshan"),
                new Path("E:\\BaiduWangPan\\sunwukong1"),true);
    }
    //删除
    @Test
    public void testRm() throws IOException {
        //删除文件
        //参数解读:参数一:要删除的路径;参数二:是否递归删除
        fileSystem.delete(new Path("hdfs://hadoop102/xiyou/huaguoshan1/"),false);
        //删除空目录
        fileSystem.delete(new Path("hdfs://hadoop102/xiyou/"),false);
        //删除非空目录
        fileSystem.delete(new Path("/jinguo"),true);
    }
    //文件的更名和移动
    @Test
    public void testmv() throws IOException {
        //1.对文件名称的修改
        //参数一:原文件路径,参数二:目标文件路径
        fileSystem.rename(new Path("/wcinput/word.txt"),new Path("/wcinput/djw.txt"));
        //2.对目录名的修改
        fileSystem.rename(new Path("/wcinput"),new Path("/input"));
        //3.对文件的移动和更名
        fileSystem.rename(new Path("/input/djw.txt"),new Path("/cls.txt"));
    }
    //获取文件详细信息
    @Test
    public void fileDetail() throws IOException {
        //获取所有文件信息
        RemoteIterator<LocatedFileStatus> listFiles = fileSystem.listFiles(new Path("/"), true);
        //遍历文件
        while (listFiles.hasNext()) {
            LocatedFileStatus next = listFiles.next();
            System.out.println("======"+next.getPath()+"=====");
            System.out.println(next.getPermission());
            System.out.println(next.getOwner());
            System.out.println(next.getGroup());
            System.out.println(next.getLen());
            System.out.println(next.getModificationTime());
            System.out.println(next.getReplication());
            System.out.println(next.getBlockSize());
            System.out.println(next.getPath().getName());
            //获取块信息
            BlockLocation[] blockLocations = next.getBlockLocations();
            System.out.println(Arrays.toString(blockLocations));
        }
    }
    //判断文件夹还是文件
    @Test
    public void testFile() throws IOException {
        FileStatus[] fileStatuses = fileSystem.listStatus(new Path("/"));

        for (FileStatus fileStatus : fileStatuses) {
            if (fileStatus.isFile()) {
                System.out.println("文件:"+fileStatus.getPath().getName());
            }else {
                System.out.println("目录:"+fileStatus.getPath().getName());
            }
        }
    }
}

三、MapReduce

3.1MapReduce编程规范

在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值