![](/img/trans.png)
[英]spark-submit how to pass --driver-class-path in cluster mode?
[英]How to pass environment variables to spark driver in cluster mode with spark-submit
spark-submit
允许使用--conf spark.executorEnv.FOO=bar
配置执行器环境变量,Spark REST API 允许使用environmentVariables
字段传递一些环境变量。 不幸的是,在集群模式下使用spark-submit
驱动程序时,我没有发现与配置驱动程序环境变量类似的东西:
spark-submit --deploy-mode cluster myapp.jar
是否可以在集群模式下使用spark-submit
设置驱动程序的环境变量?
至少在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时,需要使用conf/spark-defaults.conf
文件中的spark.yarn.appMasterEnv.[EnvironmentVariableName]
属性设置环境变量。
我已经测试过它可以使用--conf
标志传递给spark-submit
,这样你就不必编辑全局conf文件了。
您可以使用以下分类在执行程序和主节点上设置环境变量:
[
{
"Classification": "yarn-env",
"Properties": {},
"Configurations": [
{
"Classification": "export",
"Properties": {
"VARIABLE_NAME": VARIABLE_VALUE,
}
}
]
}
]
如果只设置spark.yarn.appMasterEnv.FOO = "foo"
,那么env变量将不会出现在执行程序实例上。
在集群模式下的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文件中添加它们来完成此操作。
是的,这是可能的。 您需要在spark-submit中发布哪些变量,就像您正在做的那样?
spark-submit --deploy-mode cluster myapp.jar
从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
在这里,我的jar是类的参数。
cc /inputData/data_all.txt / output / users / hastimal / /users/hastimal/query.txt index 2
你测试过吗?
--conf spark.driver.FOO="bar"
然后获得价值
spark.conf.get("spark.driver.FOO")
deploy-mode cluster
正如前面提到的答案,如果你想将环境变量传递给 spark master,你想使用:
--conf spark.yarn.appMasterEnv.FOO=bar // pass bar value to FOO variable
--conf spark.yarn.appMasterEnv.FOO=${FOO} // passing current FOO env variable
--conf spark.yarn.appMasterEnv.FOO2=bar2 // multiple variables are passed separately
deploy-mode client
即使问题中没有提到它,如果您开始怀疑自己的技能并在谷歌中找到这个 SO 页面,我只是想向您保证。
使用client
模式时,当前 SHELL 中的所有 ENV 变量都可用于 spark master。 所以基本上:
export FOO=bar
export FOO2=bar2
肯定是有效的,所以如果你因为某种原因不能访问这个值,它一定是别的东西:-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.