Hadoop (Introduction) of Big Data Technology

Chapter 1 Hadoop Overview

1.1 What is Hadoop

1) Hadoop is a distributed system infrastructure developed by the Apache Foundation ;

2) Mainly solve the problems of massive data storage and massive data analysis and calculation ;

3) In a broad sense, Hadoop usually refers to a broader concept - the Hadoop ecosystem;

1.2 Three Hadoop releases (understand)

Three Hadoop distributions: Apache, Cloudera, Hortonworks.

  • The most primitive (most basic) version of the Apache version, the best for getting started. 2006

  • Cloudera integrates many big data frameworks, corresponding to the product CDH. 2008

  • The Hortonworks documentation is better, corresponding to the product HDP. 2011; Hortonworks has now been acquired by Cloudera and launched a new brand CDP.

1)Apache Hadoop

Official website address: http://hadoop.apache.org

Download address: https://hadoop.apache.org/releases.html

2)Cloudera Hadoop

Official website address: https://www.cloudera.com/downloads/cdh

Download address: https://docs.cloudera.com/documentation/enterprise/6/release-notes/topics/rg_cdh_6_download.html

(1) Cloudera, established in 2008, was the first company to commercialize Hadoop, providing partners with Hadoop commercial solutions, mainly including support, consulting services, and training.

(2) In 2009, Doug Cutting, the founder of Hadoop, also joined Cloudera. Cloudera products are mainly CDH, Cloudera Manager, Cloudera Support

(3) CDH is Cloudera's Hadoop distribution, which is completely open source and has enhanced compatibility, security, and stability compared to Apache Hadoop. Cloudera's list price is $10,000 per node per year.

(4) Cloudera Manager is a software distribution, management and monitoring platform for clusters. It can deploy a Hadoop cluster within a few hours and monitor the nodes and services of the cluster in real time.

3)Hortonworks Hadoop

Official website address: https://hortonworks.com/products/data-center/hdp/

Download link: https://hortonworks.com/downloads/#data-platform

(1) Hortonworks, established in 2011, is a joint venture between Yahoo and Silicon Valley venture capital firm Benchmark Capital.

(2) At the beginning of the company's establishment, it has absorbed about 25 to 30 Yahoo engineers who specialize in Hadoop. The above-mentioned engineers all began to assist Yahoo in the development of Hadoop in 2005 and contributed 80% of Hadoop's code.

(3) The main product of Hortonworks is Hortonworks Data Platform (HDP), which is also a 100% open source product. In addition to common projects, HDP also includes Ambari, an open source installation and management system.

(4) Hortonworks has been acquired by Cloudera in 2018.

1.3 Hadoop advantages (4 high)

  1. High reliability: Hadoop maintains multiple data copies at the bottom layer, so even if a Hadoop computing element or storage fails, it will not cause data loss.

  1. High scalability: Distributing task data among clusters can easily expand thousands of nodes.

  1. Efficiency: Under the idea of ​​MapReduce, Hadoop works in parallel to speed up task processing.

  1. High fault tolerance: can automatically reassign failed tasks.

1.4 Hadoop composition (interview focus)

Differences between Hadoop1.X, 2.X, and 3.X:

  • In the Hadoop 1.x era, MapReduce in Hadoop handles business logic operations and resource scheduling at the same time, which is highly coupled.

  • In the Hadoop 2.x era, Yarn was added. Yarn is only responsible for resource scheduling, and MapReduce is only responsible for computing.

  • Hadoop 3.x has no change in composition.

1.4.1 Overview of HDFS architecture

Hadoop Distributed File System, HDFS for short, is a distributed file system.

1.4.2 Overview of YARN architecture

Yet Another Resource Negotiator, YARN for short, another resource coordinator, is the resource manager of Hadoop.

1.4.3 Overview of MapReduce architecture

MapReduce divides the computing process into two phases: Map and Reduce.

(1) The Map stage processes input data in parallel

(2) The Reduce stage summarizes the Map results

1.4.4 Relationship among HDFS, YARN, and MapReduce

1.5 Big Data Technology Ecosystem

The technical terms involved in the figure are explained as follows:

(1) Sqoop: Sqoop is an open source tool, mainly used for data transfer between Hadoop, Hive and traditional databases (MySQL), and can transfer data in a relational database (such as MySQL, Oracle, etc.) Imported into Hadoop's HDFS, HDFS data can also be imported into a relational database.

(2) Flume: Flume is a highly available, highly reliable, and distributed massive log collection, aggregation, and transmission system. Flume supports customizing various data senders in the log system for data collection;

(3) Kafka: Kafka is a high-throughput distributed publish-subscribe messaging system;

(4) Spark: Spark is currently the most popular open source big data memory computing framework. It can be calculated based on big data stored on Hadoop.

