如何使用spark-submit将环境变量传递给集群模式中的spark驱动程序

Gaë*_*ann 12 environment-variables apache-spark

spark-submit允许使用,配置执行程序环境变量--conf spark.executorEnv.FOO=bar,并且Spark REST API允许使用该environmentVariables字段传递一些环境变量.不幸的是,spark-submit在集群模式下提交驱动程序时,我发现没有类似配置驱动程序的环境变量:

spark-submit --deploy-mode cluster myapp.jar
Run Code Online (Sandbox Code Playgroud)

是否可以spark-submit在群集模式下设置驱动程序的环境变量?

juh*_*tio 12

至少在YARN上,这有效:

spark-submit --deploy-mode cluster --conf spark.yarn.appMasterEnv.FOO=bar myapp.jar


它在http://spark.apache.org/docs/latest/configuration.html#environment-variables中提到:

注意:在cluster模式下在YARN上运行Spark时,需要使用文件中的spark.yarn.appMasterEnv.[EnvironmentVariableName]属性设置环境变量conf/spark-defaults.conf.

我已经测试过它可以带有--conf标志传递spark-submit,因此您不必编辑全局配置文件.

  • 为了使环境变量也受约束,您还需要添加:`--conf spark.executorEnv.FOO = bar` (3认同)

小智 6

在集群模式下的 Yarn 上,它通过使用 --conf 在 spark-submit 命令中添加环境变量来工作,如下所示-

spark-submit --master yarn-cluster --num-executors 15 --executor-memory 52g --executor-cores 7 --driver-memory 52g --conf "spark.yarn.appMasterEnv.FOO=/Path/foo" --conf "spark.executorEnv.FOO2=/path/foo2" app.jar

此外,您可以通过将它们添加到 conf/spark-defaults.conf 文件中来实现。


San*_*hay 5

您可以使用以下分类在执行器和主节点上设置环境变量:

[   
  {
   "Classification": "yarn-env",
   "Properties": {},
   "Configurations": [
       {
         "Classification": "export",
         "Properties": {
             "VARIABLE_NAME": VARIABLE_VALUE,
         }
       }
   ]
 }
]
Run Code Online (Sandbox Code Playgroud)

如果您只是 set spark.yarn.appMasterEnv.FOO = "foo",那么 env 变量将不会出现在 executor 实例上。

  • 分类是 EMR (AWS) 特定的机制。OP 没有指定使用 EMR (2认同)

Chi*_*iku -1

是的,这是可能的。您需要什么变量,您可以像您所做的那样将其发布到 Spark-Submit 中?

spark-submit --deploy-mode cluster myapp.jar
Run Code Online (Sandbox Code Playgroud)

从http://spark.apache.org/docs/latest/configuration.html获取变量,并根据您的优化使用这些变量。这个链接也可能有帮助。

我曾经在集群模式下使用,但现在我在 YARN 中使用,所以我的变量如下:(希望有帮助)

hastimal@nm:/usr/local/spark$ ./bin/spark-submit --class  com.hastimal.Processing  --master yarn-cluster  --num-executors 15 --executor-memory 52g --executor-cores 7 --driver-memory 52g  --driver-cores 7 --conf spark.default.parallelism=105 --conf spark.driver.maxResultSize=4g --conf spark.network.timeout=300  --conf spark.yarn.executor.memoryOverhead=4608 --conf spark.yarn.driver.memoryOverhead=4608 --conf spark.akka.frameSize=1200  --conf spark.io.compression.codec=lz4 --conf spark.rdd.compress=true --conf spark.broadcast.compress=true --conf spark.shuffle.spill.compress=true --conf spark.shuffle.compress=true --conf spark.shuffle.manager=sort /users/hastimal/Processing.jar Main_Class /inputRDF/rdf_data_all.nt /output /users/hastimal/ /users/hastimal/query.txt index 2
Run Code Online (Sandbox Code Playgroud)

在此,我的 jar 以下是类的参数。

抄送 /inputData/data_all.txt /输出 /users/hastimal/ /users/hastimal/query.txt 索引 2