在hdfs-site.xml 配置文件按下面三个步骤添加参数。添加完同步至datanode节点。
1、数据存储磁盘参数设置多个磁盘目录
剩余磁盘空间大的在前面
<property>
<name>dfs.data.dir</name>
<value>/data1/dfs/dn,/mnt1/dfs/dn1,/mnt2/dfs/dn</value>
</property>
2、datanode多存储硬盘设置数据副本存放策略
第一种是沿用hadoop1.0的磁盘目录轮询方式,实现类:RoundRobinVolumeChoosingPolicy.java
第二种是选择可用空间足够多的磁盘方式存储,实现类:AvailableSpaceVolumeChoosingPolicy.java
hdfs-site.xml的配置样例:
<property>
<name>dfs.datanode.fsdataset.volume.choosing.policy</name>
<value>org.apache.hadoop.hdfs.server.datanode.fsdataset.AvailableSpaceVolumeChoosingPolicy</value>
</property>
<property>
<name>dfs.datanode.available-space-volume-choosing-policy.balanced-space-threshold</name>
<!--100G -->
<value>107374182400</value>
</property>
<property>
<name>dfs.datanode.available-space-volume-choosing-policy.balanced-space-preference-fraction</name>
<value>0.8f</value>
</property>
dfs.datanode.available-space-volume-choosing-policy.balanced-space-threshold
默认值是10737418240,既10G,一般使用默认值就行,以下是该选项的官方解释:
Only used when the dfs.datanode.fsdataset.volume.choosing.policy is set to org.apache.hadoop.hdfs.server.datanode.fsdataset.AvailableSpaceVolumeChoosingPolicy. This setting controls how much DN volumes are allowed to differ in terms of bytes of free disk space before they are considered imbalanced. If the free space of all the volumes are within this range of each other, the volumes will be considered balanced and block assignments will be done on a pure round robin basis. Support multiple size unit suffix(case insensitive), as described in dfs.blocksize.
意思是首先计算出两个值,一个是所有磁盘中最大可用空间,另外一个值是所有磁盘中最小可用空间,如果这两个值相差小于该配置项指定的阀值时,则就用轮询方式的磁盘选择策略选择磁盘存储数据副本
dfs.datanode.available-space-volume-choosing-policy.balanced-space-preference-fraction
默认值是0.75f,一般使用默认值就行,以下是该选项的官方解释:
Only used when the dfs.datanode.fsdataset.volume.choosing.policy is set to org.apache.hadoop.hdfs.server.datanode.fsdataset.AvailableSpaceVolumeChoosingPolicy. This setting controls what percentage of new block allocations will be sent to volumes with more available disk space than others. This setting should be in the range 0.0 - 1.0, though in practice 0.5 - 1.0, since there should be no reason to prefer that volumes with less available disk space receive more block allocations.
意思是有多少比例的数据副本应该存储到剩余空间足够多的磁盘上。该配置项取值范围是0.0-1.0,一般取0.5-1.0,如果配置太小,会导致剩余空间足够的磁盘实际上没分配足够的数据副本,而剩余空间不足的磁盘取需要存储更多的数据副本,导致磁盘数据存储不均衡。
3、hadoop dfs.datanode.du.reserved 预留空间配置方法
(通过实践这个参数最管用,前提是在步骤1的基础上)
对于datanode配置预留空间的方法为:
在hdfs-site.xml添加如下配置(因为磁盘容量较正常值小,则预留空间值一般设置偏大)
<property>
<name>dfs.datanode.du.reserved</name>
<value>21474836480</value>
</property>
dfs.datanode.du.reserved的单位为字节,预留30G:32212254720 预留20G:21474836480