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并連接到Y(jié)ARN ResourceManager。該目錄中包含的配置文件將被分發(fā)到Y(jié)ARN集群,以便應(yīng)用程序使用的所有容器具有相同的配置忍燥。如果配置引用了不是由YARN管理的Java系統(tǒng)屬性或環(huán)境變量局劲,還應(yīng)該在Spark應(yīng)用程序的配置(驅(qū)動程序占拍,執(zhí)行程序和以客戶端模式運行時的AM)中對其進(jìn)行設(shè)置沽讹。

Spark on Yarn 有兩種部署模式宾符。在cluster模式中,Spark驅(qū)動程序在由YARN管理的應(yīng)用程序主進(jìn)程內(nèi)運行梗掰,客戶端可以在啟動應(yīng)用程序后離開嵌言。在client模式下,驅(qū)動程序在客戶端進(jìn)程中運行及穗,而應(yīng)用程序主服務(wù)器僅用于從YARN請求資源摧茴。

與Spark支持的其他集群管理器不同,--master 參數(shù)中指定了master的地址埂陆,在YARN模式下苛白,ResourceManager的地址從Hadoop配置中獲取。因此焚虱,--master參數(shù)是yarn购裙。

cluster模式啟動Spark應(yīng)用程序:

$ ./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客戶端程序,它將啟動默認(rèn)Application Master鹃栽。然后SparkPi將作為Application Master的子線程運行躏率。客戶端將定期輪詢AM的狀態(tài)并將其顯示在控制臺中民鼓。一旦你的應(yīng)用程序運行完畢薇芝,客戶端將退出。有關(guān)如何查看驅(qū)動程序和執(zhí)行程序日志的信息摹察,請參閱下面的“調(diào)試應(yīng)用程序”部分恩掷。

要在client模式下啟動Spark應(yīng)用程序,請執(zhí)行相同的操作供嚎,但替換clusterclient黄娘。以下顯示如何spark-shellclient模式下運行:

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

添加其他JAR

cluster模式下,驅(qū)動程序運行在與客戶端不同的機器上克滴,因此SparkContext.addJar 無法使用客戶端本地文件開箱即用逼争。要使客戶端上的文件可用SparkContext.addJar,請使用--jars啟動命令中的選項將它們包括在內(nèi)劝赔。

$ ./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

準(zhǔn)備工作

在YARN上運行Spark需要使用YARN支持構(gòu)建的Spark版本誓焦。二進(jìn)制發(fā)行版可以從項目網(wǎng)站的下載頁面下載。要自己構(gòu)建Spark着帽,請參閱Building Spark杂伟。

為了從YARN端訪問Spark運行時jar,你可以指定spark.yarn.archivespark.yarn.jars仍翰。有關(guān)詳細(xì)信息赫粥,請參閱Spark屬性。如果既沒有指定spark.yarn.archive也沒有spark.yarn.jars予借,Spark將創(chuàng)建一個包含所有jar文件的zip文件$SPARK_HOME/jars并將其上傳到分布式緩存越平。

配置

YARN上的Spark大部分配置與其他部署模式都相同频蛔。有關(guān)這些的更多信息,請參閱配置頁面秦叛。這些是在YARN上特定于Spark的配置晦溪。

調(diào)試您的應(yīng)用程序

在YARN術(shù)語中,執(zhí)行者和應(yīng)用程序masters在“容器”內(nèi)部運行挣跋。在應(yīng)用程序完成后三圆,YARN有兩種處理容器日志的模式。如果打開日志聚合(使用yarn.log-aggregation-enable配置)浆劲,容器日志將復(fù)制到HDFS中嫌术,而本地計算機上的日志將被刪除。查看日志可以通過 yarn logs 命令從群集中的任何位置查看牌借。

yarn logs -applicationId <app ID>

該命令會將指定的應(yīng)用程序日志從所有的容器中打印所有的日志內(nèi)容度气。您也可以使用HDFS shell 或API直接在HDFS中查看容器日志文件。他們所在的目錄參考YARN配置(yarn.nodemanager.remote-app-log-diryarn.nodemanager.remote-app-log-dir-suffix)膨报。日志也可以通過Spark Web UI中的Executors 標(biāo)簽頁查看磷籍。你需要運行spark 歷史服務(wù)器和MapReduce歷史服務(wù)器,并在yarn-site.xml正確配置yarn.log.server.url现柠。Spark歷史記錄服務(wù)器UI上的日志URL會將您重定向到MapReduce歷史記錄服務(wù)器以顯示聚合日志院领。

