(1) 修改spark-defaults.conf配置文件
该文件在SPARK_HOME/conf/下,新安装的spark中只有spark-defaults.conf.template这个文件,改名为spark-defaults.conf即可
[root@repo conf]# vim spark-defaults.conf
spark.eventLog.enabled true
spark.eventLog.dir hdfs://repo:9000/spark/historyLog
spark.history.fs.logDirectory hdfs://repo:9000/spark/historyLog
# spark.eventLog.compress true # 可以设置保存历史日志时进行压缩
注意:
- 保存历史数据的目录需要先创建好
- 上面配置的两个目录必须是一样的
- 如果你的hadoop是HA集群,那两个目录的路径要写
hdfs://your-clustername/spark/historyLog
,your-clustername由hdfs-site.xml中的dfs.nameservices
来配置,另外,your-clustername后面不用加端口!我曾经因为写成这样:hdfs://mycluster:9000/user/hadoop/spark/historyLog
而报错:
Exception in thread "main" java.io.IOException: Port 9000 specified in URI hdfs://mycluster:9000/user/hadoop/spark/historyLog but host 'mycluster' is a logical (HA) namenode and does not use port information.
浪费了一天时间!血的教训!
(2) 启动history server
[root@repo conf]# start-history-server.sh
(3) 访问web界面
(4) 测试
提交一个spark任务
spark-submit \
--class org.apache.spark.examples.SparkPi \
--master spark://repo:7077 \
--executor-memory 2G \
--total-executor-cores 1 \
/opt/spark-2.2.0/examples/jars/spark-examples_2.11-2.2.0.jar \
1000
查看web页面
查看hdfs上的日志文件
Spark History Server配置成功!