Meine Hadoop-Version ist - 2.6.0 -cdh5.10.0 Ich benutze eine Cloudera Vm.Zugriff auf Hadoop-hdfs-Dateisystem durch Map Java-Programm reduzieren
Ich versuche, über meinen Code auf das hdfs-Dateisystem zuzugreifen, um auf die Dateien zuzugreifen und sie als Eingabe oder eine Cache-Datei hinzuzufügen.
Wenn ich versuche, über die Befehlszeile auf die hdfs-Datei zuzugreifen, kann ich die Dateien auflisten.
Befehl:
[[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
Wenn ich versuche, die gleiche Sache durch meine Karte reduzieren Programm zuzugreifen, erhalte ich Datei nicht gefunden Ausnahme. My Map reduzieren Beispielkonfigurationscode ist:
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 }
Die Linie job.addCacheFile in der obigen Snippet gibt FileNotFound Ausnahme.
2) Die zweite Frage ist:
Mein Eintrag bei Kern-site.xml Punkten auf localhost: 9000 für Standard-Dateisystem HDFS URI.But an der Eingabeaufforderung der Lage ist, das Standard-Dateisystem HDFS nur für den Zugriff auf an Port 8020 und nicht an 9000.wenn ich versuchte, Port 9000 zu verwenden, endete ich mit ConnectionRefused Exception. Ich bin mir nicht sicher, von wo die Konfigurationen gelesen werden.
Mein Kern-site.xml ist wie folgt:
<?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>
Mein hdfs-site.xml ist wie folgt:
<?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>
Ich bin empfangen iving die folgende Ausnahme:
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)
Jede Hilfe nützlich sein wird!
können Sie das Argument teilen, die Sie geben, wenn Sie die Datei über Karte zuzugreifen versuchen –
@siddhartha reduzieren Jain: hadoop test.jar path-to-Driver hdfs -path-to-input-Ausgang – user1477232
können Sie Ausnahme schreiben, die von Programm –