Spark history Server產(chǎn)生背景
以standalone運(yùn)行模式為例,在運(yùn)行Spark Application的時候,Spark會提供一個WEBUI列出應(yīng)用程序的運(yùn)行時信息;但該WEBUI隨著Application的完成(成功/失 敗)而關(guān)閉,也就是說,Spark Application運(yùn)行完(成功/失敗)后,將無法查看Application的歷史記錄;
Spark history Server就是為了應(yīng)對這種情況而產(chǎn)生的,通過配置可以在Application執(zhí)行的過程中記錄下了日志事件信息,那么在Application執(zhí)行 結(jié)束后,WEBUI就能重新渲染生成UI界面展現(xiàn)出該Application在執(zhí)行過程中的運(yùn)行時信息;
Spark運(yùn)行在yarn或者mesos之上,通過spark的history server仍然可以重構(gòu)出一個已經(jīng)完成的Application的運(yùn)行時參數(shù)信息(假如Application運(yùn)行的事件日志信息已經(jīng)記錄下來);
配置&使用Spark History Server
以默認(rèn)配置的方式啟動spark history server:
cd $SPARK_HOME/sbin start-history-server.sh
報錯:
starting org.apache.spark.deploy.history.HistoryServer, logging to /home/spark/software/source/compile/deploy_spark/sbin/../logs/spark-spark-org.apache.spark.deploy.history.HistoryServer-1-hadoop000.out failed to launch org.apache.spark.deploy.history.HistoryServer: at org.apache.spark.deploy.history.FsHistoryProvider.<init>(FsHistoryProvider.scala:44) ... 6 more
需要在啟動時指定目錄:
start-history-server.sh hdfs://hadoop000:8020/directory
hdfs://hadoop000:8020/directory可以配置在配置文件中,那么在啟動history-server時就不需要指定,后續(xù)介紹怎么配置;
注:該目錄需要事先在hdfs上創(chuàng)建好,否則history-server啟動報錯。
啟動完成之后可以通過WEBUI訪問,默認(rèn)端口是18080:http://hadoop000:18080
默認(rèn)界面列表信息是空的,下面截圖是我跑了幾次spark-sql測試后出現(xiàn)的。
history server相關(guān)的配置參數(shù)描述
1) spark.history.updateInterval
默認(rèn)值:10
以秒為單位,更新日志相關(guān)信息的時間間隔
2)spark.history.retainedApplications
默認(rèn)值:50
在內(nèi)存中保存Application歷史記錄的個數(shù),如果超過這個值,舊的應(yīng)用程序信息將被刪除,當(dāng)再次訪問已被刪除的應(yīng)用信息時需要重新構(gòu)建頁面。
3)spark.history.ui.port
默認(rèn)值:18080
HistoryServer的web端口
4)spark.history.kerberos.enabled
默認(rèn)值:false
是否使用kerberos方式登錄訪問HistoryServer,對于持久層位于安全集群的HDFS上是有用的,如果設(shè)置為true,就要配置下面的兩個屬性
5)spark.history.kerberos.principal
默認(rèn)值:用于HistoryServer的kerberos主體名稱
6)spark.history.kerberos.keytab
用于HistoryServer的kerberos keytab文件位置
7)spark.history.ui.acls.enable
默認(rèn)值:false
授權(quán)用戶查看應(yīng)用程序信息的時候是否檢查acl。如果啟用,只有應(yīng)用程序所有者和spark.ui.view.acls指定的用戶可以查看應(yīng)用程序信息;否則,不做任何檢查
8)spark.eventLog.enabled
默認(rèn)值:false
是否記錄Spark事件,用于應(yīng)用程序在完成后重構(gòu)webUI
9)spark.eventLog.dir
默認(rèn)值:file:///tmp/spark-events
保存日志相關(guān)信息的路徑,可以是hdfs://開頭的HDFS路徑,也可以是file://開頭的本地路徑,都需要提前創(chuàng)建
10)spark.eventLog.compress
默認(rèn)值:false
是否壓縮記錄Spark事件,前提spark.eventLog.enabled為true,默認(rèn)使用的是snappy
以spark.history開頭的需要配置在spark-env.sh中的SPARK_HISTORY_OPTS,以spark.eventLog開頭的配置在spark-defaults.conf
我在測試過程中的配置如下:
spark-defaults.conf
spark.eventLog.enabled true spark.eventLog.dir hdfs://hadoop000:8020/directory spark.eventLog.compress true
spark-env.sh
export SPARK_HISTORY_OPTS="-Dspark.history.ui.port=7777 -Dspark.history.retainedApplications=3 -Dspark.history.fs.logDirectory=hdfs://had oop000:8020/directory"
參數(shù)描述:
spark.history.ui.port=7777 調(diào)整WEBUI訪問的端口號為7777
spark.history.fs.logDirectory=hdfs://hadoop000:8020/directory 配置了該屬性后,在start-history-server.sh時就無需再顯示的指定路徑
spark.history.retainedApplications=3 指定保存Application歷史記錄的個數(shù),如果超過這個值,舊的應(yīng)用程序信息將被刪除
調(diào)整參數(shù)后啟動start-history-server.sh
start-history-server.sh
訪問WEBUI: http://hadoop000:7777
在使用spark history server的過程中產(chǎn)生的幾個疑問:
疑問1:spark.history.fs.logDirectory和spark.eventLog.dir指定目錄有啥區(qū)別?
經(jīng)測試后發(fā)現(xiàn):
spark.eventLog.dir:Application在運(yùn)行過程中所有的信息均記錄在該屬性指定的路徑下;
spark.history.fs.logDirectory:Spark History Server頁面只展示該指定路徑下的信息;
比如:spark.eventLog.dir剛開始時指定的是hdfs://hadoop000:8020/directory,而后修改成hdfs://hadoop000:8020/directory2
那么spark.history.fs.logDirectory如果指定的是hdfs://hadoop000:8020/directory,就只能顯示出該目錄下的所有Application運(yùn)行的日志信息;反之亦然。
疑問2:spark.history.retainedApplications=3 貌似沒生效??????
The History Server will list all applications. It will just retain a max number of them in memory. That option does not control how many applications are show, it controls how much memory the HS will need.
注意:該參數(shù)并不是也頁面中顯示的application的記錄數(shù),而是存放在內(nèi)存中的個數(shù),內(nèi)存中的信息在訪問頁面時直接讀取渲染既可;
比如說該參數(shù)配置了10個,那么內(nèi)存中就最多只能存放10個applicaiton的日志信息,當(dāng)?shù)?1個加入時,第一個就會被踢除,當(dāng)再次訪問第1個application的頁面信息時就需要重新讀取指定路徑上的日志信息來渲染展示頁面。
詳見官方文檔:http://spark.apache.org/docs/latest/monitoring.html