Linux下搭建Hadoop遇到的未知的名称或服务错误

出现的错误如下:

14/12/01 22:15:38 INFO util.NativeCodeLoader: Loaded the native-hadoop library
14/12/01 22:15:39 INFO mapred.JobClient: Cleaning up the staging area file:/tmp/hadoop-root/mapred/staging/root897106301/.staging/job_local897106301_0001
14/12/01 22:15:39 ERROR security.UserGroupInformation: PriviledgedActionException as:root cause:java.net.UnknownHostException: Slave1: Slave1: 未知的名称或服务
java.net.UnknownHostException: Slave1: Slave1: 未知的名称或服务
at java.net.InetAddress.getLocalHost(InetAddress.java:1473)
at org.apache.hadoop.mapred.JobClient$2.run(JobClient.java:960)
at org.apache.hadoop.mapred.JobClient$2.run(JobClient.java:936)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:415)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1190)
at org.apache.hadoop.mapred.JobClient.submitJobInternal(JobClient.java:936)
at org.apache.hadoop.mapreduce.Job.submit(Job.java:550)
at org.apache.hadoop.mapreduce.Job.waitForCompletion(Job.java:580)
at org.apache.hadoop.examples.WordCount.main(WordCount.java:82)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.hadoop.util.ProgramDriver$ProgramDescription.invoke(ProgramDriver.java:68)
at org.apache.hadoop.util.ProgramDriver.driver(ProgramDriver.java:139)
at org.apache.hadoop.examples.ExampleDriver.main(ExampleDriver.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.hadoop.util.RunJar.main(RunJar.java:160)
Caused by: java.net.UnknownHostException: Slave1: 未知的名称或服务
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:901)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1293)
at java.net.InetAddress.getLocalHost(InetAddress.java:1469)
... 21 more

查资料后发现是hostname与/etc/hosts中的不对应。

解决方法:

先执行hostname命令看一下主机名,然后进/etc/hosts中修改任一行中的localhost为hostname显示的主机名。例如:

我执行hostname显示Slave1,进/etc/hosts,显示

127.0.0.1   localhost     localhost.localdomain     localhost4      localhost4.localdomain4
::1         localhost     localhost.localdomain      localhost6      localhost6.localdomain6

修改为:

127.0.0.1   localhost      localhost.localdomain    Slave1     localhost4.localdomain4
::1         localhost    localhost.localdomain    localhost6     localhost6.localdomain6

你可能感兴趣的:(Linux下搭建Hadoop遇到的未知的名称或服务错误)