spark基本的提交语句:
./bin/spark-submit \ --class <main-class> \ --master <master-url> \ --deploy-mode <deploy-mode> \ --conf <key>=<value>\ ...
# other options <application-jar> \ [application-arguments]
参数的含义:
- --class: 主函数所在的类。
- --master: master的url,后面会解释 (e.g. spark://23.195.26.187:7077)
- --deploy-mode: 部署driver在本地仍是集群的一个work节点上,这也是client模式与cluster模式的区别。默认是client的模式。
- --conf:用 key=value形式指定参数,若是包含空格那么要用双引号引发来,例如“key=value”
- application-jar:jar包的路径.该路径必须在集群内全局可见。 例如: hdfs:// path 或者 file:// 这个path必须是全部节点都存在。.
- application-arguments: 传递给main函数 参数,如java main方法中的args[].
经常使用 提交模式:
第一种:client模式
适合于有专门的getway机器与集群位于同一网段,这种模式下,spark-submit提交后driver直接启动昨晚集群的一个client。集群的输出会返回到client端的console上。这种模式很适合spark-shell。
第二种:若是提交的机器远离spark集群的worker机器,最好使用cluster模式,该模式可以减小网络传输的错误。目前standalone模式并不支持py的这种方式。
对于cluster的管理还有一些参数要指定,好比说在standalone模式下,指定--supervise参数能够在driver在返回码是非0的退出后重启driver。下面是几种经常使用的提交命令参数:
#本地运行,指定8个core
./bin/spark-submit \
--class org.apache.spark.examples.SparkPi \
--master local[8] \
/path/to/examples.jar \
100
# 在 Spark standalone 集群而且是client模式
./bin/spark-submit \
--class org.apache.spark.examples.SparkPi \
--master spark://207.184.161.138:7077 \
--executor-memory 20G \
--total-executor-cores 100 \
/path/to/examples.jar \
1000
# 在 Spark standalone 集群而且是cluster模式 并指定supervise
./bin/spark-submit \
--class org.apache.spark.examples.SparkPi \
--master spark://207.184.161.138:7077 \
--deploy-mode cluster \
--supervise \
--executor-memory 20G \
--total-executor-cores 100 \
/path/to/examples.jar \
1000
# Yarn cluster模式export HADOOP_CONF_DIR=XXX
./bin/spark-submit\
--class org.apache.spark.examples.SparkPi \
--master yarn \
--deploy-mode cluster \
# can be client for client mode
--executor-memory 20G \
--num-executors 50 \
/path/to/examples.jar \
1000
# python提交到standalone的cluster模式
./bin/spark-submit \
--master spark://207.184.161.138:7077 \
examples/src/main/python/pi.py \
1000
# mesos cluster模式,并指定supervise。
./bin/spark-submit \
--class org.apache.spark.examples.SparkPi \
--master mesos://207.184.161.138:7077 \
--deploy-mode cluster \
--supervise \
--executor-memory 20G \
--total-executor-cores 100 \
http://path/to/examples.jar \
1000
关于master url的指定方法:
关于默认配置文件:
spark-submit会默认读取conf/spark-defaults.conf 里面设置 配置。
依赖管理:
使用spark-submit来提交spark程序,spark app自己jar以及使用--jars指定的全部jar包都会自动被分发到集群。--jars参数必须使用逗号分隔。spark使用下面这些方法指定jar来分发jar:
- file: - 绝对路径 file:/ dirver的http file server。executors会从该driver上拉取jar。
- hdfs:, http:, https:, ftp: -从这些位置拉取
- local: - 从worke所在 每台机器本地拉取文件,适合于jar包很大的场景。