HDFS Files remote lesen - Mit MS Windows Clients mit Hadoop arbeiten

HDFS Zugriff über Windows

Software Clients:

Java Klasse um vom Windows Host auf das HDFS zuzugreifen

package gpi.hadoop;
 
/**
see main code:
https://sites.google.com/site/hadoopandhive/home/hadoop-how-to-read-a-file-from-hdfs
*/
 
import java.io.*;
import org.apache.hadoop.fs.*;
import org.apache.hadoop.conf.*;
 
public class ReadHDFS {
 
    public static void main(String[] args) throws Exception {
        try {
            //configuration
            Configuration conf = new Configuration();
            Path path = new Path("hdfs://nosqldb01:9000/data/gpi/README.txt");
 
            //handle to the file
            FileSystem fs = FileSystem.get(path.toUri(), conf);
            FSDataInputStream inputStream = fs.open(path);
 
            //read the file
            BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
            String line;
            line = br.readLine();
            while (line != null) {
                System.out.println(line);
                line = br.readLine();
            }
 
        } catch (Exception e) {
            System.out.println(e.toString());
        }
 
    }
}
Fehler beim ersten Versuch:
2014-07-13 13:16:34,686 ERROR [main] util.Shell (Shell.java:getWinUtilsPath(336)) - Failed to locate the winutils binary in the hadoop binary path
java.io.IOException: Could not locate executable null\bin\winutils.exe in the Hadoop binaries.

Lösung:

Hadoop Home Directory setzen: Java Parameter hadoop.home.dir wie z.B: „-Dhadoop.home.dir=D:\entwicklung\libraries\hadoop-2.4.1“

UND

Die Libraries für Windows übersetzen siehe ⇒ https://wiki.apache.org/hadoop/Hadoop2OnWindows oder alternativ hier eine übersetze Version der Libraries laden ⇒ http://www.srccodes.com/p/article/39/error-util-shell-failed-locate-winutils-binary-hadoop-binary-path .

Hadoop local mit cygwin auf einen Windows 7 Rechner aufrufen

Cygwin installieren und Umgebung wie unter Linux in der .bashrc setzen:

#Hadoop Home
export HADOOP_HOME=/cygdrive/d/entwicklung/libraries/hadoop-2.4.1
 
# Avoid Java Lib errros
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native
export HADOOP_OPTS="-Djava.library.path=$HADOOP_HOME/lib -Dhadoop.home.dir=D:\entwicklung\libraries\hadoop-2.4.1"
 
# Hadoop environment Variables
export HADOOP_CONF_DIR=$HADOOP_HOME/etc/hadoop
export HADOOP_MAPRED_HOME=$HADOOP_HOME
export HADOOP_COMMON_HOME=$HADOOP_HOME
 
 
#JAVA
export JAVA_HOME=/cygdrive/d/entwicklung/java/jdk1.7.0_45
 
#fix CLASSPATH
export HADOOP_CLASSPATH=$(cygpath -pw $($HADOOP_HOME/bin/hadoop classpath)):$HADOOP_CLASSPATH
 
 
#Defaults
export PATH=$HADOOP_HOME/bin:$PATH

Beim ersten Test des ausgepackten Hadoop wird folgender Fehler mit dem Classpath geworfen:

$ ./hadoop version
Fehler: Hauptklasse org.apache.hadoop.util.VersionInfo konnte nicht gefunden oder geladen werden

Lösung: Umgebung anpassen oder im Script den Aufbau vom Klassenpfad anpassen:

export HADOOP_CLASSPATH=$(cygpath -pw $($HADOOP_HOME/bin/hadoop classpath)):$HADOOP_CLASSPATH

Hadoop Konfigurationsdateien auf den Windows Rechner kopieren.

Test:

hdfs dfs -ls /

Fehler:

2014-08-06 20:06:25,222 ERROR [main] util.Shell (Shell.java:getWinUtilsPath(336)                                                                                                                                                             ) - Failed to locate the winutils binary in the hadoop binary path
java.io.IOException: Could not locate executable null\bin\winutils.exe in the Ha                                                                                                                                                             doop binaries.
        at org.apache.hadoop.util.Shell.getQualifiedBinPath(Shell.java:318)

Lösung: Auch hier scheint ein Problem mit den Pfaden in Cygwin vorzuliegen, siehe dieses Jira Ticket https://issues.apache.org/jira/browse/HADOOP-10133 Datei $HADOOP_HOME\libexec\hadoop-config.sh anpassen:

# nach allen anderen HADOOP_OPTS das so setzen:
HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.home.dir="$(cygpath -pw "$HADOOP_PREFIX")""

Nächster Fehler:

Exception in thread "main" java.lang.RuntimeException: core-site.xml not found
        at org.apache.hadoop.conf.Configuration.loadResource(Configuration.java:                       
Lösung noch nicht gefunden, für jeden Tipp dankbar :-(