當(dāng)日志聚合未打開時,日志將保存在每臺計算機上的本地YARN_APP_LOGS_DIR够吩,通常配置為/tmp/logs$HADOOP_HOME/logs/userlogs比然,取決于Hadoop版本和安裝配置。查看容器的日志需要轉(zhuǎn)到包含它們的主機并查看此目錄周循。子目錄按應(yīng)用程序ID和容器ID組織日志文件强法。日志也可以在執(zhí)行程序選項卡下的Spark Web UI上使用,并且不需要運行MapReduce歷史記錄服務(wù)器湾笛。

要查看每個容器的啟動環(huán)境饮怯,請增加yarn.nodemanager.delete.debug-delay-sec一個較大的值(例如36000),然后通過yarn.nodemanager.local-dirs 在啟動容器的節(jié)點上訪問應(yīng)用程序緩存嚎研。該目錄包含啟動腳本蓖墅,JAR以及用于啟動每個容器的所有環(huán)境變量。這個過程特別適用于調(diào)試類路徑問題临扮。(請注意论矾,啟用此功能需要具有群集設(shè)置的管理權(quán)限并重新啟動所有節(jié)點管理器。因此杆勇,這不適用于托管群集)拇囊。

要為應(yīng)用程序master 或executor 使用自定義log4j配置,可以使用以下選項:

  • 使用spark-submit上傳自定義log4j.properties靶橱,方法是添加--files參數(shù)中與應(yīng)用程序一起上傳的文件列表。
  • 添加-Dlog4j.configuration=<location of configuration file>spark.driver.extraJavaOptions (對于驅(qū)動程序)或spark.executor.extraJavaOptions(對于執(zhí)行者)。請注意关霸,如果使用文件传黄,file:則應(yīng)明確提供協(xié)議,并且文件需要在所有節(jié)點上本地存在队寇。
  • 更新$SPARK_CONF_DIR/log4j.properties文件膘掰,它會自動與其他配置一起上傳。請注意佳遣,如果指定了多個選項识埋,其他2個選項的優(yōu)先級高于此選項。

請注意零渐,對于第一個選項窒舟,executor和master 將共享相同的log4j配置,這可能會導(dǎo)致在同一節(jié)點上運行時出現(xiàn)問題(例如嘗試寫入同一個日志文件)诵盼。

如果您需要使用正確的位置將日志文件放入YARN中惠豺,以便YARN可以正確顯示并聚合它們,請在您的log4j.properties中配置spark.yarn.app.container.log.dir风宁。例如洁墙,log4j.appender.file_appender.File=${spark.yarn.app.container.log.dir}/spark.log。對于流式應(yīng)用程序戒财,RollingFileAppender將文件位置配置到Y(jié)ARN的日志目錄將避免由大型日志文件引起的磁盤溢出热监,并且可以使用YARN的日志工具訪問日志。

要為master和 executor 使用自定義的metrics.properties饮寞,請更新該$SPARK_CONF_DIR/metrics.properties文件孝扛。它將自動與其他配置一起上傳,因此您無需手動指定它--files骂际。

Spark屬性

