Spark on Yarn

版本:spark-2.3.0-bin-hadoop2.6
http://spark.apache.org/docs/latest/running-on-yarn.html

在YARN上启动Spark

确保HADOOP_CONF_DIRYARN_CONF_DIR指向Hadoop集群(客户端)配置目录。这些配置用于写入HDFS并连接到YARN ResourceManager。该目录中包含的配置文件将被分发到YARN集群,以便应用程序使用的所有容器具有相同的配置。如果配置引用了不是由YARN管理的Java系统属性或环境变量,还应该在Spark应用程序的配置(驱动程序,执行程序和以客户端模式运行时的AM)中对其进行设置。

Spark on Yarn 有两种部署模式。在cluster模式中,Spark驱动程序在由YARN管理的应用程序主进程内运行,客户端可以在启动应用程序后离开。在client模式下,驱动程序在客户端进程中运行,而应用程序主服务器仅用于从YARN请求资源。

与Spark支持的其他集群管理器不同,--master 参数中指定了master的地址,在YARN模式下,ResourceManager的地址从Hadoop配置中获取。因此,--master参数是yarn

cluster模式启动Spark应用程序:

$ ./bin/spark-submit --class path.to.your.Class 
           --master yarn 
           --deploy-mode cluster 
           [options] <app jar> [app options]

例如:

$ ./bin/spark-submit --class org.apache.spark.examples.SparkPi \
    --master yarn \
    --deploy-mode cluster \
    --driver-memory 4g \
    --executor-memory 2g \
    --executor-cores 1 \
    --queue thequeue \
    examples/jars/spark-examples*.jar \
    10

以上示例启动了一个YARN客户端程序,它将启动默认Application Master。然后SparkPi将作为Application Master的子线程运行。客户端将定期轮询AM的状态并将其显示在控制台中。一旦你的应用程序运行完毕,客户端将退出。有关如何查看驱动程序和执行程序日志的信息,请参阅下面的“调试应用程序”部分。

要在client模式下启动Spark应用程序,请执行相同的操作,但替换clusterclient。以下显示如何spark-shellclient模式下运行:

$ ./bin/spark-shell --master yarn --deploy-mode client

添加其他JAR

cluster模式下,驱动程序运行在与客户端不同的机器上,因此SparkContext.addJar 无法使用客户端本地文件开箱即用。要使客户端上的文件可用SparkContext.addJar,请使用--jars启动命令中的选项将它们包括在内。

$ ./bin/spark-submit --class my.main.Class \
    --master yarn \
    --deploy-mode cluster \
    --jars my-other-jar.jar,my-other-other-jar.jar \
    my-main-jar.jar \
    app_arg1 app_arg2

准备工作

在YARN上运行Spark需要使用YARN支持构建的Spark版本。二进制发行版可以从项目网站的下载页面下载。要自己构建Spark,请参阅Building Spark

为了从YARN端访问Spark运行时jar,你可以指定spark.yarn.archivespark.yarn.jars。有关详细信息,请参阅Spark属性。如果既没有指定spark.yarn.archive也没有spark.yarn.jars,Spark将创建一个包含所有jar文件的zip文件$SPARK_HOME/jars并将其上传到分布式缓存。

配置

YARN上的Spark大部分配置与其他部署模式都相同。有关这些的更多信息,请参阅配置页面。这些是在YARN上特定于Spark的配置。

调试您的应用程序

在YARN术语中,执行者和应用程序masters在“容器”内部运行。在应用程序完成后,YARN有两种处理容器日志的模式。如果打开日志聚合(使用yarn.log-aggregation-enable配置),容器日志将复制到HDFS中,而本地计算机上的日志将被删除。查看日志可以通过 yarn logs 命令从群集中的任何位置查看。

yarn logs -applicationId <app ID>

