spark-submit命令总览

pyspark

可以使用pyspark 命令在服务器黑窗口中进行spark代码的编写

复制代码
pyspark --master local[2]   本地模式
pyspark --master spark://bigdata01:7077  standalone模式
pyspark --master yarn           yarn模式

// 启动一个黑窗口 进行任务的编写

spark-submit

复制代码
#提交任务的命令:
spark-submit [options] <app jar | pythonfile | R file> [app arguments]
spark-submit _04、wordcount_Vmware.py input output

#杀死一个正在运行的任务
spark-submit --kill [submission ID] --master [spark://...]

#查看某个任务的状态:
spark-submit --status [submission ID] --master [spark://...]

参数解释

复制代码
"""
各个参数的含义
其实就是在将 提交命令的 [options] 可以写什么。

"""
--master:用于指定程序运行的模式,5种模式,本地模式、
    Standalone、yarn、Mesos、K8s
    本地模式:--master local[2]
    Standalone模式:--master spark://master:7077
    YARN模式:--master yarn
    # 作用等同于代码中:setMaster
--deploy-mode:用于指定Driver进程运行位置 client/cluster
--name:用于指定程序的名称      # 作用等同于代码中:setAppName
--jars:用于指定一些额外的jar包 # 例如读写MySQL时候需要用到MySQL的驱动包
--conf:用于指定当前程序运行的额外的一些配置    # 作用等同于代码中:set


# driver资源选项:主要用于构建一个非RDD的操作
--driver-memory:指定Driver进程能够使用的内存大小,默认是1G
--driver-cores:指定Driver进程能够使用的CPU核数,默认是1Core
--supervise:指定如果Driver故障,就自动重启

# executor可以使用的参数

 --executor-cores 4 :指定每个Executor能够使用多少CPU
 --executor-memory 16 :指定每个Executor能够使用多少内存
 --total-executor-cores:Standalone集群模式,指定所有Executor总共使用的CPU核数,用于间接指定Executor的个数
 --num-executors:YARN集群模式,直接指定Executor的个数
 --queue:指定提交程序到哪个队列中运行
 
 # num-executors 和 total-executor-cores 不能同时使用
 
 以上这些参数,还可以直接写在代码中,可以配置在conf文件
优先级:代码中【set】 > 参数【--conf】 > 配置文件【公共配置:spark-defualt.conf】

代码实现

复制代码
standalone模式

# 最简单的
spark-submit \
--master spark://bigdata01:7077 \
_04、wordcount_Vmware.py \
hdfs://bigdata01:9820/spark/wordcount/input \
hdfs://bigdata01:9820/spark/wordcount/output5

# 指定资源的写法

spark-submit \
--master spark://bigdata01:7077 \
--driver-memory 512M \
--driver-cores 1 \
--supervise \
--executor-memory 1G \
--executor-cores 1 \
--total-executor-cores 2 \
_04、wordcount_Vmware.py \
hdfs://bigdata01:9820/spark/wordcount/input \
hdfs://bigdata01:9820/spark/wordcount/output6

yarn模式

spark-submit \
--master yarn \
--deploy-mode client \
--queue default \
--driver-memory 2G  \
--executor-memory 16G \
--executor-cores 4 \
--num-executors 40  \
--conf spark.sql.shuffle.partitions=1000    \
--conf spark.default.parallelism=1000 \
--conf spark.storage.memoryFraction=0.4 \
--conf spark.shuffle.memoryFraction=0.3 \
--principal gaoqi@JIERU.CUCCJS.COM \
--keytab  /home/gaoqi/gaoqi.keytab  \
--jars /data06/gaoqi/javaApp/spark-doris-connector-2.3_2.11-1.0.1.jar  \
/data06/gaoqi/spark_read_hive_stream_load_to_doris.py

spark模式和yarn模式最主要的区别

复制代码
spark 和yarn的区别
--master spark://bigdata01:7077
--total-executor-cores 2 \

--master yarn
--num-executors 2 \
相关推荐
helloweilei11 小时前
python 抽象基类
python
用户83562907805111 小时前
Python 实现 PPT 转 HTML
后端·python
SelectDB11 小时前
易车 × Apache Doris:构建湖仓一体新架构,加速 AI 业务融合实践
大数据·agent·mcp
zone773917 小时前
004:RAG 入门-LangChain读取PDF
后端·python·面试
zone773917 小时前
005:RAG 入门-LangChain读取表格数据
后端·python·agent
武子康18 小时前
大数据-241 离线数仓 - 实战:电商核心交易数据模型与 MySQL 源表设计(订单/商品/品类/店铺/支付)
大数据·后端·mysql
茶杯梦轩18 小时前
从零起步学习RabbitMQ || 第三章:RabbitMQ的生产者、Broker、消费者如何保证消息不丢失(可靠性)详解
分布式·后端·面试
IvanCodes18 小时前
一、消息队列理论基础与Kafka架构价值解析
大数据·后端·kafka
树獭非懒1 天前
AI大模型小白手册|Embedding 与向量数据库
后端·python·llm
唐叔在学习1 天前
就算没有服务器,我照样能够同步数据
后端·python·程序员