分享

hadoop指定文件输入参数问题

nwpu053871 发表于 2016-5-18 15:39:10 [显示全部楼层] 回帖奖励 阅读模式 关闭右栏 12 10893
各位好,我在eclipse中执行如下程序的时候报错。看起来是没有获取到文件输入相关的参数。麻烦大家帮忙看看是什么问题,谢谢!
看起来是这样没有起到作用
FileInputFormat.addInputPath(job, new Path("/user/hadoop/tmp/hello.txt"));// 文件输入

下面两句的输出分别如下:
System.out.println(FileInputFormat.getInputPaths(job));
System.out.println(FileOutputFormat.getOutputPath(job));

[Lorg.apache.hadoop.fs.Path;@5594a1b5
/user/hadoop/tmp
[mw_shl_code=java,true]package remote.file.manage;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import hadoop.*;

public class WordCount {
        public static void main(String[] args) throws Exception {
               
                Configuration conf = new Configuration();
                conf.set("fs.default.name", "hdfs://10.16.59.185:9000");
               
                Job job = new Job(conf, "word count");
               
                job.setJarByClass(WordCount.class);
                job.setMapperClass(WordMapper.class);
                job.setCombinerClass(WordReducer.class);
                job.setReducerClass(WordReducer.class);
               
                job.setOutputKeyClass(Text.class);
                job.setOutputValueClass(IntWritable.class);
               
                FileInputFormat.addInputPath(job, new Path("/user/hadoop/tmp/hello.txt"));// 文件输入
                FileOutputFormat.setOutputPath(job, new Path("/user/hadoop/tmp/"));// 文件输出

                System.out.println(FileInputFormat.getInputPaths(job));
                System.out.println(FileOutputFormat.getOutputPath(job));
                 
                System.exit(job.waitForCompletion(true) ? 0 : 1);// 等待完成退出
        }
}
[/mw_shl_code]


16/05/18 14:58:24 INFO jvm.JvmMetrics: Initializing JVM Metrics with processName=JobTracker, sessionId=
[Lorg.apache.hadoop.fs.Path;@5594a1b5
/user/hadoop/tmp
16/05/18 14:50:47 WARN mapred.JobClient: Use GenericOptionsParser for parsing the arguments. Applications should implement Tool for the same.
Exception in thread "main" org.apache.hadoop.security.AccessControlException: org.apache.hadoop.security.AccessControlException: Permission denied: user=corp\huangdezhi, access=WRITE, inode="":hadoop:supergroup:rwxr-xr-x
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.apache.hadoop.ipc.RemoteException.instantiateException(RemoteException.java:96)
at org.apache.hadoop.ipc.RemoteException.unwrapRemoteException(RemoteException.java:58)
at org.apache.hadoop.hdfs.DFSClient.mkdirs(DFSClient.java:910)
at org.apache.hadoop.hdfs.DistributedFileSystem.mkdirs(DistributedFileSystem.java:262)
at org.apache.hadoop.fs.FileSystem.mkdirs(FileSystem.java:1115)
at org.apache.hadoop.fs.FileSystem.mkdirs(FileSystem.java:259)
at org.apache.hadoop.mapred.JobClient.configureCommandLineOptions(JobClient.java:573)
at org.apache.hadoop.mapred.JobClient.submitJobInternal(JobClient.java:761)
at org.apache.hadoop.mapreduce.Job.submit(Job.java:432)
at org.apache.hadoop.mapreduce.Job.waitForCompletion(Job.java:447)
at remote.file.manage.WordCount.main(WordCount.java:31)

已有(12)人评论

跳转到指定楼层
qcbb001 发表于 2016-5-18 15:47:09
主函数继承下Tool

public class BookCount extends Configured implements Tool {

public static final Logger logger = Logger.getLogger(BookCount.class);

public static void main(String[] args) throws Exception {

PropertyConfigurator.configure("conf/log4j.properties");

logger.info("BookCountNew starting");

System.setProperty("HADOOP_USER_NAME", "hduser");

Configuration conf = new Configuration();

int res = ToolRunner.run(conf, new BookCount(), args);

logger.info("BookCountNew end");

System.exit(res);

}

第二设置下权限
hdfs-site.xml






回复

使用道具 举报

qcbb001 发表于 2016-5-18 15:51:49
回复

使用道具 举报

NEOGX 发表于 2016-5-18 16:08:25
hdfs上是否有这个文件/user/hadoop/tmp/hello.txt

回复

使用道具 举报

nwpu053871 发表于 2016-5-18 16:40:31
主函数继承了Tool,但是还是同样的错误。请看看是哪里写得有问题?
忽略权限的配置也已经加上去了的,错误看起来不是权限的问题(全都已经chmod 777 了),而是程序的问题:

[mw_shl_code=java,true]package remote.file.manage;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.filecache.DistributedCache;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
import org.apache.hadoop.util.GenericOptionsParser;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;

import hadoop.*;

public class WordCount extends Configured implements Tool {
        public static void main(String[] args) throws Exception {

                Configuration conf = new Configuration();
                conf.set("fs.default.name", "hdfs://10.16.59.185:9000");

                String[] myArgs = { "/user/hadoop/tmp/hello.txt", "/user/hadoop/tmp/xxxx" };

                int res = ToolRunner.run(conf, new WordCount(), myArgs);

                System.exit(res);// 等待完成退出

        }

        @Override
        public int run(String[] args) throws Exception {

                Job job = new Job(getConf(), "word count");

                job.setJarByClass(WordCount.class);
                job.setMapperClass(WordMapper.class);
                job.setCombinerClass(WordReducer.class);
                job.setReducerClass(WordReducer.class);

                job.setOutputKeyClass(Text.class);
                job.setOutputValueClass(IntWritable.class);

                String[] otherArgs = new GenericOptionsParser(job.getConfiguration(), args).getRemainingArgs();
                FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
                FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));

                job.waitForCompletion(true);
                return job.isSuccessful() ? 0 : 1;
        }
}
[/mw_shl_code]
回复

使用道具 举报

nwpu053871 发表于 2016-5-18 16:41:40
NEOGX 发表于 2016-5-18 16:08
hdfs上是否有这个文件/user/hadoop/tmp/hello.txt

有的,在hadoop本地执行没报同样的错误

回复

使用道具 举报

nwpu053871 发表于 2016-5-18 16:58:44
hadoop的版本是: 0.20.1
hadoop-0.20.1
回复

使用道具 举报

nwpu053871 发表于 2016-5-18 17:46:37
之前的permissions配错了,重新配置了之后,出现了新的错误:

Cannot run program "chmod": CreateProcess error=2, 系统找不到指定的文件。

还是权限的问题?导出jar包到服务器上本地执行是可以的
回复

使用道具 举报

nwpu053871 发表于 2016-5-18 17:48:17
nwpu053871 发表于 2016-5-18 17:46
之前的permissions配错了,重新配置了之后,出现了新的错误:

Cannot run program "chmod": CreateProce ...

另外,我用另外一个程序,也是在eclipse上跑,是可以读出来 /user/hadoop/tmp/hello.txt 的内容的
回复

使用道具 举报

nwpu053871 发表于 2016-5-18 17:50:12
文件的权限如下:
[hadoop@ci01v ~/hadoop-0.20.1/logs]$ hadoop fs -ls /user/hadoop/tmp/hello.txt
Found 1 items
-rw-rw-rw-   3 hadoop supergroup         30 2016-05-18 10:36 /user/hadoop/tmp/hello.txt
[hadoop@ci01v ~/hadoop-0.20.1/logs]$
回复

使用道具 举报

12下一页
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条