My Hadoop 버전 - 2.6.0 -cdh5.10.0 Cloudera Vm을 사용하고 있습니다.map reduce Java 프로그램을 통해 Hadoop hdfs 파일 시스템에 액세스 할 수 없습니다.
내 코드를 통해 hdfs 파일 시스템에 액세스하여 파일에 액세스하고이를 입력 또는 캐시 파일로 추가하려고합니다.
명령 줄을 통해 hdfs 파일에 액세스하려고하면 파일을 나열 할 수 있습니다.
명령 :
내지도를 통해 같은 일이 프로그램을 감소에 액세스하려고
[[email protected] java]$ hadoop fs -ls hdfs://localhost:8020/user/cloudera
Found 5items
-rw-r--r-- 1 cloudera cloudera 106 2017-02-19 15:48 hdfs://localhost:8020/user/cloudera/test
drwxr-xr-x - cloudera cloudera 0 2017-02-19 15:42 hdfs://localhost:8020/user/cloudera/test_op
drwxr-xr-x - cloudera cloudera 0 2017-02-19 15:49 hdfs://localhost:8020/user/cloudera/test_op1
drwxr-xr-x - cloudera cloudera 0 2017-02-19 15:12 hdfs://localhost:8020/user/cloudera/wc_output
drwxr-xr-x - cloudera cloudera 0 2017-02-19 15:16 hdfs://localhost:8020/user/cloudera/wc_output1
public int run(String[] args) throws Exception {
\t \t
\t \t Configuration conf = getConf();
\t \t
\t \t if (args.length != 2) {
\t \t \t System.err.println("Usage: test <in> <out>");
\t \t \t System.exit(2);
\t \t }
\t \t
\t \t ConfigurationUtil.dumpConfigurations(conf, System.out);
\t \t
\t \t LOG.info("input: " + args[0] + " output: " + args[1]);
\t \t
\t \t Job job = Job.getInstance(conf);
\t \t
\t \t job.setJobName("test");
\t \t
\t \t job.setJarByClass(Driver.class);
\t \t job.setMapperClass(Mapper.class);
\t \t job.setReducerClass(Reducer.class);
\t \t job.setMapOutputKeyClass(Text.class);
\t \t job.setMapOutputValueClass(Text.class);
\t \t
\t \t job.setOutputKeyClass(Text.class);
\t \t job.setOutputValueClass(DoubleWritable.class);
\t \t
\t \t
\t \t job.addCacheFile(new Path("hdfs://localhost:8020/user/cloudera/test/test.tsv").toUri());
\t \t
\t \t
\t \t FileInputFormat.addInputPath(job, new Path(args[0]));
\t \t FileOutputFormat.setOutputPath(job, new Path(args[1]));
\t \t
\t \t
\t \t boolean result = job.waitForCompletion(true);
\t \t return (result) ? 0 : 1;
\t }
위의 코드 조각의 행 job.addCacheFile
이 FileNotFound 예외를 반환합니다.2) 내 두 번째 질문은 :
내 로컬 호스트에 코어를 site.xml 지점에서 항목: 명령 프롬프트에서 기본 HDFS 파일 시스템 URI.But 9000 만 기본 HDFS 파일 시스템에 액세스 할 수 있어요 포트 9000을 사용하여 시도한 9000. 포트 8020에서 ConnectionRefused 예외로 끝났다. 구성을 읽는 위치를 잘 모르겠습니다. 다음과 같이
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
<!--
<property>
<name>hadoop.tmp.dir</name>
<value>/Users/student/tmp/hadoop-local/tmp</value>
<description>A base for other temporary directories.</description>
</property>
-->
<property>
<name>fs.default.name</name>
<value>hdfs://localhost:9000</value>
<description>Default file system URI. URI:scheme://authority/path scheme:method of access authority:host,port etc.</description>
</property>
</configuration>
내 HDFS-site.xml 파일은 다음과 같습니다 : 다음과 같이
내 코어를 site.xml은
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
\t <property>
\t \t <name>dfs.name.dir</name>
\t \t <value>/tmp/hdfs/name</value>
\t \t <description>Determines where on the local filesystem the DFS name
\t \t \t node should store the name table(fsimage).</description>
\t </property>
\t <property>
\t \t <name>dfs.data.dir</name>
\t \t <value>/tmp/hdfs/data</value>
\t \t <description>Determines where on the local filesystem an DFS data node should store its blocks.</description>
\t </property>
\t
\t <property>
\t \t <name>dfs.replication</name>
\t \t <value>1</value>
\t \t <description>Default block replication.Usually 3, 1 in our case
\t \t </description>
\t </property>
</configuration>
나는 받다. 다음과 같은 예외가 iving :
java.io.FileNotFoundException: hdfs:/localhost:8020/user/cloudera/test/ (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:146)
at java.io.FileInputStream.<init>(FileInputStream.java:101)
at java.io.FileReader.<init>(FileReader.java:58)
at hadoop.TestDriver$ActorWeightReducer.setup(TestDriver.java:104)
at org.apache.hadoop.mapreduce.Reducer.run(Reducer.java:168)
at org.apache.hadoop.mapred.ReduceTask.runNewReducer(ReduceTask.java:627)
at org.apache.hadoop.mapred.ReduceTask.run(ReduceTask.java:389)
at org.apache.hadoop.mapred.LocalJobRunner$Job$ReduceTaskRunnable.run(LocalJobRunner.java:319)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
어떤 도움이 도움이 될 것입니다!
당신은 당신이 –
@siddhartha 자이나교 감소지도를 통해 파일에 액세스하려고 할 때주는 인수 공유 할 수 있습니다 하둡 test.jar 경로 - 투 - driverclass HDFS를 -path-to-input 출력 – user1477232
프로그램에 의해 던지고있는 예외를 게시 할 수 있습니까 –