(5) Flink: Flink is currently the most popular open source big data memory computing framework. There are many scenarios for real-time computing.

(6) Oozie: Oozie is a workflow scheduling management system that manages Hadoop jobs (jobs).

(7)HBase:HBase是一个分布式的、面向列的开源数据库。HBase不同于一般的关系数据库,它是一个适合于非结构化数据存储的数据库。

(8)Hive:Hive是基于Hadoop的一个数据仓库工具,可以将结构化的数据文件映射为一张数据库表,并提供简单的SQL查询功能,可以将SQL语句转换为MapReduce任务进行运行。其优点是学习成本低,可以通过类SQL语句快速实现简单的MapReduce统计,不必开发专门的MapReduce应用,十分适合数据仓库的统计分析。

(9)ZooKeeper:它是一个针对大型分布式系统的可靠协调系统,提供的功能包括:配置维护、名字服务、分布式同步、组服务等。


第2章 Hadoop运行模式

1)Hadoop官方网站:http://hadoop.apache.org/

2)Hadoop运行模式包括:本地模式、伪分布式模式以及完全分布式模式。

  • 本地模式:单机运行,只是用来演示一下官方案例。生产环境不用。

  • 伪分布式模式:也是单机运行,但是具备Hadoop集群的所有功能,一台服务器模拟一个分布式的环境。个别缺钱的公司用来测试,生产环境不用。

  • 完全分布式模式:多台服务器组成分布式环境。生产环境使用。

2.1 本地运行模式(官方案例---WordCount)

1)创建在hadoop-3.1.3文件下面创建一个wcinput文件夹

[atguigu@hadoop102 hadoop-3.1.3]$ mkdir wcinput

2)在wcinput文件下创建一个word.txt文件

[atguigu@hadoop102 hadoop-3.1.3]$ cd wcinput

3)编辑word.txt文件

[atguigu@hadoop102 wcinput]$ vim word.txt

在文件中输入如下内容
hadoop yarn
hadoop mapreduce
atguigu
atguigu
保存退出::wq

4)回到Hadoop目录

[atguigu@hadoop102 hadoop-3.1.3]$ /opt/module/hadoop-3.1.3

5)执行程序

[atguigu@hadoop102 hadoop-3.1.3]$ hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-3.1.3.jar wordcount wcinput wcoutput

6)查看结果

[atguigu@hadoop102 hadoop-3.1.3]$ cat wcoutput/part-r-00000

看到如下结果:
atguigu 2
hadoop  2
mapreduce       1
yarn    1

2.2 完全分布式运行模式(开发重点)

2.2.1 虚拟机准备

(1)准备3台客户机(关闭防火墙、静态IP、主机名称)

(2)安装JDK

(3)配置环境变量

(4)安装Hadoop

(5)配置环境变量

(6)配置集群

(7)单点启动

(8)配置ssh

(9)群起并测试集群

2.2.2 编写集群分发脚本xsync

1)scp(secure copy)安全拷贝

(1)scp定义

scp可以实现服务器与服务器之间的数据拷贝。(from server1 to server2)

(2)基本语法

scp -r $pdir/$fname $user@$host:$pdir/$fname

命令 递归 要拷贝的文件路径/名称 目的地用户@主机:目的地路径/名称

(3)案例实操

前提:在hadoop102、hadoop103、hadoop104都已经创建好的/opt/module、 /opt/software两个目录,并且已经把这两个目录修改为atguigu:atguigu

①在hadoop102上,将hadoop102中/opt/module/jdk1.8.0_212目录拷贝到hadoop103上。

[atguigu@hadoop102 ~]$ scp -r /opt/module/jdk1.8.0_212  atguigu@hadoop103:/opt/module

②在hadoop103上,将hadoop102中/opt/module/hadoop-3.1.3目录拷贝到hadoop103上。

[atguigu@hadoop103 ~]$ scp -r atguigu@hadoop102:/opt/module/hadoop-3.1.3 /opt/module/

③在hadoop103上操作,将hadoop102中/opt/module目录下所有目录拷贝到hadoop104上。

