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包很大的場景。