屬性名稱 默認(rèn) 含義
spark.yarn.am.memory 512m 用于客戶端模式下的YARN Application Master的內(nèi)存量疗琉,格式與JVM內(nèi)存字符串(例如512m2g)相同歉铝。在集群模式下盈简,改為使用spark.driver.memory。使用小寫字母后綴太示,例如k柠贤,mg类缤,t臼勉,和p,分別代表kibi-餐弱,mebi-宴霸,gibi-囱晴,tebi-和pebibytes。
spark.yarn.am.cores 1 在客戶端模式下用于YARN Application Master的核心數(shù)量瓢谢。在集群模式下畸写,改為使用spark.driver.cores
spark.yarn.am.waitTime 100s cluster模式中氓扛,YARN Application Master等待SparkContext被初始化的時間枯芬。在client模式中,YARN Application Master等待驅(qū)動程序連接的時間采郎。
spark.yarn.submit.file.replication 默認(rèn)為HDFS副本(通常3 應(yīng)用程序上傳到HDFS的HDFS復(fù)制級別千所。這些包括Spark jar,應(yīng)用程序jar以及任何分布式緩存文件/存檔等內(nèi)容蒜埋。
spark.yarn.stagingDir 當(dāng)前用戶在文件系統(tǒng)中的主目錄 提交應(yīng)用程序時使用的暫存目錄淫痰。
spark.yarn.preserve.staging.files false 設(shè)置為true在作業(yè)結(jié)束時保留分段文件(Spark jar,app jar理茎,分布式緩存文件)黑界,而不是刪除它們。
spark.yarn.scheduler.heartbeat.interval-ms 3000 Spark master 到Y(jié)ARN ResourceManager的心跳時間間隔(以毫秒為單位)皂林。該值被限制在YARN配置的到期時間間隔的一半值上朗鸠,即 yarn.am.liveness-monitor.expiry-interval-ms的一半。
spark.yarn.scheduler.initial-allocation.interval 200ms 當(dāng)容器分配請求時础倍, Spark master節(jié)點到Y(jié)ARN ResourceManager的心跳時間間隔烛占。它不應(yīng)該大于 spark.yarn.scheduler.heartbeat.interval-ms。如果掛起的容器仍然存在沟启,分配間隔會是連續(xù)的心跳加倍忆家,直到達(dá)到spark.yarn.scheduler.heartbeat.interval-ms
spark.yarn.max.executor.failures numExecutors * 2德迹,最少3 認(rèn)定應(yīng)用程序失敗之前執(zhí)行者失敗的最大次數(shù)芽卿。
spark.yarn.historyServer.address (none) Spark歷史記錄服務(wù)器的地址,例如host.com:18080胳搞。地址不應(yīng)該包含scheme(http://)卸例。由于歷史記錄服務(wù)器是可選服務(wù),因此缺省設(shè)置為未設(shè)置肌毅。當(dāng)Spark應(yīng)用程序完成將應(yīng)用程序從ResourceManager UI鏈接到Spark歷史記錄服務(wù)器UI時涵防,該地址將被提供給YARN ResourceManager梆砸。對于這個屬性徽曲,YARN屬性可以用作變量避归,并且這些屬性在運行時被Spark替換。例如笨奠,如果Spark歷史記錄服務(wù)器與YARN ResourceManager在同一節(jié)點上運行袭蝗,則可將其設(shè)置為${hadoopconf-yarn.resourcemanager.hostname}:18080唤殴。
spark.yarn.dist.archives (none) 逗號分隔的檔案列表被提取到每個執(zhí)行者的工作目錄中。
spark.yarn.dist.files (none) 逗號分隔的文件列表將放置在每個執(zhí)行者的工作目錄中到腥。
spark.yarn.dist.jars (沒有) 逗號分隔的jar列表將被放置在每個執(zhí)行者的工作目錄中眨八。
spark.yarn.dist.forceDownloadSchemes (none) 在添加到Y(jié)ARN分布式緩存之前,文件將被下載到本地磁盤的逗號分隔列表左电。用于YARN服務(wù)不支持Spark支持的方案的情況,如http页响,https和ftp篓足。
spark.executor.instances 2 靜態(tài)分配的執(zhí)行者數(shù)量。當(dāng)啟用spark.dynamicAllocation.enabled時闰蚕,執(zhí)行者數(shù)量將至少這么大栈拖。
spark.yarn.am.memoryOverhead AM 內(nèi)存* 0.10,最小值為384 spark.driver.memoryOverhead客戶端模式下的YARN Application Master 相同没陡。
spark.yarn.queue default 提交應(yīng)用程序的YARN隊列的名稱涩哟。
spark.yarn.jars (none) 包含要分發(fā)到Y(jié)ARN容器的Spark代碼庫的列表。默認(rèn)情況下盼玄,Spark on YARN 將使用本地安裝的Spark jar贴彼,但Spark jar也可以位于HDFS上都可讀的位置。這允許YARN將它緩存在節(jié)點上埃儿,以便每次應(yīng)用程序運行時不需要分發(fā)它器仗。例如,要指向HDFS上的jar童番,請將此配置設(shè)置為hdfs:///some/path精钮。Globs是允許的。
spark.yarn.archive (none) 一個包含需要的Spark Jars的檔案剃斧,用于分發(fā)到Y(jié)ARN緩存轨香。如果設(shè)置,則此配置會替換spark.yarn.jars并在所有應(yīng)用程序的容器中使用該存檔幼东。歸檔文件應(yīng)該在其根目錄中包含jar文件臂容。與之前的選項一樣,存檔也可以托管在HDFS上以加速文件分發(fā)筋粗。
spark.yarn.access.hadoopFileSystems (none) Spark應(yīng)用程序?qū)⒃L問的安全Hadoop文件系統(tǒng)的逗號分隔列表策橘。例如,spark.yarn.access.hadoopFileSystems=hdfs://nn1.com:8032,hdfs://nn2.com:8032, webhdfs://nn3.com:50070娜亿。Spark應(yīng)用程序必須能夠訪問列出的文件系統(tǒng)丽已,并且必須正確配置Kerberos以便能夠訪問它們(在相同的領(lǐng)域或受信任的領(lǐng)域)。Spark為每個文件系統(tǒng)獲取安全令牌买决,以便Spark應(yīng)用程序可以訪問這些遠(yuǎn)程Hadoop文件系統(tǒng)沛婴。spark.yarn.access.namenodes 已棄用吼畏,請使用此代替。
spark.yarn.appMasterEnv.[EnvironmentVariableName] (none) 將指定的環(huán)境變量添加EnvironmentVariableName到在YARN上啟動的應(yīng)用程序主進(jìn)程嘁灯。用戶可以指定其中的多個并設(shè)置多個環(huán)境變量泻蚊。在cluster模式中,它控制Spark驅(qū)動程序的環(huán)境丑婿,并且在client模式下它僅控制執(zhí)行程序啟動程序的環(huán)境性雄。
spark.yarn.containerLauncherMaxThreads 25 YARN Application Master中用于啟動執(zhí)行程序容器的最大線程數(shù)。
spark.yarn.am.extraJavaOptions (none) 一系列額外的JVM選項以客戶端模式傳遞給YARN Application Master羹奉。在集群模式下秒旋,spark.driver.extraJavaOptions改為使用。請注意诀拭,使用此選項設(shè)置最大堆大星ㄉ浮(-Xmx)設(shè)置是非法的。最大堆大小設(shè)置可以使用spark.yarn.am.memory
spark.yarn.am.extraLibraryPath (none) 在客戶端模式下啟動YARN Application Master時耕挨,設(shè)置一個特殊的庫路徑细卧。
spark.yarn.maxAppAttempts yarn.resourcemanager.am.max-attempts 在YARN 提交申請的最大嘗試次數(shù)。它不應(yīng)該大于YARN配置中的全局最大嘗試次數(shù)筒占。
spark.yarn.am.attemptFailuresValidityInterval (沒有) 定義AM故障跟蹤的有效時間間隔贪庙。如果AM至少在定義的時間間隔內(nèi)運行,則AM故障計數(shù)將被重置赋铝。如果未配置插勤,此功能未啟用。
spark.yarn.executor.failuresValidityInterval (沒有) 定義執(zhí)行器故障跟蹤的有效時間間隔革骨。比有效期間更早的執(zhí)行程序故障將被忽略农尖。
spark.yarn.submit.waitAppCompletion true 在YARN群集模式下,控制客戶端是否等待退出良哲,直到應(yīng)用程序完成盛卡。如果設(shè)置為true,則客戶端進(jìn)程將保持活動狀態(tài)筑凫,報告應(yīng)用程序的狀態(tài)滑沧。否則,客戶端進(jìn)程將在提交后退出巍实。
spark.yarn.am.nodeLabelExpression (沒有) 一個YARN節(jié)點標(biāo)簽表達(dá)式將限制節(jié)點集合AM的安排滓技。只有大于或等于2.6的YARN版本才支持節(jié)點標(biāo)簽表達(dá)式,所以在針對早期版本運行時棚潦,該屬性將被忽略令漂。
spark.yarn.executor.nodeLabelExpression (沒有) 一個YARN節(jié)點標(biāo)簽表達(dá)式將限制節(jié)點執(zhí)行者集合的安排。只有大于或等于2.6的YARN版本才支持節(jié)點標(biāo)簽表達(dá)式,所以在針對早期版本運行時叠必,該屬性將被忽略荚孵。
spark.yarn.tags (沒有) 逗號分隔的字符串列表將作為YARN應(yīng)用程序標(biāo)簽出現(xiàn)在YARN ApplicationReports中傳遞,可用于在查詢YARN應(yīng)用程序時進(jìn)行過濾纬朝。
spark.yarn.keytab (沒有) 包含上面指定的主體的密鑰表文件的完整路徑收叶。此密鑰表將通過安全分布式緩存復(fù)制到運行YARN應(yīng)用程序主控的節(jié)點,以定期更新登錄憑單和代理令牌共苛。(也與“當(dāng)?shù)亍贝髱熀献鳎?/td>
spark.yarn.principal (沒有) 在安全的HDFS上運行時使用Principal來登錄KDC判没。(也與“當(dāng)?shù)亍贝髱熀献鳎?/td>
spark.yarn.kerberos.relogin.period 1m 多久檢查一次kerberos TGT是否應(yīng)該更新。這應(yīng)該設(shè)置為比TGT更新周期短的值(或者如果未啟用TGT續(xù)訂隅茎,則TGT壽命周期)哆致。大多數(shù)部署的默認(rèn)值應(yīng)該足夠了。
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.

重要筆記

  • 核心請求在調(diào)度決策中是否得到遵守取決于哪個調(diào)度程序正在使用以及它如何配置患膛。
  • cluster模式下,Spark執(zhí)行程序和Spark驅(qū)動程序使用的本地目錄將是為YARN配置的本地目錄(Hadoop YARN配置yarn.nodemanager.local-dirs)耻蛇。如果用戶指定spark.local.dir踪蹬,它將被忽略。在client模式中臣咖,Spark執(zhí)行程序?qū)⑹褂脼閅ARN配置的本地目錄跃捣,而Spark驅(qū)動程序?qū)⑹褂闷渲卸x的目錄spark.local.dir。這是因為Spark驅(qū)動程序不能在client模式下的YARN集群上運行夺蛇,只有Spark執(zhí)行程序會這樣做疚漆。
  • --files--archives選項支持類似于Hadoop的 # 指定文件名。例如刁赦,您可以指定:--files localtest.txt#appSees.txt 并且這會將您本地命名的文件localtest.txt上載到HDFS娶聘,但是這將通過名稱鏈接到appSees.txt,并且您的應(yīng)用程序應(yīng)該使用該名稱appSees.txt來在YARN上運行時引用它甚脉。
  • 如果您使用本地文件并在cluster模式下運行丸升,--jars選項允許該SparkContext.addJar功能起作用。如果您使用HDFS牺氨,HTTP狡耻,HTTPS或FTP文件,則不需要使用它猴凹。

