Hadoop http address绑定内网地址

Hadoop默认配置里http address接口domain段均为0.0.0.0,表示可通过任一网卡访问http接口,对于双网卡服务器(一个内网,一个外网),意味着公网用户可以随意访问hadoop系统开放的web资源,存在极大的安全隐患。

我们可以修改配置将domain段替换成内网IP,这对于dfs.http.address、mapred.job.tracker.http.address没什么问题,但dfs.datanode.http.address需要到每个datanode上去修改,这太不现实了,可以通过以下方法实现自动配置。

通过local.bind.address参数 为http address绑定内网IP:

1、修改$HADOOP_HOME/conf/hadoop-env.sh

  1. #bind_ip=$(/sbin/ifconfig eth1:0 | grep 'inet addr:' | cut -d: -f2 | awk '{print $1}')
  2. #replace eth1:0 with your NIC / alias 这种方式需要所有机器内外网对应的网卡顺序一致
  3. #bind_ip=$(/sbin/ifconfig | fgrep 'inet addr:172.16' | cut -d: -f2 | awk '{print $1}')
  4. #这种方式需要所有机器内网IP前缀一致
  5. bind_ip=$(/bin/hostname)
  6. #这种方式需要在/etc/hosts里将hostname指向内网IP
  7. export BIND_OPTS="-Dlocal.bind.address=${bind_ip}"
  8. # Command specific options appended to HADOOP_OPTS when specified
  9. export HADOOP_NAMENODE_OPTS="-Dcom.sun.management.jmxremote $HADOOP_NAMENODE_OPTS $BIND_OPTS"
  10. export HADOOP_SECONDARYNAMENODE_OPTS="-Dcom.sun.management.jmxremote $HADOOP_SECONDARYNAMENODE_OPTS $BIND_OPTS"
  11. export HADOOP_DATANODE_OPTS="-Dcom.sun.management.jmxremote $HADOOP_DATANODE_OPTS $BIND_OPTS"
  12. export HADOOP_BALANCER_OPTS="-Dcom.sun.management.jmxremote $HADOOP_BALANCER_OPTS $BIND_OPTS"
  13. export HADOOP_JOBTRACKER_OPTS="-Dcom.sun.management.jmxremote $HADOOP_JOBTRACKER_OPTS $BIND_OPTS"

2、修改$HADOOP_HOME/conf/hdfs-site.xml

  1. <property>
  2. <property>
  3. <name>dfs.http.address</name>
  4. <value>${local.bind.address}:50070</value>
  5. </property>
  6. <property>
  7. <name>dfs.https.address</name>
  8. <value>${local.bind.address}:50470</value>
  9. </property>
  10. <property>
  11. <name>dfs.secondary.http.address</name>
  12. <value>${local.bind.address}:50090</value>
  13. </property>
  14. <property>
  15. <name>dfs.datanode.address</name>
  16. <value>${local.bind.address}:50010</value>
  17. </property>
  18. <property>
  19. <name>dfs.datanode.ipc.address</name>
  20. <value>${local.bind.address}:50020</value>
  21. </property>
  22. <property>
  23. <name>dfs.datanode.http.address</name>
  24. <value>${local.bind.address}:50075</value>
  25. </property>
  26. <property>
  27. <name>dfs.datanode.https.address</name>
  28. <value>${local.bind.address}:50475</value>
  29. </property>

3、修改$HADOOP_HOME/conf/mapred-site.xml

  1. <property>
  2. <name>mapred.job.tracker.http.address</name>
  3. <value>${local.bind.address}:50030</value>
  4. </property>
  5. <property>
  6. <name>mapred.task.tracker.http.address</name>
  7. <value>${local.bind.address}:50060</value>
  8. </property>

4、重启

  1. $HADOOP_HOME/bin/stop-all.sh
  2. $HADOOP_HOME/bin/start-all.sh

相关推荐