比如在hbase的master启动的时候,需要在zookeeper里注册自己的hostname,master取得hostname的方法是
String hostname = Strings.domainNamePointerToHostName(DNS.getDefaultHost( conf.get("hbase.master.dns.interface", "default"), conf.get("hbase.master.dns.nameserver", "default")));
DNS.getDefaultHost方法为
public static String getDefaultHost(String strInterface, String nameserver) throws UnknownHostException { if (strInterface.equals("default")) return InetAddress.getLocalHost().getCanonicalHostName(); if (nameserver != null && nameserver.equals("default")) return getDefaultHost(strInterface); String[] hosts = getHosts(strInterface, nameserver); return hosts[0]; }
如果/etc/hosts文件中存在以下这样的条目,InetAddress.getLocalHost().getCanonicalHostName()就会返回localhost,那么zookeeper里的master的hostname就成了localhost,那么region server无论如何都不能访问master了
引用
127.0.0.1 localhost dev02
所以要写成
引用
127.0.0.1 localhost
192.168.1.2 dev02
192.168.1.2 dev02
这个问题应该也是同样的原因