在安全集群中運行

正如安全性所述夷狰,Kerberos用于安全的Hadoop集群中,以對與服務(wù)和客戶端關(guān)聯(lián)的主體進(jìn)行身份驗證郊霎。這允許客戶提出這些認(rèn)證服務(wù)的請求; 為授權(quán)委托人授予權(quán)利的服務(wù)沼头。

Hadoop服務(wù)發(fā)布hadoop令牌來授予對服務(wù)和數(shù)據(jù)的訪問權(quán)限。客戶必須首先獲取他們將訪問的服務(wù)的標(biāo)記瘫证,并將它們與其在YARN群集中啟動的應(yīng)用程序一起傳遞揉阎。

為了使Spark應(yīng)用程序能夠與任何Hadoop文件系統(tǒng)(例如hdfs,webhdfs等)背捌,HBase和Hive進(jìn)行交互毙籽,它必須使用啟動應(yīng)用程序的用戶的Kerberos憑據(jù)來獲取相關(guān)的令牌 - 即身份標(biāo)識的主體將成為啟動的Spark應(yīng)用程序的功能。

這通常在啟動時完成:在安全集群中毡庆,Spark將自動獲取群集的默認(rèn)Hadoop文件系統(tǒng)的標(biāo)記坑赡,并可能為HBase和Hive獲取標(biāo)記。

