1、配置hdfs-site和core-site文件
<property>
<name>net.topology.implname>
<value>org.apache.hadoop.net.NetworkTopologyWithNodeGroupvalue>
property>
<property>
<name>net.topology.script.file.namename>
<value>/tmp/rack.pyvalue>
property>
<property>
<name>net.topology.nodegroup.awarename>
<value>truevalue>
property>
<property>
<name>dfs.block.replicator.classnamename>
<value>
org.apache.hadoop.hdfs.server.blockmanagement.BlockPlacementPolicyWithNodeGroup
value>
property>
<property>
<name>dfs.use.dfs.network.topologyname>
<value>falsevalue>
property>
2、nodegroup示例
192.168.0.1 /rack1/nodegroup1
192.168.0.2 /rack1/nodegroup1
192.168.0.3 /rack1/nodegroup2
192.168.0.4 /rack1/nodegroup2
192.168.0.5 /rack2/nodegroup3
192.168.0.6 /rack2/nodegroup3
添加脚本
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import sys
rack = {
"192.168.0.1": "/rack1/nodegroup1",
"192.168.0.2": "/rack1/nodegroup1",
"192.168.0.3": "/rack1/nodegroup2",
"192.168.0.4": "/rack1/nodegroup2",
"192.168.0.5": "/rack2/nodegroup3",
"192.168.0.6": "/rack2/nodegroup3",
}
if __name__ == "__main__":
if len(sys.argv) < 2:
sys.exit(1)
ip_address = sys.argv[1]
result = rack.get(ip_address, "/default-rack")
print(result)
给脚本授权
chmod +777 /tmp/rack.py
3、通过命令查看是否配置成功
hdfs dfsadmin -printTopology