spark-通过文件提交配置

spark-submit config through file

我正在尝试使用 spark-submit 部署 spark 作业,它有一堆参数,比如

spark-submit --class Eventhub --master yarn --deploy-mode cluster --executor-memory 1024m --executor-cores 4 --files app.conf spark-hdfs-assembly-1.0.jar --conf "app.conf"

我正在寻找一种方法将所有这些标志放入文件中以传递给 spark-submit 以使我的 spark-submit 命令简单如

spark-submit --class Eventhub --master yarn --deploy-mode cluster --config-file my-app.cfg --files app.conf spark-hdfs-assembly-1.0.jar --conf "app.conf"

有人知道这是否可行吗?

您可以使用 --properties-file,它应该包含带有起始关键字 spark 的参数,例如

spark.driver.memory 5g
spark.executor.memory 10g

命令应如下所示:

spark-submit --class Eventhub --master yarn --deploy-mode cluster --properties-file <path-to-your-conf-file> --files app.conf spark-hdfs-assembly-1.0.jar --conf "app.conf"

除了@FaigB提到的设置--properties外,另一种方法是使用conf/spark-defaults.conf。您可以通过执行 find-spark-home 或定位并查看 spark-env.sh 来找到它所在的位置。或者,您可以在调用 spark-submit 时或之前通过设置环境变量来定义此配置的存放位置,例如 SPARK_CONF_DIR=/your_dir/ spark-submit ...。如果您正在使用 YARN,设置 SPARK_CONF_DIR 将不起作用。您可以在此处找到更多信息 https://spark.apache.org/docs/latest/configuration.html#dynamically-loading-spark-properties