如果HBase位于類路徑中么抗,HBase配置聲明應(yīng)用程序是安全的(即hbase-site.xml設(shè)置hbase.security.authenticationkerberos)并且spark.security.credentials.hbase.enabled未設(shè)置為HBase令牌毅否,則會獲取HBase令牌false

同樣蝇刀,如果Hive位于類路徑中螟加,則會獲得Hive標(biāo)記,其配置包含元數(shù)據(jù)存儲的URI "hive.metastore.uris吞琐,并且spark.security.credentials.hive.enabled未設(shè)置為false捆探。

如果應(yīng)用程序需要與其他安全Hadoop文件系統(tǒng)交互,那么在啟動時必須明確請求訪問這些群集所需的令牌站粟。這是通過將它們列在spark.yarn.access.hadoopFileSystems屬性中完成的黍图。

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

Spark通過Java服務(wù)機制支持與其他安全感知服務(wù)的集成(請參閱參考資料 java.util.ServiceLoader)。為此奴烙,org.apache.spark.deploy.yarn.security.ServiceCredentialProvider Spark的實現(xiàn)應(yīng)該可以通過將其名稱列在jar META-INF/services目錄中的相應(yīng)文件中來使用 助被。這些插件可以通過設(shè)置來禁用 spark.security.credentials.{service}.enabledfalse,這里{service}是證書提供商的名稱切诀。

