Spark
2025年9月5日大约 1 分钟
spark-submit
spark-submit --class cn.shingi.etl.face.FaceETLJob --master spark://node12:7077 --total-executor-cores 12 --executor-cores 4 --jars /opt/cs/lib/postgresql-42.7.3.jar --driver-class-path /opt/cs/lib/postgresql-42.7.3.jar etl-face-1.0-SNAPSHOT.jar
--jars
--driver-class-path
都需要指定
- 脚本
#!/bin/bash
JARS=$(echo lib/*.jar | tr ' ' ',')
DRIVER_CP=$(echo lib/*.jar | tr ' ' ':')
spark-submit \
--class cn.shingi.etl.face.FaceETLJob \
--master spark://node12:7077 \
--total-executor-cores 12 \
--executor-cores 4 \
--jars $JARS \
--driver-class-path $DRIVER_CP \
etl-face-1.0-SNAPSHOT.jar
--conf "spark.driver.extraJavaOptions=-Dlog4j.configuration=file:path_of_file"
--conf "spark.executor.extraJavaOptions=-Dlog4j.configuration=file:path_of_file" \
指定日志
注意
不生效查看下配置文件是否正确
#!/bin/bash
JARS=$(echo ../lib/*.jar | tr ' ' ',')
DRIVER_CP=$(echo ../lib/*.jar | tr ' ' ':')
spark-submit \
--class cn.shingi.etl.datasplit.SplitApplication \
--master spark://node12:7077 \
--total-executor-cores 4 \
--executor-cores 1 \
--jars $JARS \
--driver-class-path $DRIVER_CP \
--files ../conf/application.properties,../conf/log4j2.properties \
--conf "spark.driver.extraJavaOptions=-Dlog4j.configurationFile=../conf/log4j2.properties" \
--conf "spark.executor.extraJavaOptions=-Dlog4j.configurationFile=../conf/log4j2.properties" \
../lib/etl-datasplit-1.0-SNAPSHOT.jar
指定executor
Standalone 模式下 --num-executors 参数不起作用
在 Spark Standalone 集群模式下,--num-executors 参数不生效。这个参数是针对 YARN 或 Kubernetes 这种资源管理器有效的
Standalone 模式下,你可以通过如下参数来控制 executor 的资源:
--executor-cores:每个 executor 分配的 CPU 核数
--executor-memory:每个 executor 分配的内存
更改ssh端口
export SPARK_SSH_OPTS="-p 7788"
creating dataframe
- List<Row>
List<Row> ids = new ArrayList<>();
StructType schema = new StructType(new StructField[]{
DataTypes.createStructField("id", DataTypes.StringType, false),
});
Dataset<Row> df = spark.createDataFrame(ids, schema);
Data Sources
- 查看支持的配置
进入对应的datasource 查看Data Source Option