配置hadoop绑定内网地址

版本:hadoop-2.7.2

hadoop默认配置的监听地址都是 0.0.0.0 ,当然最简单暴力的方法就是去每个 datanode 上去修改 *-site.xml ,但是这样每个节点都要单独配置,非常的麻烦而且容易出错,但是我们可以通过变量统一设置:

1、修改 hadoop-env.sh
export BIND_OPTS="-Dlocal.bind.address=${HOSTNAME}"  
# Command specific options appended to HADOOP_OPTS when specified
export HADOOP_NAMENODE_OPTS="-Dhadoop.security.logger=${HADOOP_SECURITY_LOGGER:-INFO,RFAS} -Dhdfs.audit.logger=${HDFS_AUDIT_LOGGER:-INFO,NullAppender} $HADOOP_NAMENODE_OPTS $BIND_OPTS"  
export HADOOP_DATANODE_OPTS="-Dhadoop.security.logger=ERROR,RFAS $HADOOP_DATANODE_OPTS $BIND_OPTS"

export HADOOP_SECONDARYNAMENODE_OPTS="-Dhadoop.security.logger=${HADOOP_SECURITY_LOGGER:-INFO,RFAS} -Dhdfs.audit.logger=${HDFS_AUDIT_LOGGER:-INFO,NullAppender} $HADOOP_SECONDARYNAMENODE_OPTS $BIND_OPTS"  
2、修改 yarn-env.sh
export BIND_OPTS="-Dlocal.bind.address=${HOSTNAME}"  
YARN_OPTS="$YARN_OPTS $BIND_OPTS"  
3、修改 hdfs-site.xml
<property>  
    <name>dfs.datanode.address</name>  
    <value>${local.bind.address}:50010</value>  
</property> 

<property>  
    <name>dfs.datanode.http.address</name>  
    <value>${local.bind.address}:50075</value>  
</property> 

<property>  
    <name>dfs.datanode.ipc.address</name>  
    <value>${local.bind.address}:50020</value>  
</property>  
4、修改 yarn-site.xml
<property>  
    <name>yarn.nodemanager.localizer.address</name>
    <value>${local.bind.address}:8040</value>
</property>

<property>  
    <name>yarn.nodemanager.webapp.address</name>
    <value>${local.bind.address}:8042</value>
</property>  

重启后生效

5、配置说明参考