[atguigu@hadoop103 opt]$ scp -r atguigu@hadoop102:/opt/module/* atguigu@hadoop104:/opt/module

2)rsync远程同步工具

rsync主要用于备份和镜像。具有速度快、避免复制相同内容和支持符号链接的优点。

rsync和scp区别:用rsync做文件的复制要比scp的速度快,rsync只对差异文件做更新。scp是把所有文件都复制过去。

(1)基本语法

rsync -av $pdir/$fname $user@$host:$pdir/$fname

命令 选项参数 要拷贝的文件路径/名称 目的地用户@主机:目的地路径/名称

(2)选项参数说明

选项---->功能

-a ----> 归档拷贝

-v ---->显示复制过程

(2)案例实操

①删除hadoop103中/opt/module/hadoop-3.1.3/wcinput

[atguigu@hadoop103 hadoop-3.1.3]$ rm -rf wcinput/

②同步hadoop102中的/opt/module/hadoop-3.1.3到hadoop103

[atguigu@hadoop102 module]$ rsync -av hadoop-3.1.3/ atguigu@hadoop103:/opt/module/hadoop-3.1.3/

3) xsync集群分发脚本

1)需求:循环复制文件到所有节点的相同目录下

(2)需求分析:

①rsync命令原始拷贝:

rsync -av /opt/module atguigu@hadoop103:/opt/

②期望脚本:

xsync要同步的文件名称

③期望脚本在任何路径都能使用(脚本放在声明了全局环境变量的路径)

[atguigu@hadoop102 ~]$ echo $PATH

/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/atguigu/.local/bin:/home/atguigu/bin:/opt/module/jdk1.8.0_212/bin

(3)脚本实现

①在/home/atguigu/bin目录下创建xsync文件

[atguigu@hadoop102 opt]$ cd /home/atguigu
[atguigu@hadoop102 ~]$ mkdir bin
[atguigu@hadoop102 ~]$ cd bin
[atguigu@hadoop102 bin]$ vim xsync

在该文件中编写如下代码:

#!/bin/bash
#1. 判断参数个数
if [ $# -lt 1 ]
then
    echo "Not Enough Arguement!"
    exit
fi
#2. 遍历集群所有机器
for host in hadoop102 hadoop103 hadoop104
do
    echo ====================  $host  ====================
    #3. 遍历所有目录,挨个发送
    for file in $@
    do
        #4. 判断文件是否存在
        if [ -e $file ]
            then
                #5. 获取父目录
                pdir=$(cd -P $(dirname $file); pwd)
                #6. 获取当前文件的名称
                fname=$(basename $file)
                ssh $host "mkdir -p $pdir"
                rsync -av $pdir/$fname $host:$pdir
            else
                echo $file does not exists!
        fi
    done
done

②修改脚本 xsync 具有执行权限

[atguigu@hadoop102 bin]$ chmod +x xsync

③测试脚本

[atguigu@hadoop102 ~]$ xsync /home/atguigu/bin

④将脚本复制到/bin中,以便全局调用

[atguigu@hadoop102 bin]$ sudo cp xsync /bin/

⑤同步环境变量配置(root所有者)

[atguigu@hadoop102 ~]$ sudo xsync /etc/profile.d/my_env.sh
让环境变量生效
[atguigu@hadoop103 bin]$ source /etc/profile
[atguigu@hadoop104 opt]$ source /etc/profile

2.2.3 SSH无密登录配置

1)配置ssh

(1)基本语法

ssh另一台电脑的IP地址

[atguigu@hadoop102 ~]$ ssh hadoop103
(2)退回到hadoop102
[atguigu@hadoop103 ~]$ exit

2)无密钥配置

(1)免密登录原理
(2)生成公钥和私钥
[atguigu@hadoop102 .ssh]$ pwd
/home/atguigu/.ssh

[atguigu@hadoop102 .ssh]$ ssh-keygen -t rsa

然后敲(三个回车),就会生成两个文件id_rsa(私钥)、id_rsa.pub(公钥)

(3)将公钥拷贝到要免密登录的目标机器上
[atguigu@hadoop102 .ssh]$ ssh-copy-id hadoop102
[atguigu@hadoop102 .ssh]$ ssh-copy-id hadoop103
[atguigu@hadoop102 .ssh]$ ssh-copy-id hadoop104

# 还需要在hadoop103上采用root账号配置一下无密登录到hadoop102、hadoop103、hadoop104服务器上。
[atguigu@hadoop103 .ssh]$ ssh-copy-id hadoop102
[atguigu@hadoop103 .ssh]$ ssh-copy-id hadoop103
[atguigu@hadoop103 .ssh]$ ssh-copy-id hadoop104

[atguigu@hadoop104 .ssh]$ ssh-copy-id hadoop102
[atguigu@hadoop104 .ssh]$ ssh-copy-id hadoop103
[atguigu@hadoop104 .ssh]$ ssh-copy-id hadoop104

3).ssh文件夹下(~/.ssh)的文件功能解释

known_hosts

记录ssh访问过计算机的公钥(public key)

id_rsa

生成的私钥

id_rsa.pub

生成的公钥

authorized_keys

存放授权过的无密登录服务器公钥

2.2.4 集群配置

https://blog.csdn.net/m0_57126939/article/details/129170103

Guess you like

Origin blog.csdn.net/m0_57126939/article/details/129160877