配置外部 Shuffle 服務(wù)

NodeManager在YARN群集中的每個群集上啟動Spark Shuffle服務(wù)揩环,請按照以下說明操作:

  1. 使用YARN配置文件構(gòu)建Spark 。如果您使用的是預(yù)先打包的發(fā)行版幅虑,請?zhí)^此步驟检盼。
  2. 找到spark-<version>-yarn-shuffle.jar$SPARK_HOME/common/network-yarn/target/scala-<version>如果你正在自己構(gòu)建Spark翘单,并且在yarn使用發(fā)行版的情況下吨枉, 這應(yīng)該在下面 。
  3. 將此jar添加到NodeManager群集中所有s 的類路徑中哄芜。
  4. yarn-site.xml每個節(jié)點上貌亭,添加spark_shuffleyarn.nodemanager.aux-services,然后設(shè)置yarn.nodemanager.aux-services.spark_shuffle.classorg.apache.spark.network.yarn.YarnShuffleService认臊。
  5. NodeManager's通過設(shè)置YARN_HEAPSIZE(缺省etc/hadoop/yarn-env.sh 為1000)來增加堆大小圃庭,以避免在混洗期間垃圾收集問題。
  6. 重新啟動NodeManager群集中的所有設(shè)備。

在YARN上運行shuffle服務(wù)時剧腻,以下額外配置選項可用:

| 屬性名稱 | 默認(rèn) | 含義 |
| spark.yarn.shuffle.stopOnFailure | false | Spark Shuffle服務(wù)初始化失敗時是否停止NodeManager拘央。這可以防止在Spark Shuffle服務(wù)未運行的NodeManagers上運行容器導(dǎo)致應(yīng)用程序失敗。 |

使用Apache Oozie啟動您的應(yīng)用程序

Apache Oozie可以將Spark應(yīng)用程序作為工作流程的一部分啟動书在。在安全集群中灰伟,啟動的應(yīng)用程序?qū)⑿枰嚓P(guān)的令牌來訪問集群的服務(wù)。如果Spark使用密鑰表啟動儒旬,則這是自動的栏账。但是,如果要在沒有密鑰表的情況下啟動Spark栈源,則必須將設(shè)置安全性的責(zé)任移交給Oozie挡爵。

可以在Oozie網(wǎng)站 的特定版本文檔的“身份驗證”部分找到有關(guān)為安全集群配置Oozie和獲取作業(yè)憑證的詳細(xì)信息。

對于Spark應(yīng)用程序甚垦,必須為Oozie設(shè)置Oozie工作流程以請求應(yīng)用程序需要的所有令牌茶鹃,其中包括:

  • YARN資源管理器。
  • 本地Hadoop文件系統(tǒng)艰亮。
  • 用作I / O的源或目標(biāo)的任何遠(yuǎn)程Hadoop文件系統(tǒng)前计。
  • 配置單元 - 如果使用。
  • 使用HBase -if垃杖。
  • YARN時間軸服務(wù)器,如果應(yīng)用程序與此交互丈屹。

為了避免Spark試圖獲取Hive调俘,HBase和遠(yuǎn)程HDFS令牌,然后失敗旺垒,必須將Spark配置設(shè)置為禁用服務(wù)的令牌收集彩库。

Spark配置必須包含以下行:

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

配置選項spark.yarn.access.hadoopFileSystems必須未設(shè)置。

解決Kerberos問題

調(diào)試Hadoop / Kerberos問題可能很“困難”先蒋。一種有用的技術(shù)是通過設(shè)置HADOOP_JAAS_DEBUG 環(huán)境變量來在Hadoop中啟用額外的Kerberos操作日志記錄骇钦。

export HADOOP_JAAS_DEBUG=true

