(十九)保存Spark运行日志的配置

生产上作业运行日志务必要保存下来,以防出现错误无法排查
官网关于日志监控的说明:
You can access this interface by simply opening http://<driver-node>:4040 in a web browser. If multiple SparkContexts are running on the same host, they will bind to successive ports beginning with 4040 (4041, 4042, etc).
Note that this information is only available for the duration of the application by default. To view the web UI after the fact, set spark.eventLog.enabled to true before starting the application. This configures Spark to log Spark events that encode the information displayed in the UI to persisted storage.
怎样设置呢?

[hadoop@hadoop000 ~]$ cd $SPARK_HOME/conf
[hadoop@hadoop000 conf]$ vi spark-defaults.conf
spark.eventLog.enabled           true
spark.eventLog.dir               hdfs://hadoop000:9000/directory
[hadoop@hadoop000 conf]$ vi spark-env.sh
SPARK_HISTORY_OPTS="-Dspark.history.fs.logDirectory=hdfs://hadoop000:9000/directory"
[hadoop@hadoop000 ~]$ cd $SPARK_HOME/sbin
[hadoop@hadoop000 sbin]$ ./start-history-server.sh
starting org.apache.spark.deploy.history.HistoryServer, logging to /home/hadoop/app/spark-2.3.1-bin-2.6.0-cdh5.7.0/logs/spark-hadoop-org.apache.spark.deploy.history.HistoryServer-1-hadoop000.out

spark.history.ui.port 默认为18080,如果要修改,也在SPARK_HISTORY_OPTS里设置,如SPARK_HISTORY_OPTS="-Dspark.history.ui.port=7777"

运行一个作业验证一下

./spark-submit \
--class org.apache.spark.examples.SparkPi \
--master local[2] \
 /home/hadoop/app/spark-2.3.1-bin-2.6.0-cdh5.7.0/examples/jars/spark-examples_2.11-2.3.1.jar \
3
./spark-submit \
--class org.apache.spark.examples.SparkPi \
--master yarn \
 /home/hadoop/app/spark-2.3.1-bin-2.6.0-cdh5.7.0/examples/jars/spark-examples_2.11-2.3.1.jar \
3

前面设置日志保存在hdfs上,查看一下

[hadoop@hadoop000 sbin]$ hadoop fs -ls /directory
Found 2 items
-rwxrwx---   1 hadoop supergroup      39964 2018-09-19 23:56 /directory/application_1537370027569_0002
-rwxrwx---   1 hadoop supergroup      38568 2018-09-19 23:54 /directory/local-1537372441615

为了防止日志在HDFS累积过多,可以设置定期清理

日志还可以设置压缩,官网没有提及,可查看源码

还有其他监控方法,详见官网

最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • pyspark.sql模块 模块上下文 Spark SQL和DataFrames的重要类: pyspark.sql...
    mpro阅读 10,054评论 0赞 13
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 137,341评论 19赞 139
  • 恰似一抹娇作春阳,企图揉碎三丈冰坚,打开了紧掩的心扉是我犯下的一个错误,很抱歉让你看到了脱去伪装的我是那般迷惘,...
    夏屾阅读 389评论 6赞 2
  • 我把字写在金黄的海滩上,然后伴随着海水的来袭,他们被冲走了。 我傻傻地看着空白的滩面,终于知道为什么许多人在经...
    深水伊雪阅读 247评论 0赞 1

友情链接更多精彩内容