命令格式
【命令式】 spark-submit [options] <app jar | python file> [app options]
【例子】
spark-submit --master spark://host:7077 --executor-memory 10g my_script.py
参数 :
1. –master :指定 cluster connetion URL , 可以有多种集群设置模式:
| 值 | 说明 |
|---|---|
| spark://host:port | 连接到 spark standalone clustr ,默认端口为 7707 |
| mesos://host:port | 连接到 mesos cluster , 默认端口为 5050 |
| yarn | 连接到 Yarn cluster , 需要配置 HADOOP_CONF_DIR 环境变量 |
| local | 运行在本地模式,单核运行 |
| local[n] | 运行在本地模式,使用n核运行 |
| local[*] | 运行在本地模式,使用本机所有核运行 |
2. 常用 [options]
| 选项 | 说明 |
|---|---|
| –master | spark 连接 url |
| –deploy-mode | 运行driver的模式, client , 则在执行spark-submit的机上运行; cluster ,则交给集群去指定一台机器运行;默认是 client 。 |
| –class | main() 所在的 class ,要全名(针对java或scala)。 |
| –name | 指定运行的应用名称,将会在 webui 上显示 。 |
| –jars | 指定jar包列表,将添加到应用程序的 classpath 。 |
| –files | 指定file列表,这些文件会被部署到集群节点上。 |
| –py-files | 指定python文件、.zip文件 、 .eeg文件列表,将添加到应用程序的 PYTHONPATH 。 |
| –executor-memory | 给executor申请内存。 |
| –driver-memory | 给executor 申请内存。 |
部署到各cluster manager
部署 java 程序到 Standalone 使用 cluster 模式
./bin/spark-submit \
--master spark://hostname:7077 \
--deploy-mode cluster \
--class com.databricks.examples.SparkExample \
--name "Example Program" \
--jars dep1.jar,dep2.jar,dep3.jar \
--total-executor-cores 300 \
--executor-memory 10g \
myApp.jar "options" "to your application" "go here"
部署 python 程序到 yarn 使用 client 模式
export HADOOP_CONF_DIR=/opt/hadoop/conf
./bin/spark-submit \
--master yarn
--py-files somelib-1.2.egg,otherlib-4.4.zip,other-file.py \
--deploy-mode client \
--name "Example Program" \
--queue exampleQueue \
--num-executors 40 \
--executor-memory 10g \
my_script.py "options" "to your application" "go here"
本文介绍了Spark Submit命令的基本格式及常用参数,包括如何指定集群连接URL、运行模式、内存分配等,并提供了部署Java和Python程序的具体示例。

954

被折叠的 条评论
为什么被折叠?



