Spark on yarn 环境运行

Launching Spark on YARN

Ensure that HADOOP_CONF_DIR or YARN_CONF_DIR points to the directory which contains the (client side) configuration files for the Hadoop cluster. These configs are used to write to HDFS and connect to the YARN ResourceManager. The configuration contained in this directory will be distributed to the YARN cluster so that all containers used by the application use the same configuration. If the configuration references Java system properties or environment variables not managed by YARN, they should also be set in the Spark application’s configuration (driver, executors, and the AM when running in client mode).

There are two deploy modes that can be used to launch Spark applications on YARN. In cluster mode, the Spark driver runs inside an application master process which is managed by YARN on the cluster, and the client can go away after initiating the application. In clientmode, the driver runs in the client process, and the application master is only used for requesting resources from YARN.

Unlike other cluster managers supported by Spark in which the master’s address is specified in the --master parameter, in YARN mode the ResourceManager’s address is picked up from the Hadoop configuration. Thus, the --master parameter is yarn.

To launch a Spark application in cluster mode:

1、创建spark-env.sh

基于spark-env.sh.template 创建spark-env.sh文件

mv spark-env.sh.template spark-env.sh

2、修改spark-env.sh 

新增JAVA_HOME、YARN_CONF_DIR

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_211.jdk/Contents/Home/
export YARN_CONF_DIR=/Library/hadoop-2.7.3/etc/hadoop/

 3、执行Examples SparkPi

bin/spark-submit \
--class org.apache.spark.examples.SparkPi \
--master yarn \
--deploy-mode client \
--driver-memory 2g \
--driver-cores 1 \
--executor-memory 2g \
--executor-cores 1 \
examples/jars/spark-examples*.jar \
10
参数                                                                        解释

可选值举例

--class

Spark 程序中包含主函数的类

org.apache.spark.examples.SparkPi

--master

Spark 程序运行的模式(环境) 

local[*]、spark://linux1:7077、Yarn

--deploy-modeSpark程序运行模式

client、cluster

--driver-memory客户端内存
--driver-cores客户端核数
--executor-memory执行端内存
--executor-cores执行端核数
examples/jars/spark-examples*.jar--class对应的jar路径可以是HDFS、OSS

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在配置 Spark on YARN 环境之前,你需要确保以下条件已经满足: 1. 安装了 Hadoop 分布式文件系统和 YARN(Yet Another Resource Negotiator)资源管理器。 2. 下载和安装了 Spark。 接下来,你需要按照以下步骤配置 Spark on YARN 环境: 1. 在 Spark 安装目录中,找到 `conf` 目录并复制 `spark-env.sh.template` 文件并将其命名为 `spark-env.sh`。 2. 打开 `spark-env.sh` 文件并添加以下内容: ```bash export HADOOP_CONF_DIR=/path/to/hadoop/conf export YARN_CONF_DIR=/path/to/hadoop/conf export SPARK_EXECUTOR_MEMORY=1g export SPARK_DRIVER_MEMORY=1g export SPARK_YARN_APP_NAME=Spark export SPARK_HOME=/path/to/spark ``` 其中,`/path/to/hadoop/conf` 是你的 Hadoop 配置文件的路径,`/path/to/spark` 是你的 Spark 安装路径,`SPARK_EXECUTOR_MEMORY` 和 `SPARK_DRIVER_MEMORY` 分别设置了 Spark executor 和 driver 的内存大小,`SPARK_YARN_APP_NAME` 是 SparkYARN 上的应用名称。 3. 配置 Spark运行模式。在 `conf` 目录下找到 `spark-defaults.conf` 文件,并将以下内容添加到文件末尾: ```bash spark.master yarn spark.submit.deployMode client spark.driver.extraJavaOptions -Dhdp.version=2.7.3.2.6.0.3-8 spark.yarn.am.extraJavaOptions -Dhdp.version=2.7.3.2.6.0.3-8 spark.executor.extraJavaOptions -Dhdp.version=2.7.3.2.6.0.3-8 ``` `spark.master yarn` 表示 Spark 运行YARN 上,`spark.submit.deployMode client` 表示 Spark 运行在客户端模式下。 4. 启动 Spark on YARN。在 Spark 安装目录中运行以下命令: ```bash ./bin/spark-submit --class org.apache.spark.examples.SparkPi \ --master yarn \ --deploy-mode client \ --executor-memory 1g \ --num-executors 2 \ --driver-memory 1g \ --executor-cores 1 \ --queue default \ examples/jars/spark-examples_2.11-2.4.5.jar 10 ``` 这会启动一个 Spark 应用程序,并在 YARN 上分配 2 个执行器,并使用 1GB 的内存。 配置完成后,你可以在 Spark on YARN运行 Spark 应用程序了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值