该命令会将指定的应用程序日志从所有的容器中打印所有的日志内容。您也可以使用HDFS shell 或API直接在HDFS中查看容器日志文件。他们所在的目录参考YARN配置(yarn.nodemanager.remote-app-log-diryarn.nodemanager.remote-app-log-dir-suffix)。日志也可以通过Spark Web UI中的Executors 标签页查看。你需要运行spark 历史服务器和MapReduce历史服务器,并在yarn-site.xml正确配置yarn.log.server.url。Spark历史记录服务器UI上的日志URL会将您重定向到MapReduce历史记录服务器以显示聚合日志。

当日志聚合未打开时,日志将保存在每台计算机上的本地YARN_APP_LOGS_DIR,通常配置为/tmp/logs$HADOOP_HOME/logs/userlogs,取决于Hadoop版本和安装配置。查看容器的日志需要转到包含它们的主机并查看此目录。子目录按应用程序ID和容器ID组织日志文件。日志也可以在执行程序选项卡下的Spark Web UI上使用,并且不需要运行MapReduce历史记录服务器。

要查看每个容器的启动环境,请增加yarn.nodemanager.delete.debug-delay-sec一个较大的值(例如36000),然后通过yarn.nodemanager.local-dirs 在启动容器的节点上访问应用程序缓存。该目录包含启动脚本,JAR以及用于启动每个容器的所有环境变量。这个过程特别适用于调试类路径问题。(请注意,启用此功能需要具有群集设置的管理权限并重新启动所有节点管理器。因此,这不适用于托管群集)。

要为应用程序master 或executor 使用自定义log4j配置,可以使用以下选项:

  • 使用spark-submit上传自定义log4j.properties,方法是添加--files参数中与应用程序一起上传的文件列表。
  • 添加-Dlog4j.configuration=<location of configuration file>spark.driver.extraJavaOptions (对于驱动程序)或spark.executor.extraJavaOptions(对于执行者)。请注意,如果使用文件,file:则应明确提供协议,并且文件需要在所有节点上本地存在。
  • 更新$SPARK_CONF_DIR/log4j.properties文件,它会自动与其他配置一起上传。请注意,如果指定了多个选项,其他2个选项的优先级高于此选项。

请注意,对于第一个选项,executor和master 将共享相同的log4j配置,这可能会导致在同一节点上运行时出现问题(例如尝试写入同一个日志文件)。

如果您需要使用正确的位置将日志文件放入YARN中,以便YARN可以正确显示并聚合它们,请在您的log4j.properties中配置spark.yarn.app.container.log.dir。例如,log4j.appender.file_appender.File=${spark.yarn.app.container.log.dir}/spark.log。对于流式应用程序,RollingFileAppender将文件位置配置到YARN的日志目录将避免由大型日志文件引起的磁盘溢出,并且可以使用YARN的日志工具访问日志。

要为master和 executor 使用自定义的metrics.properties,请更新该$SPARK_CONF_DIR/metrics.properties文件。它将自动与其他配置一起上传,因此您无需手动指定它--files

Spark属性

