Bind hadoop to a specific network device

quick and dirty

hadoop-env.sh:

  1. #replace eth1:0 with your NIC / alias
  2. bind_ip=$(/sbin/ifconfig eth1:0 | grep 'inet addr:' | cut -d: -f2 | awk '{print $1}')
  3.  
  4. export BIND_OPTS="-Dlocal.bind.address=${bind_ip}"
  5.  
  6. # Command specific options appended to HADOOP_OPTS when specified
  7. export HADOOP_NAMENODE_OPTS="-Dcom.sun.management.jmxremote $HADOOP_NAMENODE_OPTS $BIND_OPTS"
  8. export HADOOP_SECONDARYNAMENODE_OPTS="-Dcom.sun.management.jmxremote $HADOOP_SECONDARYNAMENODE_OPTS $BIND_OPTS"
  9. export HADOOP_DATANODE_OPTS="-Dcom.sun.management.jmxremote $HADOOP_DATANODE_OPTS $BIND_OPTS"
  10. export HADOOP_BALANCER_OPTS="-Dcom.sun.management.jmxremote $HADOOP_BALANCER_OPTS $BIND_OPTS"
  11. export HADOOP_JOBTRACKER_OPTS="-Dcom.sun.management.jmxremote $HADOOP_JOBTRACKER_OPTS $BIND_OPTS"
append to hdfs-site.xml:
  1. <property>
  2. <name>dfs.secondary.http.address</name>
  3. <value>${local.bind.address}:50090</value>
  4. <description>
  5. The secondary namenode http server address and port.
  6. If the port is 0 then the server will start on a free port.
  7. </description>
  8. </property>
  9.  
  10. <property>
  11. <name>dfs.datanode.address</name>
  12. <value>${local.bind.address}:50010</value>
  13. </property>
  14.  
  15. <property>
  16. <name>dfs.datanode.http.address</name>
  17. <value>${local.bind.address}:50075</value>
  18. </property>
  19.  
  20. <property>
  21. <name>dfs.datanode.ipc.address</name>
  22. <value>${local.bind.address}:50020</value>
  23. </property>
  24.  
  25. <property>
  26. <name>dfs.http.address</name>
  27. <value>${local.bind.address}:50070</value>
  28. </property>
  29.  
  30. <property>
  31. <name>dfs.datanode.https.address</name>
  32. <value>${local.bind.address}:50475</value>
  33. </property>
  34.  
  35. <property>
  36. <name>dfs.https.address</name>
  37. <value>${local.bind.address}:50470</value>
  38. </property>
you will also need to hardcode the HDFS URL in the core-site.xml by hand. This is not an issue since the same config should be deployed on all nodes in the cluster. Same pattern can be applied to mapred-site.xml - I did not need it.