注意:EC2 特定答案,而不是一般的 Spark 答案。只是想为一年前提出的一个问题提供一个答案,该问题具有相同的症状但通常是不同的原因,并且会绊倒很多人。
如果我对问题的理解正确,您会问:“我需要手动复制 jar 文件吗?如果需要,复制到哪个目录?”你说,“并设置 SparkConf 来分发类”,但你不清楚这是通过 spark-env.sh 还是 spark-defaults.conf 完成的?所以做一些假设,主要是你在集群模式下运行,这意味着你的驱动程序在其中一个工作人员上运行,而你事先不知道哪个工作人员......然后......
答案是肯定的,在类路径中命名的目录。在 EC2 中,唯一的持久数据存储是 /root/persistent-hdfs,但我不知道这是否是个好主意。
In the Spark docs on EC2 I see this line:
To deploy code or data within your cluster, you can log in and use
the provided script ~/spark-ec2/copy-dir, which, given a directory
path, RSYNCs it to the same location on all the slaves.
SPARK_CLASSPATH
我不会使用 SPARK_CLASSPATH,因为它在 Spark 1.0 中已被弃用,所以一个好主意是在 $SPARK_HOME/conf/spark-defaults.conf 中使用它的替换:
spark.executor.extraClassPath /path/to/jar/on/worker
这应该是可行的选项。如果您需要即时执行此操作,而不是在 conf 文件中,建议使用“./spark-submit with --driver-class-path 来扩充驱动程序类路径”(from Spark docs about spark.executor.extraClassPath 并查看另一个答案的结尾来源)。
但是...您没有使用 spark-submit ...我不知道它在 EC2 中是如何工作的,查看脚本我不知道 EC2 在哪里让您在命令行上提供这些参数。您提到您在设置 SparkConf 对象时已经这样做了,所以如果这对您有用,请坚持下去。
我在 Spark-years 看到这是一个非常古老的问题,所以我想知道您是如何解决的?我希望这对某人有所帮助,我在研究 EC2 的细节方面学到了很多东西。
我必须承认,作为对此的限制,它在Spark docs that for spark.executor.extraClassPath 中说:
用户通常不需要设置此选项
我认为他们的意思是大多数人将通过驱动程序配置选项获取类路径。我知道 spark-submit 的大多数文档都让它应该像脚本处理在集群中移动你的代码但我认为这只是在我假设你没有使用的“独立客户端模式”下,我假设 EC2 必须在“独立集群模式。”
关于 SPARK_CLASSPATH 弃用的更多/背景:
更多背景让我想到 SPARK_CLASSPATH is deprecated is this archived thread. 和 this one, crossing the other thread 和 this one about a WARN message when using SPARK_CLASSPATH:
14/07/09 13:37:36 WARN spark.SparkConf:
SPARK_CLASSPATH was detected (set to 'path-to-proprietary-hadoop-lib/*:
/path-to-proprietary-hadoop-lib/lib/*').
This is deprecated in Spark 1.0+.
Please instead use:
- ./spark-submit with --driver-class-path to augment the driver classpath
- spark.executor.extraClassPath to augment the executor classpath