Spark Hadoop Free 安装遇到的问题
运行 ./sbin/start-master.sh :
- SparkCommand:/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java -cp /home/server/spark/conf/:/home/server/spark/jars/*:/home/server/hadoop/etc/hadoop/:/home/server/hadoop/share/hadoop/common/lib/:/home/server/hadoop/share/hadoop/common/:/home/server/hadoop/share/hadoop/mapreduce/:/home/server/hadoop/share/hadoop/mapreduce/lib/:/home/server/hadoop/share/hadoop/yarn/:/home/server/hadoop/share/hadoop/yarn/lib/ -Xmx1g org.apache.spark.deploy.master.Master --host ThinkPad-W550s-Lab --port 7077 --webui-port 8080
- ========================================
- Error: A JNI error has occurred, please check your installation and try again
- Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/Logger
- at java.lang.Class.getDeclaredMethods0(Native Method)
- at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
- at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
- at java.lang.Class.getMethod0(Class.java:3018)
- at java.lang.Class.getMethod(Class.java:1784)
- at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
- at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
- Caused by: java.lang.ClassNotFoundException: org.slf4j.Logger
- at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
- at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
- at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
- at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
- ... 7 more
参考Spark官网:http://spark.apache.org/docs/latest/hadoop-provided.html
Using Spark's "Hadoop Free" Build
Spark uses Hadoop client libraries for HDFS and YARN. Starting in version Spark 1.4, the project packages “Hadoop free” builds that lets you more easily connect a single Spark binary to any Hadoop version. To use these builds, you need to modify SPARK_DIST_CLASSPATH
to include Hadoop’s package jars. The most convenient place to do this is by adding an entry in conf/spark-env.sh
.
This page describes how to connect Spark to Hadoop for different types of distributions.
Apache Hadoop
For Apache distributions, you can use Hadoop’s ‘classpath’ command. For instance:
- ### in conf/spark-env.sh ###
- # If 'hadoop' binary is on your PATH
- export SPARK_DIST_CLASSPATH=$(hadoop classpath)
- # With explicit path to 'hadoop' binary
- export SPARK_DIST_CLASSPATH=$(/path/to/hadoop/bin/hadoop classpath)
- # Passing a Hadoop configuration directory
- export SPARK_DIST_CLASSPATH=$(hadoop --config /path/to/configs classpath)
最终在spark-env.sh文件添加如下配置:
- export SPARK_DIST_CLASSPATH=$(/usr/local/hadoop/hadoop-2.7.3/bin/hadoop classpath)
启动运行,成功!