属性名称 默认 含义
spark.yarn.am.memory 512m 用于客户端模式下的YARN Application Master的内存量,格式与JVM内存字符串(例如512m2g)相同。在集群模式下,改为使用spark.driver.memory。使用小写字母后缀,例如kmgt,和p,分别代表kibi-,mebi-,gibi-,tebi-和pebibytes。
spark.yarn.am.cores 1 在客户端模式下用于YARN Application Master的核心数量。在集群模式下,改为使用spark.driver.cores
spark.yarn.am.waitTime 100s cluster模式中,YARN Application Master等待SparkContext被初始化的时间。在client模式中,YARN Application Master等待驱动程序连接的时间。
spark.yarn.submit.file.replication 默认为HDFS副本(通常3 应用程序上传到HDFS的HDFS复制级别。这些包括Spark jar,应用程序jar以及任何分布式缓存文件/存档等内容。
spark.yarn.stagingDir 当前用户在文件系统中的主目录 提交应用程序时使用的暂存目录。
spark.yarn.preserve.staging.files false 设置为true在作业结束时保留分段文件(Spark jar,app jar,分布式缓存文件),而不是删除它们。
spark.yarn.scheduler.heartbeat.interval-ms 3000 Spark master 到YARN ResourceManager的心跳时间间隔(以毫秒为单位)。该值被限制在YARN配置的到期时间间隔的一半值上,即 yarn.am.liveness-monitor.expiry-interval-ms的一半。
spark.yarn.scheduler.initial-allocation.interval 200ms 当容器分配请求时, Spark master节点到YARN ResourceManager的心跳时间间隔。它不应该大于 spark.yarn.scheduler.heartbeat.interval-ms。如果挂起的容器仍然存在,分配间隔会是连续的心跳加倍,直到达到spark.yarn.scheduler.heartbeat.interval-ms
spark.yarn.max.executor.failures numExecutors * 2,最少3 认定应用程序失败之前执行者失败的最大次数。
spark.yarn.historyServer.address (none) Spark历史记录服务器的地址,例如host.com:18080。地址不应该包含scheme(http://)。由于历史记录服务器是可选服务,因此缺省设置为未设置。当Spark应用程序完成将应用程序从ResourceManager UI链接到Spark历史记录服务器UI时,该地址将被提供给YARN ResourceManager。对于这个属性,YARN属性可以用作变量,并且这些属性在运行时被Spark替换。例如,如果Spark历史记录服务器与YARN ResourceManager在同一节点上运行,则可将其设置为${hadoopconf-yarn.resourcemanager.hostname}:18080
spark.yarn.dist.archives (none) 逗号分隔的档案列表被提取到每个执行者的工作目录中。
spark.yarn.dist.files (none) 逗号分隔的文件列表将放置在每个执行者的工作目录中。
spark.yarn.dist.jars (没有) 逗号分隔的jar列表将被放置在每个执行者的工作目录中。
spark.yarn.dist.forceDownloadSchemes (none) 在添加到YARN分布式缓存之前,文件将被下载到本地磁盘的逗号分隔列表。用于YARN服务不支持Spark支持的方案的情况,如http,https和ftp。
spark.executor.instances 2 静态分配的执行者数量。当启用spark.dynamicAllocation.enabled时,执行者数量将至少这么大。
spark.yarn.am.memoryOverhead AM 内存* 0.10,最小值为384 spark.driver.memoryOverhead客户端模式下的YARN Application Master 相同。
spark.yarn.queue default 提交应用程序的YARN队列的名称。
spark.yarn.jars (none) 包含要分发到YARN容器的Spark代码库的列表。默认情况下,Spark on YARN 将使用本地安装的Spark jar,但Spark jar也可以位于HDFS上都可读的位置。这允许YARN将它缓存在节点上,以便每次应用程序运行时不需要分发它。例如,要指向HDFS上的jar,请将此配置设置为hdfs:///some/path。Globs是允许的。
spark.yarn.archive (none) 一个包含需要的Spark Jars的档案,用于分发到YARN缓存。如果设置,则此配置会替换spark.yarn.jars并在所有应用程序的容器中使用该存档。归档文件应该在其根目录中包含jar文件。与之前的选项一样,存档也可以托管在HDFS上以加速文件分发。
spark.yarn.access.hadoopFileSystems (none) Spark应用程序将访问的安全Hadoop文件系统的逗号分隔列表。例如,spark.yarn.access.hadoopFileSystems=hdfs://nn1.com:8032,hdfs://nn2.com:8032, webhdfs://nn3.com:50070。Spark应用程序必须能够访问列出的文件系统,并且必须正确配置Kerberos以便能够访问它们(在相同的领域或受信任的领域)。Spark为每个文件系统获取安全令牌,以便Spark应用程序可以访问这些远程Hadoop文件系统。spark.yarn.access.namenodes 已弃用,请使用此代替。
spark.yarn.appMasterEnv.[EnvironmentVariableName] (none) 将指定的环境变量添加EnvironmentVariableName到在YARN上启动的应用程序主进程。用户可以指定其中的多个并设置多个环境变量。在cluster模式中,它控制Spark驱动程序的环境,并且在client模式下它仅控制执行程序启动程序的环境。
spark.yarn.containerLauncherMaxThreads 25 YARN Application Master中用于启动执行程序容器的最大线程数。
spark.yarn.am.extraJavaOptions (none) 一系列额外的JVM选项以客户端模式传递给YARN Application Master。在集群模式下,spark.driver.extraJavaOptions改为使用。请注意,使用此选项设置最大堆大小(-Xmx)设置是非法的。最大堆大小设置可以使用spark.yarn.am.memory
spark.yarn.am.extraLibraryPath (none) 在客户端模式下启动YARN Application Master时,设置一个特殊的库路径。
spark.yarn.maxAppAttempts yarn.resourcemanager.am.max-attempts 在YARN 提交申请的最大尝试次数。它不应该大于YARN配置中的全局最大尝试次数。
spark.yarn.am.attemptFailuresValidityInterval (没有) 定义AM故障跟踪的有效时间间隔。如果AM至少在定义的时间间隔内运行,则AM故障计数将被重置。如果未配置,此功能未启用。
spark.yarn.executor.failuresValidityInterval (没有) 定义执行器故障跟踪的有效时间间隔。比有效期间更早的执行程序故障将被忽略。
spark.yarn.submit.waitAppCompletion true 在YARN群集模式下,控制客户端是否等待退出,直到应用程序完成。如果设置为true,则客户端进程将保持活动状态,报告应用程序的状态。否则,客户端进程将在提交后退出。
spark.yarn.am.nodeLabelExpression (没有) 一个YARN节点标签表达式将限制节点集合AM的安排。只有大于或等于2.6的YARN版本才支持节点标签表达式,所以在针对早期版本运行时,该属性将被忽略。
spark.yarn.executor.nodeLabelExpression (没有) 一个YARN节点标签表达式将限制节点执行者集合的安排。只有大于或等于2.6的YARN版本才支持节点标签表达式,所以在针对早期版本运行时,该属性将被忽略。
spark.yarn.tags (没有) 逗号分隔的字符串列表将作为YARN应用程序标签出现在YARN ApplicationReports中传递,可用于在查询YARN应用程序时进行过滤。
spark.yarn.keytab (没有) 包含上面指定的主体的密钥表文件的完整路径。此密钥表将通过安全分布式缓存复制到运行YARN应用程序主控的节点,以定期更新登录凭单和代理令牌。(也与“当地”大师合作)
spark.yarn.principal (没有) 在安全的HDFS上运行时使用Principal来登录KDC。(也与“当地”大师合作)
spark.yarn.kerberos.relogin.period 1m 多久检查一次kerberos TGT是否应该更新。这应该设置为比TGT更新周期短的值(或者如果未启用TGT续订,则TGT寿命周期)。大多数部署的默认值应该足够了。
Property Name Default Meaning
spark.yarn.am.memory 512m Amount of memory to use for the YARN Application Master in client mode, in the same format as JVM memory strings (e.g. 512m, 2g). In cluster mode, use spark.driver.memory instead.Use lower-case suffixes, e.g. k, m, g, t, and p, for kibi-, mebi-, gibi-, tebi-, and pebibytes, respectively.
spark.yarn.am.cores 1 Number of cores to use for the YARN Application Master in client mode. In cluster mode, use spark.driver.cores instead.
spark.yarn.am.waitTime 100s In cluster mode, time for the YARN Application Master to wait for the SparkContext to be initialized. In client mode, time for the YARN Application Master to wait for the driver to connect to it.
spark.yarn.submit.file.replication The default HDFS replication (usually 3) HDFS replication level for the files uploaded into HDFS for the application. These include things like the Spark jar, the app jar, and any distributed cache files/archives.
spark.yarn.stagingDir Current user's home directory in the filesystem Staging directory used while submitting applications.
spark.yarn.preserve.staging.files false Set to true to preserve the staged files (Spark jar, app jar, distributed cache files) at the end of the job rather than delete them.
spark.yarn.scheduler.heartbeat.interval-ms 3000 The interval in ms in which the Spark application master heartbeats into the YARN ResourceManager. The value is capped at half the value of YARN's configuration for the expiry interval, i.e. yarn.am.liveness-monitor.expiry-interval-ms.
spark.yarn.scheduler.initial-allocation.interval 200ms The initial interval in which the Spark application master eagerly heartbeats to the YARN ResourceManager when there are pending container allocation requests. It should be no larger than spark.yarn.scheduler.heartbeat.interval-ms. The allocation interval will doubled on successive eager heartbeats if pending containers still exist, untilspark.yarn.scheduler.heartbeat.interval-ms is reached.
spark.yarn.max.executor.failures numExecutors * 2, with minimum of 3 The maximum number of executor failures before failing the application.
spark.yarn.historyServer.address (none) The address of the Spark history server, e.g. host.com:18080. The address should not contain a scheme (http://). Defaults to not being set since the history server is an optional service. This address is given to the YARN ResourceManager when the Spark application finishes to link the application from the ResourceManager UI to the Spark history server UI. For this property, YARN properties can be used as variables, and these are substituted by Spark at runtime. For example, if the Spark history server runs on the same node as the YARN ResourceManager, it can be set to ${hadoopconf-yarn.resourcemanager.hostname}:18080.
spark.yarn.dist.archives (none) Comma separated list of archives to be extracted into the working directory of each executor.
spark.yarn.dist.files (none) Comma-separated list of files to be placed in the working directory of each executor.
spark.yarn.dist.jars (none) Comma-separated list of jars to be placed in the working directory of each executor.
spark.yarn.dist.forceDownloadSchemes (none) Comma-separated list of schemes for which files will be downloaded to the local disk prior to being added to YARN's distributed cache. For use in cases where the YARN service does not support schemes that are supported by Spark, like http, https and ftp.
spark.executor.instances 2 The number of executors for static allocation. With spark.dynamicAllocation.enabled, the initial set of executors will be at least this large.
spark.yarn.am.memoryOverhead AM memory * 0.10, with minimum of 384 Same as spark.driver.memoryOverhead, but for the YARN Application Master in client mode.
spark.yarn.queue default The name of the YARN queue to which the application is submitted.
spark.yarn.jars (none) List of libraries containing Spark code to distribute to YARN containers. By default, Spark on YARN will use Spark jars installed locally, but the Spark jars can also be in a world-readable location on HDFS. This allows YARN to cache it on nodes so that it doesn't need to be distributed each time an application runs. To point to jars on HDFS, for example, set this configuration to hdfs:///some/path. Globs are allowed.
spark.yarn.archive (none) An archive containing needed Spark jars for distribution to the YARN cache. If set, this configuration replaces spark.yarn.jars and the archive is used in all the application's containers. The archive should contain jar files in its root directory. Like with the previous option, the archive can also be hosted on HDFS to speed up file distribution.
spark.yarn.access.hadoopFileSystems (none) A comma-separated list of secure Hadoop filesystems your Spark application is going to access. For example, spark.yarn.access.hadoopFileSystems=hdfs://nn1.com:8032,hdfs://nn2.com:8032, webhdfs://nn3.com:50070. The Spark application must have access to the filesystems listed and Kerberos must be properly configured to be able to access them (either in the same realm or in a trusted realm). Spark acquires security tokens for each of the filesystems so that the Spark application can access those remote Hadoop filesystems. spark.yarn.access.namenodes is deprecated, please use this instead.
spark.yarn.appMasterEnv.[EnvironmentVariableName] (none) Add the environment variable specified by EnvironmentVariableName to the Application Master process launched on YARN. The user can specify multiple of these and to set multiple environment variables. In cluster mode this controls the environment of the Spark driver and in client mode it only controls the environment of the executor launcher.
spark.yarn.containerLauncherMaxThreads 25 The maximum number of threads to use in the YARN Application Master for launching executor containers.
spark.yarn.am.extraJavaOptions (none) A string of extra JVM options to pass to the YARN Application Master in client mode. In cluster mode, use spark.driver.extraJavaOptions instead. Note that it is illegal to set maximum heap size (-Xmx) settings with this option. Maximum heap size settings can be set with spark.yarn.am.memory
spark.yarn.am.extraLibraryPath (none) Set a special library path to use when launching the YARN Application Master in client mode.
spark.yarn.maxAppAttempts yarn.resourcemanager.am.max-attempts in YARN The maximum number of attempts that will be made to submit the application. It should be no larger than the global number of max attempts in the YARN configuration.
spark.yarn.am.attemptFailuresValidityInterval (none) Defines the validity interval for AM failure tracking. If the AM has been running for at least the defined interval, the AM failure count will be reset. This feature is not enabled if not configured.
spark.yarn.executor.failuresValidityInterval (none) Defines the validity interval for executor failure tracking. Executor failures which are older than the validity interval will be ignored.
spark.yarn.submit.waitAppCompletion true In YARN cluster mode, controls whether the client waits to exit until the application completes. If set to true, the client process will stay alive reporting the application's status. Otherwise, the client process will exit after submission.
spark.yarn.am.nodeLabelExpression (none) A YARN node label expression that restricts the set of nodes AM will be scheduled on. Only versions of YARN greater than or equal to 2.6 support node label expressions, so when running against earlier versions, this property will be ignored.
spark.yarn.executor.nodeLabelExpression (none) A YARN node label expression that restricts the set of nodes executors will be scheduled on. Only versions of YARN greater than or equal to 2.6 support node label expressions, so when running against earlier versions, this property will be ignored.
spark.yarn.tags (none) Comma-separated list of strings to pass through as YARN application tags appearing in YARN ApplicationReports, which can be used for filtering when querying YARN apps.
spark.yarn.keytab (none) The full path to the file that contains the keytab for the principal specified above. This keytab will be copied to the node running the YARN Application Master via the Secure Distributed Cache, for renewing the login tickets and the delegation tokens periodically. (Works also with the "local" master)
spark.yarn.principal (none) Principal to be used to login to KDC, while running on secure HDFS. (Works also with the "local" master)
spark.yarn.kerberos.relogin.period 1m How often to check whether the kerberos TGT should be renewed. This should be set to a value that is shorter than the TGT renewal period (or the TGT lifetime if TGT renewal is not enabled). The default value should be enough for most deployments.
spark.yarn.config.gatewayPath (none) A path that is valid on the gateway host (the host where a Spark application is started) but may differ for paths for the same resource in other nodes in the cluster. Coupled withspark.yarn.config.replacementPath, this is used to support clusters with heterogeneous configurations, so that Spark can correctly launch remote processes.The replacement path normally will contain a reference to some environment variable exported by YARN (and, thus, visible to Spark containers).For example, if the gateway node has Hadoop libraries installed on /disk1/hadoop, and the location of the Hadoop install is exported by YARN as the HADOOP_HOME environment variable, setting this value to /disk1/hadoop and the replacement path to $HADOOP_HOMEwill make sure that paths used to launch remote processes properly reference the local YARN configuration.
spark.yarn.config.replacementPath (none) See spark.yarn.config.gatewayPath.
spark.security.credentials.${service}.enabled true Controls whether to obtain credentials for services when security is enabled. By default, credentials for all supported services are retrieved when those services are configured, but it's possible to disable that behavior if it somehow conflicts with the application being run. For further details please see Running in a Secure Cluster
spark.yarn.rolledLog.includePattern (none) Java Regex to filter the log files which match the defined include pattern and those log files will be aggregated in a rolling fashion. This will be used with YARN's rolling log aggregation, to enable this feature in YARN side yarn.nodemanager.log-aggregation.roll-monitoring-interval-seconds should be configured in yarn-site.xml. This feature can only be used with Hadoop 2.6.4+. The Spark log4j appender needs be changed to use FileAppender or another appender that can handle the files being removed while it is running. Based on the file name configured in the log4j configuration (like spark.log), the user should set the regex (spark*) to include all the log files that need to be aggregated.
spark.yarn.rolledLog.excludePattern (none) Java Regex to filter the log files which match the defined exclude pattern and those log files will not be aggregated in a rolling fashion. If the log file name matches both the include and the exclude pattern, this file will be excluded eventually.

重要笔记

  • 核心请求在调度决策中是否得到遵守取决于哪个调度程序正在使用以及它如何配置。
  • cluster模式下,Spark执行程序和Spark驱动程序使用的本地目录将是为YARN配置的本地目录(Hadoop YARN配置yarn.nodemanager.local-dirs)。如果用户指定spark.local.dir,它将被忽略。在client模式中,Spark执行程序将使用为YARN配置的本地目录,而Spark驱动程序将使用其中定义的目录spark.local.dir。这是因为Spark驱动程序不能在client模式下的YARN集群上运行,只有Spark执行程序会这样做。
  • --files--archives选项支持类似于Hadoop的 # 指定文件名。例如,您可以指定:--files localtest.txt#appSees.txt 并且这会将您本地命名的文件localtest.txt上载到HDFS,但是这将通过名称链接到appSees.txt,并且您的应用程序应该使用该名称appSees.txt来在YARN上运行时引用它。
  • 如果您使用本地文件并在cluster模式下运行,--jars选项允许该SparkContext.addJar功能起作用。如果您使用HDFS,HTTP,HTTPS或FTP文件,则不需要使用它。

在安全集群中运行

正如安全性所述,Kerberos用于安全的Hadoop集群中,以对与服务和客户端关联的主体进行身份验证。这允许客户提出这些认证服务的请求; 为授权委托人授予权利的服务。

Hadoop服务发布hadoop令牌来授予对服务和数据的访问权限。客户必须首先获取他们将访问的服务的标记,并将它们与其在YARN群集中启动的应用程序一起传递。

为了使Spark应用程序能够与任何Hadoop文件系统(例如hdfs,webhdfs等),HBase和Hive进行交互,它必须使用启动应用程序的用户的Kerberos凭据来获取相关的令牌 - 即身份标识的主体将成为启动的Spark应用程序的功能。

这通常在启动时完成:在安全集群中,Spark将自动获取群集的默认Hadoop文件系统的标记,并可能为HBase和Hive获取标记。

如果HBase位于类路径中,HBase配置声明应用程序是安全的(即hbase-site.xml设置hbase.security.authenticationkerberos)并且spark.security.credentials.hbase.enabled未设置为HBase令牌,则会获取HBase令牌false

同样,如果Hive位于类路径中,则会获得Hive标记,其配置包含元数据存储的URI "hive.metastore.uris,并且spark.security.credentials.hive.enabled未设置为false

如果应用程序需要与其他安全Hadoop文件系统交互,那么在启动时必须明确请求访问这些群集所需的令牌。这是通过将它们列在spark.yarn.access.hadoopFileSystems属性中完成的。

spark.yarn.access.hadoopFileSystems hdfs://ireland.example.org:8020/,webhdfs://frankfurt.example.org:50070/

Spark通过Java服务机制支持与其他安全感知服务的集成(请参阅参考资料 java.util.ServiceLoader)。为此,org.apache.spark.deploy.yarn.security.ServiceCredentialProvider Spark的实现应该可以通过将其名称列在jar META-INF/services目录中的相应文件中来使用 。这些插件可以通过设置来禁用 spark.security.credentials.{service}.enabledfalse,这里{service}是证书提供商的名称。

配置外部 Shuffle 服务

NodeManager在YARN群集中的每个群集上启动Spark Shuffle服务,请按照以下说明操作:

  1. 使用YARN配置文件构建Spark 。如果您使用的是预先打包的发行版,请跳过此步骤。
  2. 找到spark-<version>-yarn-shuffle.jar$SPARK_HOME/common/network-yarn/target/scala-<version>如果你正在自己构建Spark,并且在yarn使用发行版的情况下, 这应该在下面 。
  3. 将此jar添加到NodeManager群集中所有s 的类路径中。
  4. yarn-site.xml每个节点上,添加spark_shuffleyarn.nodemanager.aux-services,然后设置yarn.nodemanager.aux-services.spark_shuffle.classorg.apache.spark.network.yarn.YarnShuffleService
  5. NodeManager's通过设置YARN_HEAPSIZE(缺省etc/hadoop/yarn-env.sh 为1000)来增加堆大小,以避免在混洗期间垃圾收集问题。
  6. 重新启动NodeManager群集中的所有设备。

在YARN上运行shuffle服务时,以下额外配置选项可用:

| 属性名称 | 默认 | 含义 |
| spark.yarn.shuffle.stopOnFailure | false | Spark Shuffle服务初始化失败时是否停止NodeManager。这可以防止在Spark Shuffle服务未运行的NodeManagers上运行容器导致应用程序失败。 |

使用Apache Oozie启动您的应用程序

Apache Oozie可以将Spark应用程序作为工作流程的一部分启动。在安全集群中,启动的应用程序将需要相关的令牌来访问集群的服务。如果Spark使用密钥表启动,则这是自动的。但是,如果要在没有密钥表的情况下启动Spark,则必须将设置安全性的责任移交给Oozie。

可以在Oozie网站 的特定版本文档的“身份验证”部分找到有关为安全集群配置Oozie和获取作业凭证的详细信息。

对于Spark应用程序,必须为Oozie设置Oozie工作流程以请求应用程序需要的所有令牌,其中包括:

  • YARN资源管理器。
  • 本地Hadoop文件系统。
  • 用作I / O的源或目标的任何远程Hadoop文件系统。
  • 配置单元 - 如果使用。
  • 使用HBase -if。
  • YARN时间轴服务器,如果应用程序与此交互。

为了避免Spark试图获取Hive,HBase和远程HDFS令牌,然后失败,必须将Spark配置设置为禁用服务的令牌收集。

Spark配置必须包含以下行:

spark.security.credentials.hive.enabled   false
spark.security.credentials.hbase.enabled  false

配置选项spark.yarn.access.hadoopFileSystems必须未设置。

解决Kerberos问题

调试Hadoop / Kerberos问题可能很“困难”。一种有用的技术是通过设置HADOOP_JAAS_DEBUG 环境变量来在Hadoop中启用额外的Kerberos操作日志记录。

export HADOOP_JAAS_DEBUG=true

可以将JDK类配置为通过系统属性启用额外的Kerberos和SPNEGO / REST身份验证日志记录,sun.security.krb5.debug 以及sun.security.spnego.debug=true

-Dsun.security.krb5.debug=true -Dsun.security.spnego.debug=true

所有这些选项都可以在Application Master中启用:

spark.yarn.appMasterEnv.HADOOP_JAAS_DEBUG true
spark.yarn.am.extraJavaOptions -Dsun.security.krb5.debug=true -Dsun.security.spnego.debug=true

最后,如果日志级别org.apache.spark.deploy.yarn.Client设置为DEBUG,则日志将包含获取的所有令牌的列表及其到期的详细信息

使用Spark历史记录服务器来替换Spark Web UI

当应用程序UI被禁用时,可以使用Spark History Server应用程序页面作为运行应用程序的跟踪URL。这在安全集群上可能是需要的,或者减少Spark驱动程序的内存使用量。要通过Spark历史记录服务器设置跟踪,请执行以下操作:

  • 在应用程序方面,设置spark.yarn.historyServer.allowTracking=trueSpark的配置。如果应用程序的UI被禁用,这将告诉Spark使用历史记录服务器的URL作为跟踪URL。
  • 在Spark历史记录服务器上,添加org.apache.spark.deploy.yarn.YarnProxyRedirectFilterspark.ui.filters配置中的过滤器列表。

请注意,历史记录服务器信息可能不是应用程序状态的最新信息。

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 151,688评论 1 330
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 64,559评论 1 273
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 101,749评论 0 226
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 42,581评论 0 191
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 50,741评论 3 271
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 39,684评论 1 192
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,122评论 2 292
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 29,847评论 0 182
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 33,441评论 0 228
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 29,939评论 2 232
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 31,333评论 1 242
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 27,783评论 2 236
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 32,275评论 3 220
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 25,830评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,444评论 0 180
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 34,553评论 2 249
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 34,618评论 2 249

推荐阅读更多精彩内容