6.1 NN内存
NameNode内存计算,每个文件块大概占用150byte,一台服务器128G内存为例,能存储多少文件块呢?
128 * 1024 * 1024 * 1024 / 150Byte ≈ 9.1亿
NameNode内存默认2000m,如果服务器内存4G,NameNode内存可以配置3g。在hadoop-env.sh文件中配置如下。
Hadoop2.x系列
HADOOP_NAMENODE_OPTS=-Xmx3072mHadoop3.x系列
hadoop-env.sh中描述Hadoop的内存是动态分配的
# The maximum amount of heap to use (Java -Xmx). If no unit
# is provided, it will be converted to MB. Daemons will
# prefer any Xmx setting in their respective _OPT variable.
# There is no default; the JVM will autoscale based upon machine
# memory size.
# export HADOOP_HEAPSIZE_MAX=
# The minimum amount of heap to use (Java -Xms). If no unit
# is provided, it will be converted to MB. Daemons will
# prefer any Xms setting in their respective _OPT variable.
# There is no default; the JVM will autoscale based upon machine
# memory size.
# export HADOOP_HEAPSIZE_MIN=
#设置NameNode内存如下
HADOOP_NAMENODE_OPTS=-Xmx102400m
默认linux不允许查看内存,如要查看内存执行命令如下
echo 0 |sudo tee /proc/sys/kernel/yama/ptrace_scope
查看当前计算机开启的进程
jps该命令下次计算机重启恢复原有设置

查看NameNode占用内存
jmap -heap 204511
结果:
MaxHeapSize = 1021313024 (974.0MB)
查看DataNode占用内存
jmap -heap 204686
结果:
MaxHeapSize = 1021313024 (974.0MB)
进过前两步会发现,默认情况NameNode和DataNode占用内存都是自动分配的,且相等。不是很合理。基于官网指导配置如下:

综上,NameNode最小值1G,每增加1000000个block,增加1G内存;DataNode最小值4G,block数、副本数升高,对应调整DataNode的值,一个DataNode副本总数低于4000000调为4G,每超过1000000增加1G。具体修改hadoop-env.sh文件。
export HDFS_NAMENODE_OPTS="-Dhadoop.security.logger=INFO,RFAS -Xmx1024m"
export HDFS_DATANODE_OPTS="-Dhadoop.security.logger=ERROR,RFAS -Xmx1024m"