可以將JDK類配置為通過系統(tǒng)屬性啟用額外的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設(shè)置為DEBUG眯搭,則日志將包含獲取的所有令牌的列表及其到期的詳細(xì)信息

使用Spark歷史記錄服務(wù)器來替換Spark Web UI

當(dāng)應(yīng)用程序UI被禁用時,可以使用Spark History Server應(yīng)用程序頁面作為運行應(yīng)用程序的跟蹤URL业岁。這在安全集群上可能是需要的鳞仙,或者減少Spark驅(qū)動程序的內(nèi)存使用量。要通過Spark歷史記錄服務(wù)器設(shè)置跟蹤笔时,請執(zhí)行以下操作:

  • 在應(yīng)用程序方面棍好,設(shè)置spark.yarn.historyServer.allowTracking=trueSpark的配置。如果應(yīng)用程序的UI被禁用,這將告訴Spark使用歷史記錄服務(wù)器的URL作為跟蹤URL借笙。
  • 在Spark歷史記錄服務(wù)器上扒怖,添加org.apache.spark.deploy.yarn.YarnProxyRedirectFilterspark.ui.filters配置中的過濾器列表。

請注意业稼,歷史記錄服務(wù)器信息可能不是應(yīng)用程序狀態(tài)的最新信息盗痒。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市盼忌,隨后出現(xiàn)的幾起案子积糯,更是在濱河造成了極大的恐慌,老刑警劉巖谦纱,帶你破解...
    沈念sama閱讀 216,496評論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件看成,死亡現(xiàn)場離奇詭異,居然都是意外死亡跨嘉,警方通過查閱死者的電腦和手機川慌,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,407評論 3 392
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來祠乃,“玉大人梦重,你說我怎么就攤上這事×链桑” “怎么了琴拧?”我有些...
    開封第一講書人閱讀 162,632評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長嘱支。 經(jīng)常有香客問我蚓胸,道長,這世上最難降的妖魔是什么除师? 我笑而不...
    開封第一講書人閱讀 58,180評論 1 292
  • 正文 為了忘掉前任沛膳,我火速辦了婚禮,結(jié)果婚禮上汛聚,老公的妹妹穿的比我還像新娘锹安。我一直安慰自己,他們只是感情好倚舀,可當(dāng)我...
    茶點故事閱讀 67,198評論 6 388
  • 文/花漫 我一把揭開白布叹哭。 她就那樣靜靜地躺著,像睡著了一般痕貌。 火紅的嫁衣襯著肌膚如雪话速。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,165評論 1 299
  • 那天芯侥,我揣著相機與錄音泊交,去河邊找鬼乳讥。 笑死,一個胖子當(dāng)著我的面吹牛廓俭,可吹牛的內(nèi)容都是我干的云石。 我是一名探鬼主播,決...
    沈念sama閱讀 40,052評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼研乒,長吁一口氣:“原來是場噩夢啊……” “哼汹忠!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起雹熬,我...
    開封第一講書人閱讀 38,910評論 0 274
  • 序言:老撾萬榮一對情侶失蹤宽菜,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后竿报,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體铅乡,經(jīng)...
    沈念sama閱讀 45,324評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,542評論 2 332
  • 正文 我和宋清朗相戀三年烈菌,在試婚紗的時候發(fā)現(xiàn)自己被綠了阵幸。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,711評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡芽世,死狀恐怖挚赊,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情济瓢,我是刑警寧澤荠割,帶...
    沈念sama閱讀 35,424評論 5 343
  • 正文 年R本政府宣布,位于F島的核電站旺矾,受9級特大地震影響蔑鹦,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜宠漩,卻給世界環(huán)境...
    茶點故事閱讀 41,017評論 3 326
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望懊直。 院中可真熱鬧扒吁,春花似錦、人聲如沸室囊。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,668評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽融撞。三九已至盼铁,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間尝偎,已是汗流浹背饶火。 一陣腳步聲響...
    開封第一講書人閱讀 32,823評論 1 269
  • 我被黑心中介騙來泰國打工鹏控, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人肤寝。 一個月前我還...
    沈念sama閱讀 47,722評論 2 368
  • 正文 我出身青樓当辐,卻偏偏與公主長得像,于是被迫代替她去往敵國和親鲤看。 傳聞我的和親對象是個殘疾皇子缘揪,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,611評論 2 353

推薦閱讀更多精彩內(nèi)容