启动
然后,激动人心的时刻到了,所有配置都搞定了,我们可以启动了!
不过还有一件事情必须要先做,格式化名称空间。
在NameNode上,执行如下命令:
1. cd /Hadoop/bin
2. ./hadoop namenode -format
执行后结果如下:
然后就可以执行最后一个命令了:
1. ./start-all.sh
如果一切顺利的话,应该就成功了:
浏览NameNode和JobTracker的网络接口,它们的地址默认为:
- NameNode - http://localhost:50070/
- JobTracker - http://localhost:50030/
将输入文件拷贝到分布式文件系统:
$ bin/hadoop fs -put conf input
运行发行版提供的示例程序:
$ bin/hadoop jar hadoop-examples-*.jar grep inputoutput 'dfs[a-z.]+'
运行上述程序如果遇到java.net.NoRouteToHostException: No route to host错误,则
解决方法:网上有人说是/etc/hosts 下面的ip 和机器名没写对,有人说是防火墙没关。我遇到这个问题是由于防火墙没关,/etc/init.d/iptables stop关闭防火墙。
运行成功后查看输出文件:
将输出文件从分布式文件系统拷贝到本地文件系统查看:
$ bin/hadoop fs -get output output
$ cat output/*
或者
在分布式文件系统上查看输出文件:
$ bin/hadoop fs -cat output/*
完成全部操作后,停止守护进程:
$ bin/stop-all.sh
如果要关闭的话,可以执行
1. ./stop-all.sh
附录:常见错误解决:
http://hi.baidu.com/wyw5257/blog/item/39e51fd3c93d451c3af3cf28.html
1. 如果在bin/hadoopdfs -put /home/test-in input该过程中出现"can only bereplicated to node 0, instead of 1",以下两种办法,均可尝试。
1)解决办法一:
打开http://localhost:50070/dfshealth.jsp查看,确定了livenode数目为你的机器实际数目时,再进行put(注:如果有个别datanode没有启动起来,这是正常的,重新格式化文件系统,然后start-up)。
2)解决办法二:
当执行 #bin/hadoop dfs -put input input 时,报错 ...,could only bereplicated to 0 nodes, instead of 1,网上查了查,最后确定应该是iptables问题。
如果你的 conf/core-site.xml的配置是:
<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://machine1:9000/</value>
</property>
</configuration>
那么你应该将machine1的9000端口打开:
#iptables -I INPUT -p tcp --dport 9000 -j ACCEPT
然后可以查看
http://machine1:50070/dfshealth.jsp(你应该将500070端口也打开)
再执行,又报别的错:hdfs.DFSClient: Exception in createBlockOutputStreamjava.net.ConnectException: Connection refused
应该是datanode上的端口不能访问,到datanode上修改iptables:
#iptables -IINPUT -s machine1 -p tcp -j ACCEPT
OK 了!
2.如果put时出现java.io.IOException:Not a file: hdfs://localhost:9000/user/icymary/input/test-in
解决办法是bin/hadoop dfs -rmr input
bin/hadoop dfs -put /home/test-in input
原因是,当执行了多次put之后,就会在分布式文件系统中生成子目录,删除重新put即可。
3.如果在 bin/hadoop jarhadoop-0.16.0-examples.jar wordcount input output该过程中出现"canonly be replicated to node 0, instead of 1",解决办法是,给磁盘释放更多的空间,当时我的空间只有200M了,运行一直报错,折腾了1天。
4.如果 bin/hadoop jarhadoop-0.16.0-examples.jar wordcount input output过程中
INFO mapred.JobClient: map 0% reduce 0%
且一直卡住,在log日志中也没有出现异样,那么解决办法是,把/etc/hosts里面多余的机器名删掉,即可。
