


<property> <name>dfs.datanode.du.reserved</name> <value>107374182400</value> </property>
上面這個參數的意思:
Reserved space in bytes per volume. Always leave this much space free for non dfs use.
再查看datanode日志,希望能找到可靠的線索:
這種錯誤無法通過namenode來避免,因為它不會再failed的時候去嘗試往別的節點寫數, 最初的辦法是將該節點的datanode關閉掉,就能順利地跑完這個mapreduce。
再者查看namenode的頁面,看到有好多datanode的節點的Remaining快要趨於0B了,這個時候就很容易出現上面的報錯。
The balancer is a tool that balances disk space usage on an HDFS cluster when some datanodes become full or when new empty nodes join the cluster.
The tool is deployed as an application program that can be run by the cluster administrator on a live HDFS cluster while applications adding and deleting files.
下面的圖片是官網中balancer命令得詳解:

start-balancer.sh -threshold 20 -policy blockpool -include -f /tmp/ip.txt
<property> <name>dfs.datanode.balance.bandwidthPerSec</name> <value>10485760</value> </property>
但是這個需要重啟,hadoop提供了一個動態調整的命令:
hdfs dfsadmin -fs hdfs://ns1:8020 -setBalancerBandwidth 104857600 hdfs dfsadmin -fs hdfs://ns2:8020 -setBalancerBandwidth 104857600 hdfs dfsadmin -fs hdfs://ns3:8020 -setBalancerBandwidth 104857600 hdfs dfsadmin -fs hdfs://ns4:8020 -setBalancerBandwidth 104857600 hdfs dfsadmin -fs hdfs://ns5:8020 -setBalancerBandwidth 104857600
hdfs dfs -get hdfs://ns1/test/dt=2016-07-24/000816_0.lzo hdfs dfs -put -f 000816_0.lzo hdfs://ns1/test/dt=2016-07-24/000816_0.lzo hdfs dfs -chown dd_edw:dd_edw hdfs://ns1/test/dt=2016-07-24/000816_0.lzo
前提條件需要將這個節點的datanode重新啟動。
hdfs dfs -setrep -R -w 2 hdfs://ns1/tmp/test.db
升副本的命令如下:
hdfs dfs -setrep -R -w 3 hdfs://ns1/tmp/test.db
上面的命令是將ns1下的/tmp/test.db副本數降至2個,然后又將它升至3哥副本。具體的hdfs dfs -setrep命令如下圖:
這樣動態的升降副本可以解決。
另外在升降副本的遇到一個BUG:
推測可能是namenode的replications模塊有夯住情況,所以出現該情況執行kill掉進行,跳過該塊再跑!
總結:之所以選擇使用升降副本是因為它不受帶寬的控制,另外在升降副本的時候hadoop是需要重新寫數的,這個時候它會優先往磁盤低寫數據,這樣就能將磁盤高的數據遷移至磁盤低的。
4、distcp
DistCp (distributed copy) is a tool used for large inter/intra-cluster copying. It uses MapReduce to effect its distribution, error handling and recovery, and reporting. It expands a list of files and directories into input to map tasks, each of which will copy a partition of the files specified in the source list. Its MapReduce pedigree has endowed it with some quirks in both its semantics and execution. The purpose of this document is to offer guidance for common tasks and to elucidate its model.
在這里舉一個例子:
通過distcp將/tmp/output12上的數據調用mapreduce遷移至/tmp/zhulh目錄下,原先/tmp/output12上的數據還是有存在的,但是它的塊就發生了變化。
這個時候有人可能會說怎么不使用cp命令呢?
兩者的區別如下:
CP的模式是不走mapreduce的;DISTCP的模式是走mapreduce的,所以它優先寫有nodemanager的機器;
CP是單線程的,類似scp的模式,在執行速度上比DISTCP要慢很多。
5、提高dfs.datanode.du.reserved值
官網是這么說的:Reserved space in bytes per volume. Always leave this much space free for non dfs use.
在上面的提到dfs.datanode.du.reserved的值是設成100G,因為namenode認為該節點還有剩余的空間,所以給分配到這里,假如這個塊是128K,但是實際剩余空間只有100K,所以就會報上面的錯誤,假如把dfs.datanode.du.reserved成300G,讓namenode知道該節點已經沒有剩余空間,所以就不會往這里寫數據了。
6、關閉nodemanger進程
在現有計算資源多余的情況下,可以考慮關閉高磁盤節點的nodemanager,避免在該節點起YarnChild,因為如果在該節點上進行計算的話,數據存儲首先會往本地寫一份,這樣更加加重了本地節點的負擔。
7、刪除舊數據
該方案是在迫不得已的情況下進行的,因為刪掉的數據可能以后還得補回來,這樣的話又是得要浪費一定的時間。
另外在刪除數據時候就得需要跳過回收站才能算是真正刪除,可以使用的命令如下:
本篇文章主要介紹了對hadoop數據出現不均衡情況下可以使用的方案,並以實例來解決問題!
對此有興趣的同學歡迎一起交流 。