美文网首页
Spark on YARN基础

Spark on YARN基础

作者: sparkle123 | 来源:发表于2020-11-17 11:59 被阅读0次

在Spark中,支持4种运行模式:

  • Local:开发调试时使用
  • Standalone:如果一个集群是Standalone的话,那么就需要在多台机器上同时部署Spark环境
  • YARN:在生产环境上使用该模式,统一使用YARN进行整个集群作业(MR、Spark)的资源调度
  • Mesos:目前使用较少

不管使用哪种模式,Spark应用程序的代码是一模一样的,只需要在提交的时候通过--master参数来指定我们的运行模式即可


Client
Driver运行在Client端(提交Spark作业的机器)
Client会和请求到的Container进行通信来完成作业的调度和执行,Client是不能退出的
日志信息会在控制台输出:便于我们测试


Cluster
Driver运行在ApplicationMaster中
Client只要提交完作业之后就可以关掉,因为作业已经在YARN上运行了
日志是在终端看不到的,因为日志是在Driver上,只能通过
yarn logs -applicationIdapplication_id


./bin/spark-submit \
--class org.apache.spark.examples.SparkPi \
--master yarn \
--executor-memory 1G \
--num-executors 1 \
/home/hadoop/app/spark-2.1.0-bin-2.6.0-cdh5.7.0/examples/jars/spark-examples_2.11-2.1.0.jar \
4

此处的yarn就是我们的yarn client模式
如果是yarn cluster模式的话,设置为yarn-cluster

Exception in thread "main" java.lang.Exception: When running with master 'yarn' either HADOOP_CONF_DIR or YARN_CONF_DIR must be set in the environment.

如果想运行在YARN之上,那么就必须要设置HADOOP_CONF_DIR或者是YARN_CONF_DIR

1)export HADOOP_CONF_DIR=/home/hadoop/app/hadoop-2.6.0-cdh5.7.0/etc/hadoop
2) $SPARK_HOME/conf/spark-env.sh
./bin/spark-submit \
--class org.apache.spark.examples.SparkPi \
--master yarn-cluster \
--executor-memory 1G \
--num-executors 1 \
/home/hadoop/app/spark-2.1.0-bin-2.6.0-cdh5.7.0/examples/jars/spark-examples_2.11-2.1.0.jar \
4

查看spark任务的日志
yarn logs -applicationId application_1495632775836_0002

相关文章

网友评论

      本文标题:Spark on YARN基础

      本文链接:https://www.haomeiwen.com/subject/qkcurftx.html