借鑒:https://blog.csdn.net/mnasd/article/details/80369603?utm_source=blogxgwz2
參考文檔:
1.快速入門
當前存儲集群的DN的空間占用率很不均衡,最大的使用率接近100%,最小的使用率不到35%。
為了平衡空間的占用率,我們在CDH上開啟了“重新平衡”。
調用的腳本實際如下:
hdfs/hdfs.sh ["balancer","-threshold","10.0","-policy","DataNode”]
查看當前的進度條:
Successfully moved blk_1255414776_181709174 with size=134217728 from 172.16.16.66:50010:DISK to 172.16.16.39:50010:DISK through 172.16.16.219:50010
重新平衡並沒有將空間占用率最高的DN優先執行。
2.命令行優化辦法
查看hdfs balancer的命令如下:
[root@R720ip39 ~]# hdfs balancer -help
Usage: java Balancer
[-policy <policy>] the balancing policy: datanode or blockpool
[-threshold <threshold>] Percentage of disk capacity
[-exclude [-f <hosts-file> | comma-sperated list of hosts]] Excludes the specified datanodes.
[-include [-f <hosts-file> | comma-sperated list of hosts]] Includes only the specified datanodes.
為了更高效率的執行balancer操作,建議如下:
-threshold 30 設置越大,越快結束,並且優先解決DN占用率高的
參數含義:判斷集群是否平衡的目標參數,每一個 datanode 存儲使用率和集群總存儲使用率的差值都應該小於這個閥值 ,理論上,該參數設置的越小,整個集群就越平衡,但是在線上環境中,hadoop集群在進行balance時,還在並發的進行數據的寫入和刪除,所以有可能無法到達設定的平衡參數值。
-include 包含如下的DN列表
dfs.balance.bandwidthPerSec 300MB(我們計算集群的設置)
參數含義:設置balance工具在運行中所能占用的帶寬,設置的過大可能會造成mapred運行緩慢。
執行命令如下:
hdfs balancer -policy datanode -threshold 30 -include -f /tmp/hdfs-blancer.txt
3.CDH中優化balancer實例
在CDH中,balancer是通過如下實例實現的。
幾個優化項:
優化一:
Balancer
閾值越高,需要平衡的量越少,DN占用率不夠均衡;閾值越低,需要平衡的量越大, DN占有率越均衡;
優化二:增大Balancer的Java堆大小
優化三:高級配置:
hdfs-site.xml 高級配置代碼段(安全閥)
#在DataNode和balancer實例都需要配置
<property>
<name>dfs.datanode.balance.max.concurrent.moves</name>
<value>50</value>
</property>
#在balancer實例配置
<property>
<name>dfs.balancer.moverThreads</name>
<value>5000</value>
</property>
<property>
<name>dfs.balancer.dispatcherThreads</name>
<value>5000</value>
</property>
<property>
<name>dfs.balancer.max-size-to-move</name>
<value>53687091200</value>
</property>
均衡block,執行start-balancer.sh
這個會非常耗時,但啟動后不中斷datanode服務執行,會占用帶寬和資源。可調整balance執行性能:
1)如果不balance,那么cluster會把新的數據都存放在新的node上,這樣會降低mapred的工作效率
2)設置平衡閾值,默認是10G[dfs.datanode.available-space-volume-choosing-policy.balanced-space-threshold=10737418240]。該屬性表示當各datanode的空閑空間差異達到10G時,就認為不平衡,將觸發datanode之間的balance,將空閑空間少的datanode的block向空閑空間多的datanode遷移,直到差異處於10G范圍內。
值越低各節點越平衡,但消耗時間也更長。例如:start-balancer.sh -threshold 5
3)設置balance的帶寬,默認只有1M/s [dfs.datanode.balance.bandwidthPerSec=1048576]
