测试网络中有三台虚拟机。一台为NameNode,另两台为DataNode。
主机名 IP 角色
ubuntu 192.167.8.189 NameNode
ubuntu190 192.167.8.190 DataNode1
ubuntu192 192.167.8.192 DataNode2
NameNode所在主机名为ubuntu。由于其它两个虚拟机,都是克隆的NameNode虚拟机。导致了主机名都一样。
如果修改了主机名,而没有修改hosts文件。则DataNode所在的机器,启动DataNode时,可能会失败。
修改hosts文件。添加如下内容:
192.167.8.189 ubuntu
192.167.8.190 ubuntu190
192.167.8.192 ubuntu192
复制此hosts文件到NameNode、DataNode1、DataNode2机器上。
Core-site.xml配置文件内容
fs.defaultFS
hdfs://192.167.8.189:9000
io.file.buffer.size
131072
复制到NameNode、DataNode1、DataNode2机器上。
NamNode机器上Hdfs-site.xml文件的内容
dfs.replication
1
dfs.namenode.name.dir
/home/dreamcs/hadoopdata/name
dfs.blocksize
268435456
dfs.namenode.handler.count
10
dfs.namenode.datanode.registration.ip-hostname-check
false
DataNode1、DataNode2机器上Hdfs-site.xml文件的内容。
dfs.datanode.data.dir
/home/dreamcs/hadoopdata/data
dfs.blocksize
268435456
NamNode机器上Hdfs-site.xml文件,配置了一个特殊的字段:
dfs.namenode.datanode.registration.ip-hostname-check。
没有配置之前,会出现如下错误。
ERROR org.apache.hadoop.hdfs.server.datanode.DataNode: Initialization failed for Block pool BP-1184863888-172.17.0.3-1430984962919 (Datanode Uuid null) service to dockernamenode.zanox.com/172.17.0.3:8020 Datanode denied communication with namenode because hostname cannot be resolved (ip=172.17.0.5, hostname=172.17.0.5): DatanodeRegistration(0.0.0.0,
出错原因见如下文字:
So we have a namenode up and running, now we boot up a datanode. We have the defaultFS correct, so the datanode knows where the namenode is. It tries to connect to namenode. The connection happens through IP, so namenode only see the datanode's ip. The problem is, in this process. Namenode has a list of blacklisted hostnames, which should not connect to it.This list can be empty, but namenode will keep checking it anyway, so it will try to do a reverse dns lookup to see which hostname the ip has. If it fails, then namenode will throw the exception you saw, and this it the source of all problems.【1】
打开home目录下的.profile文件。在文件末尾配置如下两个环境变量。
HADOOP_PREFIX="$HOME/hadoop-2.8.0"
HADOOP_CONF_DIR="$HADOOP_PREFIX/etc/hadoop"
NameNode和DataNode之间,不设置免密码登录,也可以实现集群。
$HADOOP_PREFIX/sbin/hadoop-daemon.sh --script hdfs start namenode
$HADOOP_PREFIX/sbin/hadoop-daemons.sh --script hdfs start datanode
注意是hadoop-daemons.sh,而不是hadoop-daemon.sh。
通过Web查看NameNode。
通过Web查看DataNode。
【1】Why Datanode is Denied Communication With Namenode