- 任务调度
- 大数据
- 后端
- 前端
【免费下载链接】dolphinscheduler
Apache DolphinScheduler is the modern data orchestration platform. Agile to create high performance workflow with low-code
Apache DolphinScheduler 支持将任务日志异步上传到远端对象存储(OSS、S3、GCS、ABS),并在本地日志缺失时自动从远端下载。本文以docs/docs/zh/guide/remote-logging.md为骨架,结合仓库源码与配置文件模板,系统讲解远程日志存储的开启方式、四个核心参数、四种对象存储的完整配置项,以及背后的异步上传与按需下载实现原理,帮助你在集群、伪集群或单机部署下快速落地任务日志的集中化持久存储。
远程日志存储的核心工作流程
默认情况下,DolphinScheduler 的任务日志保存在执行节点(Worker)的本地文件系统中。开启远程日志存储后,日志的生命周期变为两个阶段:
- 任务结束后异步上传:当某个任务执行完成,Worker 会触发
RemoteLogUtils.sendRemoteLog(logPath),将对应的任务日志文件异步发送到remote.logging.target指定的远端存储; - 查看/下载时按需拉取:用户在 Web 界面查看或下载任务日志时,如果本地文件系统没有该日志文件,DolphinScheduler 会调用
RemoteLogUtils.getRemoteLog(logPath)从远端存储下载对应日志到本地(下载前会自动创建本地父目录,见 RemoteLogUtils.java)。
从源码结构看,远端存储的读写能力被抽象为统一的RemoteLogHandler接口,并由工厂类RemoteLogHandlerFactory根据remote.logging.target动态选择实现,dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/log/remote 目录下分别提供了:
OssRemoteLogHandler.java(阿里云 OSS)S3RemoteLogHandler.java(Amazon S3)GcsRemoteLogHandler.java(Google Cloud Storage)AbsRemoteLogHandler.java(Azure Blob Storage)
开启远程日志存储
根据部署模式,需要配置不同的common.properties文件:
- 集群 / 伪集群模式:配置
api-server/conf/common.properties、master-server/conf/common.properties、worker-server/conf/common.properties三个文件(Worker 负责上传日志,API Server 负责读取日志,Master 与日志读写无关但部署包中同样下发该文件,建议保持一致); - 单机(standalone)模式:只需配置
standalone-server/conf/common.properties。
当前源码仓库中的配置模板位于 dolphinscheduler-common/src/main/resources/common.properties,所有remote.logging.*键的定义可在 Constants.java 中查到,其中第 650–656 行即四个核心开关参数:
# 是否开启远程日志存储 remote.logging.enable=true # 任务日志写入的远端存储,目前支持OSS, S3, GCS, ABS remote.logging.target=OSS # 任务日志在远端存储上的目录 remote.logging.base.dir=logs # 设置向远端存储异步发送日志的线程池大小 remote.logging.thread.pool.size=10四个参数的说明与取值要点:
| 参数 | 默认值 | 作用 |
|---|---|---|
remote.logging.enable | false | 总开关,设为true后日志才会写入远端存储 |
remote.logging.target | OSS | 远端存储类型,仅支持OSS、S3、GCS、ABS四种取值 |
remote.logging.base.dir | logs | 日志在远端存储上的根目录,上传时日志文件会被映射到该目录下 |
remote.logging.thread.pool.size | 10 | 异步发送日志的线程池大小,需根据任务并发量适当调整 |
注意:
remote.logging.enable默认关闭(模板中为false),开启后请在 common.properties 中按需调整上述参数。
异步线程池的源码实现
remote.logging.thread.pool.size直接决定异步上传线程池的规格。在 RemoteLogHandleThreadPool.java 中,该值同时被用作核心线程数与最大线程数,线程名前缀为remote-logging-:
executor.setCorePoolSize(PropertyUtils.getInt(Constants.REMOTE_LOGGING_THREAD_POOL_SIZE, 10)); executor.setMaxPoolSize(PropertyUtils.getInt(Constants.REMOTE_LOGGING_THREAD_POOL_SIZE, 10)); executor.setThreadNamePrefix("remote-logging-");上传动作由 RemoteLogService.java 通过@Async("remoteLogHandleExecutor")注解异步执行,并在日志中记录目标存储类型,因此不会阻塞任务线程。
上传触发的调用链
任务执行完成后,Worker 侧调用入口位于 WorkerTaskExecutor.java 的RemoteLogUtils.sendRemoteLog(taskExecutionContext.getLogPath())。sendRemoteLog内部先判断开关是否开启,再转交RemoteLogService异步发送;日志在远端存储上的对象路径由RemoteLogUtils.getObjectNameFromLogPath计算,其逻辑是:用remote.logging.base.dir作为远端前缀,拼上本地日志根目录之后的相对路径(见 RemoteLogUtils.java)。
将任务日志写入阿里云对象存储(OSS)
选择remote.logging.target=OSS时,需要在common.properties中补充以下四项配置:
# oss access key id, required if you set remote.logging.target=OSS remote.logging.oss.access.key.id=<access.key.id> # oss access key secret, required if you set remote.logging.target=OSS remote.logging.oss.access.key.secret=<access.key.secret> # oss bucket name, required if you set remote.logging.target=OSS remote.logging.oss.bucket.name=<bucket.name> # oss endpoint, required if you set remote.logging.target=OSS remote.logging.oss.endpoint=<endpoint>remote.logging.oss.access.key.id/remote.logging.oss.access.key.secret:阿里云账号的 AccessKey 对,需具备对目标 Bucket 的读写权限;remote.logging.oss.bucket.name:存放任务日志的 OSS Bucket 名称;remote.logging.oss.endpoint:OSS 服务的访问端点,形如https://oss-cn-hangzhou.aliyuncs.com(参考模板 common.properties 中的资源存储同类型配置注释)。
对应的上传与下载逻辑由OssRemoteLogHandler实现,仓库中可通过dolphinscheduler-common模块的测试资源与配置模板交叉验证字段名。
将任务日志写入 Amazon S3
选择remote.logging.target=S3时,配置如下:
# s3 access key id, required if you set remote.logging.target=S3 remote.logging.s3.access.key.id=<access.key.id> # s3 access key secret, required if you set remote.logging.target=S3 remote.logging.s3.access.key.secret=<access.key.secret> # s3 bucket name, required if you set remote.logging.target=S3 remote.logging.s3.bucket.name=<bucket.name> # s3 endpoint, required if you set remote.logging.target=S3 remote.logging.s3.endpoint=<endpoint> # s3 region, required if you set remote.logging.target=S3 remote.logging.s3.region=<region>与 OSS 相比,S3 多了一个必填的remote.logging.s3.region(Bucket 所在区域)。endpoint字段使该配置同样适用于兼容 S3 协议的其他对象存储(如 MinIO 等自建服务),S3RemoteLogHandler内部基于该 endpoint 构造客户端。
将任务日志写入 Google Cloud Storage(GCS)
选择remote.logging.target=GCS时,配置如下:
# the location of the google cloud credential, required if you set remote.logging.target=GCS remote.logging.google.cloud.storage.credential=/path/to/credential # gcs bucket name, required if you set remote.logging.target=GCS remote.logging.google.cloud.storage.bucket.name=<your-bucket>GCS 使用服务账号凭证文件进行认证:
remote.logging.google.cloud.storage.credential:指向本地的 Google Cloud 服务账号 JSON 凭证文件路径,需要保证运行 DolphinScheduler 的机器对该路径可读;remote.logging.google.cloud.storage.bucket.name:存放日志的 GCS Bucket 名称。
将任务日志写入 Azure Blob Storage(ABS)
选择remote.logging.target=ABS时,配置如下:
# abs account name, required if you set resource.storage.type=ABS remote.logging.abs.account.name=<your-account-name> # abs account key, required if you set resource.storage.type=ABS remote.logging.abs.account.key=<your-account-key> # abs container name, required if you set resource.storage.type=ABS remote.logging.abs.container.name=<your-container-name>remote.logging.abs.account.name:Azure 存储账号名称;remote.logging.abs.account.key:存储账号的访问密钥;remote.logging.abs.container.name:存储容器(Container)名称,日志会写入该容器下。
注意事项
由于 Azure Blob Storage 不支持空目录单独存在,因此资源目录下会出现空文件<no name>。但这并不影响 DolphinScheduler 资源中心上的文件展示,可以放心使用。
结语
远程日志存储让 DolphinScheduler 的任务日志不再局限于各 Worker 节点的本地磁盘,从而支持日志的集中归档、审计与跨节点检索。启用时只需在common.properties中打开remote.logging.enable、指定remote.logging.target,并按对应云厂商补齐认证与 Bucket 配置即可;若需加深理解,可继续阅读 RemoteLogService.java、RemoteLogUtils.java 以及配置模板 common.properties。
- 任务调度
- 大数据
- 后端
- 前端
【免费下载链接】dolphinscheduler
Apache DolphinScheduler is the modern data orchestration platform. Agile to create high performance workflow with low-code
相关推荐
Apache DolphinScheduler 远程日志(Remote Logging)配置与实现原理详解
Apache DolphinScheduler 远程日志(Remote Logging)配置与实现原理详解 本指南围绕 Apache DolphinSchedu
任务调度大数据后端前端Apache DolphinScheduler 远程日志(Remote Logging)完整配置指南:支持 OSS、S3、GCS、ABS
Apache DolphinScheduler 远程日志(Remote Logging)完整配置指南:支持 OSS、S3、GCS、ABS Apache Dolp
任务调度数据编排工作流自动化后端大数据Apache DolphinScheduler 远程日志存储配置指南:OSS / S3 / GCS / ABS 全接入
Apache DolphinScheduler 远程日志存储配置指南:OSS / S3 / GCS / ABS 全接入 Apache DolphinSchedu
任务调度数据编排工作流自动化后端大数据
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考