在Yarn上部署Spark程序,前提是启动HDFS和YARN,需要有相关环境。
Spark客户端直接连接Yarn,不需要额外构建Spark集群。有yarn-client和yarn-cluster两种模式,主要区别在于:Driver程序的运行节点。
yarn-client:Driver程序运行在客户端,适用于交互、调试,希望立即看到app的输出
yarn-cluster:Driver程序运行在由RM(ResourceManager)启动的AP(APPMaster)适用于生产环境。
配置
①修改hadoop配置文件yarn-site.xml,添加如下内容
[atguigu@hadoop102 hadoop]$ vi yarn-site.xml <!--是否启动一个线程检查每个任务正使用的物理内存量,如果任务超出分配值,则直接将其杀掉,默认是true --> <property> <name>yarn.nodemanager.pmem-check-enabled</name> <value>false</value> </property> <!--是否启动一个线程检查每个任务正使用的虚拟内存量,如果任务超出分配值,则直接将其杀掉,默认是true --> <property> <name>yarn.nodemanager.vmem-check-enabled</name> <value>false</value> </property>
②修改spark-env.sh,添加如下配置,指定Yarn配置文件所在目录
[atguigu@hadoop102 conf]$ vi spark-env.sh YARN_CONF_DIR=/opt/module/hadoop-2.7.2/etc/hadoop
执行程序
--master yarn 指定Master的地址为yarn(默认为local)
--deploy-mode client Driver运行在客户端
[atguigu@hadoop102 spark]$ bin/spark-submit \ --class org.apache.spark.examples.SparkPi \ --master yarn \ --deploy-mode client \ ./examples/jars/spark-examples_2.11-2.1.1.jar \ 100
查看执行进程
[atguigu@hadoop102 hadoop]$ yarn application -list 20/05/22 02:41:10 INFO client.RMProxy: Connecting to ResourceManager at hadoop103/192.168.138.129:8032 SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/opt/module/hadoop-2.7.2/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/opt/module/hbase/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory] Total number of applications (application-types: [] and states: [SUBMITTED, ACCEPTED, RUNNING]):1 Application-Id Application-Name Application-Type User Queue State Final-State Progress Tracking-URL application_1590086434708_0002 Spark Pi SPARK atguigu default ACCEPTED UNDEFINED 0% N/A