在先前Hadoop集群完成组装后,已经完成在linux虚拟机上运行hadoop自带程序wordcount,但是在用eclipse调试的过程中,一直出现很多问题,参考的文章是:http://www.cnblogs.com/xia520pi/archive/2012/05/20/2510723.html
其中,在完成添加相应的jar包后,运行的过程中先后出现了很多问题,如:
Exception in thread "main" java.net.UnknowHostException:unknow host : Master.Hadoop
查了很多资料,有的说是/etc/hosts不匹配引起的,但是我的/etc/hosts没有问题,最后,发现不是虚拟机的hosts有问题,而是windows的hosts文件没有修改,在C:\Windows\System32\drivers\etc下修改hosts文件,加上
192.168.1.2 Master.Hadoop
192.168.1.3 slave1..Hadoop
192.168.1.4 slave2.Hadoop
每台电脑都加上,但是接着运行,又出现了形如:
Exception in thread "main" java.lang.IllegalArgumentException: Wrong FS: hdfs://192.168.1.2:9000/user/keyan/newout, expected: hdfs://Master.Hadoop:9000
at org.apache.hadoop.fs.FileSystem.checkPath(FileSystem.java:310)
at org.apache.hadoop.hdfs.DistributedFileSystem.checkPath(DistributedFileSystem.java:99)
at org.apache.hadoop.hdfs.DistributedFileSystem.getPathName(DistributedFileSystem.java:155)
at org.apache.hadoop.hdfs.DistributedFileSystem.getFileStatus(DistributedFileSystem.java:453)
at org.apache.hadoop.fs.FileSystem.exists(FileSystem.java:648)
at org.apache.hadoop.mapreduce.lib.output.FileOutputFormat.checkOutputSpecs(FileOutputFormat.java:122)
at org.apache.hadoop.mapred.JobClient.submitJobInternal(JobClient.java:770)
at org.apache.hadoop.mapreduce.Job.submit(Job.java:432)
at org.apache.hadoop.mapreduce.Job.waitForCompletion(Job.java:447)
at org.apache.hadoop.examples.WordCount.main(WordCount.java:79)
的错误,查了很多资料都没有解决,最后发现时输出路径的问题:
conf.set("mapred.job.tracker", "192.168.1.2:9001");
String[] ars=new String[]{"hdfs://192.168.1.2:9000/user/keyan/input","hdfs://192.168.1.2:9000/user/keyan/newout"};
中输出改为”newout“,需要指出的是输入路径”hdfs://192.168.1.2:9000/user/keyan/input“一定要完整,否则找不到,
另外,在使用API操作HDFS时,一定要记得改权限,否则上传不了文件。