集群启动顺序:
关于安全模式的一些操作
强调一下块(block)、副本数(replication)的概念
集群启动顺序:#
NameNode启动
NameNode启动时,首先将镜像文件(Fsimage)载入内存,并执行编辑日志(Edits)中的各项操作。一旦在内存中成功建立文件系统元数据的映像,则创建一个新的Fsimage文件和一个空的编辑日志。此时,NameNode开始监听DataNode请求。这个过程期间,NameNode一直运行在安全模式,即NameNode的文件系统对于客户端来说是只读的,并且是有限只读,即在没有启动DataNode的机器上的文件依旧不可读!
DataNode启动
系统中的数据块的位置并不是由NameNode维护的,而是以块列表的形式存储在DataNode中。在系统的正常操作期间,NameNode会在内存中保留所有块位置的映射信息。在安全模式下,各个DataNode会向NameNode发送最新的块列表信息,NameNode了解到足够多的块位置信息之后,即可退出安全模式。
安全模式退出判断
如果满足“最小副本条件”,NameNode会在30秒钟之后就退出安全模式。所谓的最小副本条件指的是在整个文件系统中99.9%的块满足最小副本级别(默认值:dfs.replication.min=1)。在启动一个刚刚格式化的HDFS集群时,因为系统中还没有任何块,所以NameNode不会进入安全模式。
当NN中所保存的所有块的最小副本数(默认为1) / 块的总数 > 99.99%时,NN会自动离开安全模式!

关于安全模式的一些操作#
集群处于安全模式,不能执行重要操作(写操作)。集群启动完成后,自动退出安全模式。
(1)bin/hdfs dfsadmin -safemode get (功能描述:查看安全模式状态[on/off])
(2)bin/hdfs dfsadmin -safemode enter (功能描述:进入安全模式)
(3)bin/hdfs dfsadmin -safemode leave (功能描述:离开安全模式)
(4)bin/hdfs dfsadmin -safemode wait (功能描述:输入写操作的命令,但不立即执行,而是放在缓存队列中,等待安全模式退出再依次执行)

强调一下块(block)、副本数(replication)的概念#
在hadoop2.x中,一个块的默认大小是128M,至于是为什么请看我之前的文章HDFS的文件块大小,
而一个块的副本数默认是3。
这些参数在hdfs-default.xml文件中有体现:

Copy

dfs.blocksize
134217728

The default block size for new files, in bytes.
You can use the following suffix (case insensitive):
k(kilo), m(mega), g(giga), t(tera), p(peta), e(exa) to specify the size (such as 128k, 512m, 1g, etc.),
Or provide complete size in bytes (such as 134217728 for 128 MB).


dfs.replication
3
Default block replication.
The actual number of replications can be specified when the file is created.
The default is used if replication is not specified in create time.


知道了上面的概念,那么就考大家一个小问题:
面试题:如果一个文件130M,将文件以块的方式分割,去存储,怎样实现?

Copy
实际存储 大小 副本
块A: 128M 128M A0 A1 A2
块B: 2M 128M B0 B1 B2
很明显,130M的文件,128M的块是存不下的,还需要2M的空间,虽然只有2M,但还是得分配一个块。

再来一个进阶题:
题目: 块大小128m,副本数3份,一个文件260m,请问多少块,多少实际存储?
存储块数:260%128=2块…4M,所以需要3个块,一个块有3个副本,所以最后需要33=9块
实际存储:260m
3 =780M

有人看到这儿就懵了,为什么是260*3呢?

分开算就一目了然了!
第一块有128M,第二块也是128M,第三块是剩下的4M,每一块有三个副本,那么:
128 3 + 128 3 + 4 3 = (128+128+4) 3 = 260 * 3

作者: 孙晨c

出处:https://www.cnblogs.com/sunbr/p/13277019.html

版权:本文采用「署名-非商业性使用-相同方式共享 4.0 国际」知识共享许可协议进行许可。https://www.jianshu.com/p/b3b9425d82fd
https://www.jianshu.com/p/2711c5f44ed2
https://www.jianshu.com/p/29b52764eb9c
https://www.jianshu.com/p/11a4d1e935c2
https://www.jianshu.com/p/29e061f86dcf
https://www.jianshu.com/p/75df376dc083
https://www.jianshu.com/p/155a7fdb0dad
https://www.jianshu.com/p/ee50485ea87e
https://www.jianshu.com/p/3fa284dd4ff5
https://www.jianshu.com/p/c6a1023fda73
https://www.jianshu.com/p/4cc30ea67488
https://www.jianshu.com/p/686bc7d382f2
https://www.jianshu.com/p/997501747683
https://www.jianshu.com/p/ea0cbd4355cc
https://www.jianshu.com/p/51708081d072
https://www.jianshu.com/p/02e882943c9b
https://www.jianshu.com/p/ed13a4feb0b1
https://www.jianshu.com/p/6f6a24cd347c
https://www.jianshu.com/p/295f05293dc2
https://www.jianshu.com/p/061f75d753fa
https://www.jianshu.com/p/45263df56f0f
https://www.jianshu.com/p/4a2590aa446a
https://www.jianshu.com/p/2f5a550a64ad
https://www.jianshu.com/p/5a9cf1a7211b
https://www.jianshu.com/p/0029378740e1
https://www.jianshu.com/p/357e6ed95748
https://www.jianshu.com/p/b5e3b04d92ad
https://www.jianshu.com/p/56a728c377bb
https://www.jianshu.com/p/df0159f5dfb0
https://www.jianshu.com/p/f79013501038
https://www.jianshu.com/p/b37572f506cb
https://www.jianshu.com/p/a89a41d83e11
https://www.jianshu.com/p/edef908e51fa
https://www.jianshu.com/p/b1a74b2efe04
https://www.jianshu.com/p/bd348f155466
https://www.jianshu.com/p/fea5a8888e81
https://www.jianshu.com/p/1d757058aa3b
https://www.jianshu.com/p/91f09a70237f
https://www.jianshu.com/p/cc0ea8a99538
https://www.jianshu.com/p/02a856d4cfc2
https://www.jianshu.com/p/86ddddc7a255
https://www.jianshu.com/p/b81483e87a5c
https://www.jianshu.com/p/3a770b8bdf01
https://www.jianshu.com/p/77af22836b07
https://www.jianshu.com/p/91740cdddbc8
https://www.jianshu.com/p/99837e6a265a
https://www.jianshu.com/p/7dbe4f0b0787
https://www.jianshu.com/p/8a03a2137baa
https://www.jianshu.com/p/71387f8877e1
https://www.jianshu.com/p/486cd5abfaea
https://www.jianshu.com/p/a1e3edc79e6b
https://www.jianshu.com/p/457d2b038e5d
https://www.jianshu.com/p/9d68b60bad12
https://www.jianshu.com/p/63719275910b
https://www.jianshu.com/p/3b62614d607e
https://www.jianshu.com/p/892558c571d0
https://www.jianshu.com/p/5970fb8d8031
https://www.jianshu.com/p/fba71414dbda
https://www.jianshu.com/p/cf60eadbc91d
https://www.jianshu.com/p/13c880862178
https://www.jianshu.com/p/cb78f976ee8b
https://www.jianshu.com/p/fe19a4a34970
https://www.jianshu.com/p/3b3d35fa04d5
https://www.jianshu.com/p/2f77b4d04aa3
https://www.jianshu.com/p/741dd9929d5c
https://www.jianshu.com/p/f5b3a760db10
https://www.jianshu.com/p/9e5a5917a5fe
https://www.jianshu.com/p/83e82102fc0f
https://www.jianshu.com/p/f2ed7f25e12e