Hadoop 的三种运行模式_完全分布式运行模式

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


分析:

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

       2)安装JDK

       3)配置环境变量

       4)安装Hadoop

       5)配置环境变量

       6)配置集群

       7)单点启动

       8)配置ssh

       9)群起并测试集群

1、虚拟机准备

至少三台虚拟机,和虚拟机配置参照前面两种运行模式。

a) 配置静态 ip 地址

b) 修改主机名

c) 配置映射文件

映射文件如下: 

[atguigu@hadoop101 opt]$ vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.19.100 hadoop100
192.168.19.101 hadoop101
192.168.19.102 hadoop102
192.168.19.103 hadoop103
192.168.19.104 hadoop104
192.168.19.105 hadoop105
192.168.19.106 hadoop106
192.168.19.107 hadoop107
192.168.19.108 hadoop108

注:我下面的演示用了三台服务器,分别是   hadoop102  hadoop103  hadoop104。


2、编写集群分发脚本xsync

 2.1、scp(secure copy)安全拷贝

定义:

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

基本语法:

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

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

案例实操:

(a)在hadoop101上,将hadoop101中 /opt/module 目录下的软件拷贝到 hadoop102 上。(

[atguigu@hadoop101 /]$ scp -r /opt/module  root@hadoop102:/opt/module

(b)在hadoop103上,将 hadoop101 服务器上的 /opt/module 目录下的软件拷贝到 hadoop103 上。(

[atguigu@hadoop103 opt]$sudo scp -r atguigu@hadoop101:/opt/module  root@hadoop103:/opt/module

(c)在hadoop103上操作将 hadoop101 中 /opt/module 目录下的软件拷贝到 hadoop104上。(站在其他服务器上操作另外两条服务器

[atguigu@hadoop103 opt]$ scp -r atguigu@hadoop101:/opt/module  root@hadoop104:/opt/module

注意:拷贝过来的/opt/module目录,别忘了在hadoop102、hadoop103、hadoop104上修改所有文件的,所有者和所有者组。sudo chown atguigu:atguigu -R /opt/module (-R, --recursive 递归处理所有的文件及子目录)

(d)将 hadoop101 中 /etc/profile 文件拷贝到 hadoop102 的 /etc/profile 上。

[atguigu@hadoop101 ~]$ sudo  scp  /etc/profile  root@hadoop102:/etc/profile

(e)将 hadoop101 中 /etc/profile 文件拷贝到 hadoop103 的 /etc/profile上。

[atguigu@hadoop101 ~]$ sudo scp  /etc/profile  root@hadoop103:/etc/profile

(f)将 hadoop101 中 /etc/profile 文件拷贝到 hadoop104 的 /etc/profile 上。

[atguigu@hadoop101 ~]$ sudo scp  /etc/profile  root@hadoop104:/etc/profile

注意:拷贝过来的配置文件别忘了 source 一下 /etc/profile。 source /etc/profile

2.2、rsync 远程同步工具

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

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

基本语法:

rsync    -rvl       $pdir/$fname              $user@hadoop$host:$pdir/$fname

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

选项参数说明:

选项

功能

-r

递归

-v

显示复制过程

-l

拷贝符号连接

案例实操:

(a)把hadoop101机器上的/opt/software目录同步到hadoop102服务器的root用户下的/opt/目录

[atguigu@hadoop101 opt]$ rsync -rvl /opt/software/  root@hadoop102:/opt/software

2.3、 xsync集群分发脚本  (名字顺便取)

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

(2)需求分析:

         (a)rsync命令原始拷贝:

rsync  -rvl     /opt/module       root@hadoop103:/opt/

         (b)期望脚本: xsync要同步的文件名称

         (c)说明:在 /home/atguigu/bin 这个目录下存放的脚本,atguigu 用户可以在系统任何地方直接执行。

(3)脚本实现

(a)在/home/atguigu目录下创建bin目录,并在bin目录下xsync创建文件,文件内容如下:

[atguigu@hadoop102 ~]$ mkdir bin

[atguigu@hadoop102 ~]$ cd bin/

[atguigu@hadoop102 bin]$ touch xsync

[atguigu@hadoop102 bin]$ vi xsync

在该文件中编写如下代码

#!/bin/bash
#1 获取输入参数个数,如果没有参数,直接退出
pcount=$#
if((pcount==0)); then
echo no args;
exit;
fi

#2 获取文件名称
p1=$1
fname=`basename $p1`
echo fname=$fname

#3 获取上级目录的绝对路径
pdir=`cd -P $(dirname $p1); pwd`
echo pdir=$pdir

#4 获取当前用户名称
user=`whoami`

#5 循环
for((host=103; host<105; host++)); do
    echo ------------------- hadoop$host --------------
    rsync -rvl $pdir/$fname $user@hadoop$host:$pdir
done

注释:cd -P 是以物理路径进入的意思。

(b)修改脚本 xsync 具有执行权限

[atguigu@hadoop102 bin]$ chmod 777 xsync

(c)调用脚本形式:xsync 文件名称

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

注意:如果将 xsync 放到 /home/atguigu/bin 目录下仍然不能实现全局使用,可以将 xsync 移动到 /usr/local/bin 目录下

演示:在 hadoop102  /home/atguigu 目录下的文件和目录同步到 hadoop103  和 hadoop104

[atguigu@hadoop102 /]$ cd ~
[atguigu@hadoop102 ~]$ mkdir bin
[atguigu@hadoop102 ~]$ cd bin/
[atguigu@hadoop102 bin]$ touch xsync
[atguigu@hadoop102 bin]$ vi xsync 
[atguigu@hadoop102 bin]$ chmod 777 xsync 
[atguigu@hadoop102 bin]$ ll
总用量 4
-rwxrwxrwx. 1 atguigu atguigu 501 1月  29 05:54 xsync

[atguigu@hadoop102 bin]$ cd ..
[atguigu@hadoop102 ~]$ xsync bin/
fname=bin
pdir=/home/atguigu
------------------- hadoop103 --------------
The authenticity of host 'hadoop103 (192.168.19.103)' can't be established.
RSA key fingerprint is 30:2a:31:af:95:b1:ee:ba:dc:4c:27:4b:77:14:b7:b6.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'hadoop103,192.168.19.103' (RSA) to the list of known hosts.
atguigu@hadoop103's password: 
Permission denied, please try again.
atguigu@hadoop103's password: 
sending incremental file list
bin/
bin/xsync

sent 596 bytes  received 35 bytes  60.10 bytes/sec
total size is 500  speedup is 0.79
------------------- hadoop104 --------------
The authenticity of host 'hadoop104 (192.168.19.104)' can't be established.
RSA key fingerprint is 30:2a:31:af:95:b1:ee:ba:dc:4c:27:4b:77:14:b7:b6.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'hadoop104,192.168.19.104' (RSA) to the list of known hosts.
atguigu@hadoop104's password: 
sending incremental file list
bin/
bin/xsync

sent 596 bytes  received 35 bytes  114.73 bytes/sec
total size is 500  speedup is 0.79
[atguigu@hadoop102 ~]$ 

 [atguigu@hadoop103 ~]$ cd ll
-bash: cd: ll: 没有那个文件或目录
[atguigu@hadoop103 ~]$ ll
总用量 4
drwxrwxr-x. 2 atguigu atguigu 4096 1月  29 06:07 bin
[atguigu@hadoop103 ~]$ cd bin/
[atguigu@hadoop103 bin]$ ll
总用量 4
-rwxrwxr-x. 1 atguigu atguigu 500 1月  29 06:07 xsync
[atguigu@hadoop103 bin]$ 

注意:如果将 xsync 放到 /home/atguigu/bin 目录下仍然不能实现全局使用,可以将 xsync 移动到 /usr/local/bin 目录下

[atguigu@hadoop102 ~]$ echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/module/jdk1.8.0_144/bin:/opt/module/hadoop-2.7.2/bin:/opt/module/hadoop-2.7.2/sbin:/home/atguigu/bin
[atguigu@hadoop102 ~]$ 
 


3、集群配置

3.1、集群部署规划

 

hadoop102

hadoop103

hadoop104

HDFS

 

NameNode

DataNode

 

DataNode

SecondaryNameNode

DataNode

YARN

 

NodeManager

ResourceManager

NodeManager

 

NodeManager

规划解释:

HDFS:NameNode 和 SecondaryNameNode  占用内存几乎是一比一,这就要求它们两个不能放在一台服务器上,避免服务器性能下降(比如一个内存为128G 的服务器 两个在一台服务器上的话,那么每个就只有64个G了,严重影响集群性能)。

YARN:ResourceManager 是整个集群资源的老大,它也是很耗费内存的的,所以它要避开上面的  NameNode 和 SecondaryNameNode,满足条件的就只有 hadoop103 这台服务器了。

3.2、配置集群

配置文件:

[atguigu@hadoop104 hadoop-2.7.2]$ cd etc/hadoop/
[atguigu@hadoop104 hadoop]$ tree
.
├── capacity-scheduler.xml
├── configuration.xsl
├── container-executor.cfg
├── core-site.xml
├── hadoop-env.cmd
├── hadoop-env.sh
├── hadoop-metrics2.properties
├── hadoop-metrics.properties
├── hadoop-policy.xml
├── hdfs-site.xml
├── httpfs-env.sh
├── httpfs-log4j.properties
├── httpfs-signature.secret
├── httpfs-site.xml
├── kms-acls.xml
├── kms-env.sh
├── kms-log4j.properties
├── kms-site.xml
├── log4j.properties
├── mapred-env.cmd
├── mapred-env.sh
├── mapred-queues.xml.template
├── mapred-site.xml
├── mapred-site.xml.template
├── slaves
├── ssl-client.xml.example
├── ssl-server.xml.example
├── yarn-env.cmd
├── yarn-env.sh
└── yarn-site.xml

0 directories, 30 files
[atguigu@hadoop104 hadoop]$ 

(1)核心配置文件     配置core-site.xml

[atguigu@hadoop102 hadoop]$ vi core-site.xml

在该文件中编写如下配置

<!-- 指定HDFS中NameNode的地址 -->
<property>
        <name>fs.defaultFS</name>
      <value>hdfs://hadoop102:9000</value>
</property>

<!-- 指定Hadoop运行时产生文件的存储目录 -->
<property>
        <name>hadoop.tmp.dir</name>
        <value>/opt/module/hadoop-2.7.2/data/tmp</value>
</property>

(2)HDFS配置文件 

 配置 hadoop-env.sh

[atguigu@hadoop102 hadoop]$ vi hadoop-env.sh

export JAVA_HOME=/opt/module/jdk1.8.0_144

配置 hdfs-site.xml

[atguigu@hadoop102 hadoop]$ vi hdfs-site.xml

在该文件中编写如下配置

<property>
        <name>dfs.replication</name>
        <value>3</value>
</property>

<!-- 指定Hadoop辅助名称节点主机配置 -->
<property>
      <name>dfs.namenode.secondary.http-address</name>
      <value>hadoop104:50090</value>
</property>

(3)YARN配置文件

配置 yarn-env.sh

[atguigu@hadoop102 hadoop]$ vi yarn-env.sh

export JAVA_HOME=/opt/module/jdk1.8.0_144

配置 yarn-site.xml

[atguigu@hadoop102 hadoop]$ vi yarn-site.xml

在该文件中增加如下配置

<!-- Reducer获取数据的方式 -->
<property>
        <name>yarn.nodemanager.aux-services</name>
        <value>mapreduce_shuffle</value>
</property>

<!-- 指定YARN的ResourceManager的地址 -->
<property>
        <name>yarn.resourcemanager.hostname</name>
        <value>hadoop103</value>
</property>
 

(4)MapReduce配置文件

配置mapred-env.sh

[atguigu@hadoop102 hadoop]$ vi mapred-env.sh

export JAVA_HOME=/opt/module/jdk1.8.0_144

配置 mapred-site.xml

[atguigu@hadoop102 hadoop]$ cp mapred-site.xml.template  mapred-site.xml

[atguigu@hadoop102 hadoop]$ vi mapred-site.xml

 注: mapred-site.xml 原来是没有的,是通过模板 mapred-site.xml.template 改的。

在该文件中增加如下配置

<!-- 指定MR运行在Yarn上 -->
<property>
        <name>mapreduce.framework.name</name>
        <value>yarn</value>
</property>

3.在集群上分发配置好的Hadoop配置文件

[atguigu@hadoop102 hadoop]$ xsync /opt/module/hadoop-2.7.2/

4.查看文件分发情况

[atguigu@hadoop103 hadoop]$ cat /opt/module/hadoop-2.7.2/etc/hadoop/core-site.xml 

注:通过集群分发文件,修改一处其他服务器的配置 “一键同步” 即可。SSH无密登录配置好了无需输入密码。


4、集群单点启动

(1)如果集群是第一次启动,需要 格式化NameNode

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop namenode -format

(2)在hadoop102上启动NameNode

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop-daemon.sh start namenode
[atguigu@hadoop102 hadoop-2.7.2]$ jps
3461 NameNode

(3)在hadoop102、hadoop103以及 hadoop104 上分别启动DataNode

[atguigu@hadoop102 hadoop-2.7.2]$ hadoop-daemon.sh start datanode
[atguigu@hadoop102 hadoop-2.7.2]$ jps
3461 NameNode
3608 Jps
3561 DataNode

[atguigu@hadoop103 hadoop-2.7.2]$ hadoop-daemon.sh start datanode
[atguigu@hadoop103 hadoop-2.7.2]$ jps
3190 DataNode
3279 Jps

[atguigu@hadoop104 hadoop-2.7.2]$ hadoop-daemon.sh start datanode
[atguigu@hadoop104 hadoop-2.7.2]$ jps
3237 Jps
3163 DataNode

4)思考:每次都一个一个节点启动,如果节点数增加到1000个怎么办?

 早上来了开始一个一个节点启动,到晚上下班刚好完成,下班?


5、SSH无密登录配置

5.1、配置ssh

(1)基本语法 

ssh  另一台电脑的ip地址

(2)ssh连接时出现Host key verification failed 的解决方法

[atguigu@hadoop102 opt] $ ssh 192.168.1.103
The authenticity of host '192.168.1.103 (192.168.1.103)' can't be established.
RSA key fingerprint is cf:1e:de:d7:d0:4c:2d:98:60:b4:fd:ae:b1:2d:ad:06.
Are you sure you want to continue connecting (yes/no)? 
Host key verification failed.

(3)解决方案如下:直接输入yes

5.2、 无密钥配置

(1)免密登录原理

 

(2)生成公钥和私钥:

[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

注意:

还需要在hadoop102上采用root账号,配置一下无密登录到hadoop102hadoop103hadoop104

还需要在hadoop103上采用atguigu账号配置一下无密登录到hadoop102hadoop103hadoop104服务器上。

 

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

known_hosts

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

id_rsa

生成的私钥

id_rsa.pub

生成的公钥

authorized_keys

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


6、群起集群

6.1、配置slaves

/opt/module/hadoop-2.7.2/etc/hadoop/slaves

[atguigu@hadoop102 hadoop]$ vi slaves

在该文件中增加如下内容:

hadoop102
hadoop103
hadoop104

注意:该文件中添加的内容结尾不允许有空格,文件中不允许有空行。

同步所有节点配置文件

[atguigu@hadoop102 hadoop]$ xsync slaves

6.2、启动集群

(1)如果集群是第一次启动,需要格式化NameNode(注意格式化之前,一定要先停止上次启动的所有namenodedatanode进程,然后再删除datalog数据)

[atguigu@hadoop102 hadoop-2.7.2]$ bin/hdfs namenode -format

2)启动HDFS

[atguigu@hadoop102 hadoop-2.7.2]$ sbin/start-dfs.sh
[atguigu@hadoop102 hadoop-2.7.2]$ jps
4166 NameNode
4482 Jps
4263 DataNode

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
[atguigu@hadoop103 hadoop-2.7.2]$ jps
3218 DataNode
3288 Jps

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

[atguigu@hadoop104 hadoop-2.7.2]$ jps
3221 DataNode
3283 SecondaryNameNode
3364 Jps

(3)启动YARN

[atguigu@hadoop103 hadoop-2.7.2]$ sbin/start-yarn.sh

注意:NameNodeResourceManger如果不是同一台机器,不能在NameNode上启动 YARN,应该在ResouceManager所在的机器上启动YARN

(4)Web端查看SecondaryNameNode

             (a)浏览器中输入:http://hadoop104:50090/status.html

              (b)查看SecondaryNameNode信息,如下图。

6.3、集群基本测试

(1)上传文件到集群

上传小文件

[atguigu@hadoop102 hadoop-2.7.2]$ hdfs dfs -mkdir -p /user/atguigu/input
[atguigu@hadoop102 hadoop-2.7.2]$ hdfs dfs -put wcinput/wc.input /user/atguigu/input

上传大文件 

[atguigu@hadoop102 hadoop-2.7.2]$ bin/hadoop fs -put  /opt/software/hadoop-2.7.2.tar.gz  /user/atguigu/input

(2)上传文件后查看文件存放在什么位置

(a)查看HDFS文件存储路径

[atguigu@hadoop102 subdir0]$ pwd

/opt/module/hadoop-2.7.2/data/tmp/dfs/data/current/BP-938951106-192.168.10.107-1495462844069/current/finalized/subdir0/subdir0

(b)查看HDFS在磁盘存储文件内容

[atguigu@hadoop102 subdir0]$ cat blk_1073741825
hadoop yarn
hadoop mapreduce 
atguigu
atguigu

(3)拼接

-rw-rw-r--. 1 atguigu atguigu 134217728 5月  23 16:01 blk_1073741836

-rw-rw-r--. 1 atguigu atguigu   1048583 5月  23 16:01 blk_1073741836_1012.meta

-rw-rw-r--. 1 atguigu atguigu  63439959 5月  23 16:01 blk_1073741837

-rw-rw-r--. 1 atguigu atguigu    495635 5月  23 16:01 blk_1073741837_1013.meta

[atguigu@hadoop102 subdir0]$ cat blk_1073741836>>tmp.file

[atguigu@hadoop102 subdir0]$ cat blk_1073741837>>tmp.file

[atguigu@hadoop102 subdir0]$ tar -zxvf tmp.file

(4)下载

[atguigu@hadoop102 hadoop-2.7.2]$ bin/hadoop fs  -get  /user/atguigu/input/hadoop-2.7.2.tar.gz  ./

演示:

[atguigu@hadoop104 hadoop-2.7.2]$ cd data/
[atguigu@hadoop104 data]$ tree
.
└── tmp
    ├── dfs
    │   ├── data
    │   │   ├── current
    │   │   │   ├── BP-2051365642-192.168.19.102-1548716028310
    │   │   │   │   ├── current
    │   │   │   │   │   ├── dfsUsed
    │   │   │   │   │   ├── finalized
    │   │   │   │   │   │   └── subdir0
    │   │   │   │   │   │       └── subdir0
    │   │   │   │   │   │           ├── blk_1073741825
    │   │   │   │   │   │           ├── blk_1073741825_1001.meta
    │   │   │   │   │   │           ├── blk_1073741826
    │   │   │   │   │   │           ├── blk_1073741826_1002.meta
    │   │   │   │   │   │           ├── blk_1073741827
    │   │   │   │   │   │           └── blk_1073741827_1003.meta
    │   │   │   │   │   ├── rbw
    │   │   │   │   │   └── VERSION
    │   │   │   │   ├── scanner.cursor
    │   │   │   │   └── tmp
    │   │   │   └── VERSION
    │   │   └── in_use.lock
    │   └── namesecondary
    │       ├── current
    │       │   ├── edits_0000000000000000003-0000000000000000004
    │       │   ├── fsimage_0000000000000000002
    │       │   ├── fsimage_0000000000000000002.md5
    │       │   ├── fsimage_0000000000000000004
    │       │   ├── fsimage_0000000000000000004.md5
    │       │   └── VERSION
    │       └── in_use.lock
    └── nm-local-dir
        ├── filecache
        ├── nmPrivate
        └── usercache

17 directories, 18 files
[atguigu@hadoop104 data]$ 
[atguigu@hadoop104 data]$ cd tmp/dfs/data/current/BP-2051365642-192.168.19.102-1548716028310/current/finalized/subdir0/
[atguigu@hadoop104 subdir0]$ cd subdir0/
[atguigu@hadoop104 subdir0]$ ll
总用量 194552
-rw-rw-r-- 1 atguigu atguigu        45 1月  29 08:53 blk_1073741825
-rw-rw-r-- 1 atguigu atguigu        11 1月  29 08:53 blk_1073741825_1001.meta
-rw-rw-r-- 1 atguigu atguigu 134217728 1月  29 08:54 blk_1073741826
-rw-rw-r-- 1 atguigu atguigu   1048583 1月  29 08:54 blk_1073741826_1002.meta
-rw-rw-r-- 1 atguigu atguigu  63439959 1月  29 08:56 blk_1073741827
-rw-rw-r-- 1 atguigu atguigu    495635 1月  29 08:56 blk_1073741827_1003.meta
[atguigu@hadoop104 subdir0]$ cat blk_1073741825
hadoop yarn
hadoop mapreduce
atguigu
atguigu

[atguigu@hadoop104 subdir0]$ 
 

注: blk_1073741825 正是前面本地模式中,官方WordCount案例,我测试的文件。

 

 [atguigu@hadoop104 subdir0]$ ll
总用量 194552
-rw-rw-r-- 1 atguigu atguigu        45 1月  29 08:53 blk_1073741825
-rw-rw-r-- 1 atguigu atguigu        11 1月  29 08:53 blk_1073741825_1001.meta
-rw-rw-r-- 1 atguigu atguigu 134217728 1月  29 08:54 blk_1073741826
-rw-rw-r-- 1 atguigu atguigu   1048583 1月  29 08:54 blk_1073741826_1002.meta
-rw-rw-r-- 1 atguigu atguigu  63439959 1月  29 08:56 blk_1073741827
-rw-rw-r-- 1 atguigu atguigu    495635 1月  29 08:56 blk_1073741827_1003.meta
[atguigu@hadoop104 subdir0]$ cat blk_1073741825
hadoop yarn
hadoop mapreduce
atguigu
atguigu
[atguigu@hadoop104 subdir0]$ cat blk_1073741826 >> temp.txt
[atguigu@hadoop104 subdir0]$ cat blk_1073741827 >> temp.txt 
[atguigu@hadoop104 subdir0]$ ll
总用量 387580
-rw-rw-r-- 1 atguigu atguigu        45 1月  29 08:53 blk_1073741825
-rw-rw-r-- 1 atguigu atguigu        11 1月  29 08:53 blk_1073741825_1001.meta
-rw-rw-r-- 1 atguigu atguigu 134217728 1月  29 08:54 blk_1073741826
-rw-rw-r-- 1 atguigu atguigu   1048583 1月  29 08:54 blk_1073741826_1002.meta
-rw-rw-r-- 1 atguigu atguigu  63439959 1月  29 08:56 blk_1073741827
-rw-rw-r-- 1 atguigu atguigu    495635 1月  29 08:56 blk_1073741827_1003.meta
-rw-rw-r-- 1 atguigu atguigu 197657687 1月  29 09:42 temp.txt
[atguigu@hadoop104 subdir0]$ tar -zxvf temp.txt 

...

 .........解压过程省略........

..........................

[atguigu@hadoop104 subdir0]$ ll
总用量 387584
-rw-rw-r-- 1 atguigu atguigu        45 1月  29 08:53 blk_1073741825
-rw-rw-r-- 1 atguigu atguigu        11 1月  29 08:53 blk_1073741825_1001.meta
-rw-rw-r-- 1 atguigu atguigu 134217728 1月  29 08:54 blk_1073741826
-rw-rw-r-- 1 atguigu atguigu   1048583 1月  29 08:54 blk_1073741826_1002.meta
-rw-rw-r-- 1 atguigu atguigu  63439959 1月  29 08:56 blk_1073741827
-rw-rw-r-- 1 atguigu atguigu    495635 1月  29 08:56 blk_1073741827_1003.meta
drwxr-xr-x 9 atguigu atguigu      4096 5月  22 2017 hadoop-2.7.2
-rw-rw-r-- 1 atguigu atguigu 197657687 1月  29 09:42 temp.txt
[atguigu@hadoop104 subdir0]$ cd hadoop-2.7.2/
[atguigu@hadoop104 hadoop-2.7.2]$ ll
总用量 52
drwxr-xr-x 2 atguigu atguigu  4096 5月  22 2017 bin
drwxr-xr-x 3 atguigu atguigu  4096 5月  22 2017 etc
drwxr-xr-x 2 atguigu atguigu  4096 5月  22 2017 include
drwxr-xr-x 3 atguigu atguigu  4096 5月  22 2017 lib
drwxr-xr-x 2 atguigu atguigu  4096 5月  22 2017 libexec
-rw-r--r-- 1 atguigu atguigu 15429 5月  22 2017 LICENSE.txt
-rw-r--r-- 1 atguigu atguigu   101 5月  22 2017 NOTICE.txt
-rw-r--r-- 1 atguigu atguigu  1366 5月  22 2017 README.txt
drwxr-xr-x 2 atguigu atguigu  4096 5月  22 2017 sbin
drwxr-xr-x 4 atguigu atguigu  4096 5月  22 2017 share

[atguigu@hadoop104 hadoop-2.7.2]$ 


7、集群启动/停止方式总结

7.1、各个服务组件逐一启动/停止

(1)分别启动/停止HDFS组件

hadoop-daemon.sh  start / stop  namenode / datanode / secondarynamenode

(2)启动/停止YARN

yarn-daemon.sh  start / stop  resourcemanager / nodemanager

7.2、各个模块分开启动/停止(配置ssh是前提)常用

(1)整体启动/停止HDFS

start-dfs.sh   /  stop-dfs.sh

(2)整体启动/停止YARN

start-yarn.sh  /  stop-yarn.sh

 8、集群时间同步

时间同步的方式:找一个机器,作为时间服务器,所有的机器与这台集群时间进行定时的同步,比如,每隔十分钟,同步一次时间。

原理图:

注:ntp 即:Network Time Protocol ,网络时间协议 的意思。 

配置时间同步具体实操:

1、时间服务器配置(必须root用户)

(1)检查ntp是否安装

[root@hadoop102 桌面]# rpm -qa|grep ntp

ntp-4.2.6p5-10.el6.centos.x86_64

fontpackages-filesystem-1.41-1.1.el6.noarch

ntpdate-4.2.6p5-10.el6.centos.x86_64

注:没有安装可以通过 yum 安装即可。 yum install ntp -y

(2)修改ntp配置文件

[root@hadoop102 桌面]# vi /etc/ntp.conf

修改内容如下

a)修改1(授权192.168.1.0-192.168.1.255网段上的所有机器可以从这台机器上查询和同步时间)
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap为
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

b)修改2(集群在局域网中,不使用其他互联网上的时间)
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst为
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst

