Hadoop集群机架感应配置

首先在core-site.xml中配置如下参数:

<property>
    <name>topology.script.file.name</name>
    <value>/opt/Hadoop/bin/rackawareness.py</value>
    <description></description>
</property>

rackawareness.py脚本内容如下

#!/usr/bin/Python
import sys
from string import join

DEFAULT_RACK = '/default/rack0';

RACK_MAP = {
'192.168.1.10' : '/tvhadoop/rack0',
'192.168.1.11': '/tvhadoop/rack0',
'192.168.1.12' : '/tvhadoop/rack0',
'192.168.1.13': '/tvhadoop/rack0',
'192.168.1.14': '/tvhadoop/rack0',
'192.168.1.15' : '/tvhadoop/rack0',
'192.10.1.31' : '/tvhadoop/rack1',
'192.10.77.32' : '/tvhadoop/rack1',
'192.10.77.33' : '/tvhadoop/rack1',
'192.10.77.34' : '/tvhadoop/rack1'

}

if len(sys.argv)==1:
    print DEFAULT_RACK
else:
    print join([RACK_MAP.get(i, DEFAULT_RACK) for i in sys.argv[1:]]," ")

需要重启集群

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/ea8295c74e67906e9d24f1c12c8ef7b8.html