c)添加3(当该节点丢失网络连接,依然可以采用本地时间作为时间服务器为集群中的其他节点提供时间同步)
server 127.127.1.0
fudge 127.127.1.0 stratum 10

(3)修改/etc/sysconfig/ntpd 文件

[root@hadoop102 桌面]# vim /etc/sysconfig/ntpd

增加内容如下(让硬件时间与系统时间一起同步)

SYNC_HWCLOCK=yes

(4)重新启动ntpd服务

[root@hadoop102 桌面]# service ntpd status
ntpd 已停
[root@hadoop102 桌面]# service ntpd start
正在启动 ntpd:                                            [确定]

(5)设置ntpd服务开机启动

[root@hadoop102 桌面]# chkconfig ntpd on

 注:取消开机启动。chkconfig ntpd off

2.    其他机器配置(必须root用户)

(1)在其他机器配置10分钟与时间服务器同步一次

[root@hadoop103桌面]# crontab -e

编写定时任务如下:

*/10 * * * * /usr/sbin/ntpdate hadoop102

(2)修改任意机器时间

[root@hadoop103桌面]# date -s "2017-9-11 11:11:11"

(3)十分钟后查看机器是否与时间服务器同步

[root@hadoop103桌面]# date

说明:测试的时候可以将10分钟调整为1分钟,节省时间。

猜你喜欢

转载自blog.csdn.net/qq_40794973/article/details/86681941