目录
0 参考列表
CSDN:Azkaban知识点入门https://blog.csdn.net/weixin_45682261/article/details/125118559
CSDN:dataX同步mysql至hivehttps://blog.csdn.net/AyubLIbra/article/details/115838882剥削园:Azkaban-2.5及Plugins的安装配置
https://www.cnblogs.com/wuyida/p/6300230.html
CSDN:Azkaban的使用(完全版)https://blog.csdn.net/I_Demo/article/details/89555412
1 概念
1.1 概念
(1) Azkaban:一个批量工作流任务调度器,用于在一个工作流内以一个特定的顺序运行一组任务.Azkaban使用job配置文件建立任务之间的依赖关系,并通过web用户界面维护工作流.
(2) Project:包含一个或多个工作流flow.
(3) Flow:工作流,由一个或多个job组成.工作流是指一类能够完全自动执行的经营过程,根据一系列过程规则,将文档、信息或任务在不同的执行者之间进行传递与执行.工作流就是封装好的一种框架,我们利用这种框架来解决需要多个人或者多个部门协同完成的某项工作.
(4) Job:一个工作流中的具体节点,可以是各种类型的执行任务.
1.2 特点
①提供功能清晰,简单易用的Web UI界面;
②提供job配置文件快速建立任务和任务之间的依赖关系;
③支持多种组件,原生支持command、Java、Hive、Pig、Hadoop;
④代码结构清晰,易于二次开发.
2 系统架构
2.1 组件
①数据库:用于存储项目、日志或者执行计划之类的元数据;
②Web Server:提供页面维护工作流;
③Executor Server:负责具体的工作流的提交、执行.
2.2 运行模式
①独立服务器模式:使用自带的数据库,Web Server与Executor Server在同一进程中运行;
②双服务器模式:使用MySQL数据库,Web Server与Executor Server在不同进程中运行;
③分布式多执行器模式:使用MySQL数据库,一个Web Servce,多个Executor Server分开部署.
3 安装使用
3.1 安装
CSDN:集群搭建系列(十三) azkaban 3.73.1https://blog.csdn.net/cs261244787/article/details/111625889
3.2 访问
(1) 进程
Executor Server:AzkabanExecutorServer
Web Server:AzkabanWebServer
(2) 日志
Executor Server:azkaban-exec-server/logs/azkaban-execserver.log
Web Server:azkaban-web-server/logs/azkaban-webserver.log
(3) 页面:ip:8081
(4) 启动
①启动 Executor Server:bin/start-exec.sh
②激活 executors:
将 executors 表 active 字段的值改为1;
或者执行 curl http://${executorHost}:${executorPort}/executor?action=activate
③启动 Web Server:bin/start-web.sh
(5) 停止
①停止 Web Server:bin/shutdown-web.sh
②停止 Executor Server:bin/shutdown-exec.sh
4 项目开发
4.1 开发job作业
4.1.1 flow 1.0
开发job文件,xx.job
# dwd_trd_order_detail
# 作业的类型,command(shell脚本)、java等
type=command
# 需要运行的脚本,如果需要运行多个,则配置多个commamd.x
command=echo "dwd_trd_order_detail job start"
command.1=echo "dwd_trd_order_detail job end"
# 依赖,可选参数,多个依赖用','隔开
dependencies=ods_trd_order,dim_stu_student
4.1.2 flow 2.0
将所有 job 和 properties 文件合并到单个流定义文件中,同时支持在流中再定义流.
(1) 开发版本文件,xxx.project
azkaban-flow-version: 2.0
(2) 开发flow文件,xx.flow,flow文件是Yml格式的
①多任务调度流
config:
user.to.proxy: azktest
param.hadoopOutData: /tmp/wordcounthadoopout
param.inData: /tmp/wordcountpigin
param.outData: /tmp/wordcountpigout
# This section defines the list of jobs
# A node can be a job or a flow
# In this example, all nodes are jobs
nodes:
# Job definition
# The job definition is like a YAMLified version of properties file
# with one major difference. All custom properties are now clubbed together
# in a config section in the definition.
# The first line describes the name of the job
- name: AZTest
type: noop
# The dependsOn section contains the list of parent nodes the current
# node depends on
dependsOn:
- hadoopWC1
- NoOpTest1
- hive2
- java1
- jobCommand2
- name: pigWordCount1
type: pig
# The config section contains custom arguments or parameters which are
# required by the job
config:
pig.script: src/main/pig/wordCountText.pig
- name: hadoopWC1
type: hadoopJava
dependsOn:
- pigWordCount1
config:
classpath: ./*
force.output.overwrite: true
input.path: ${param.inData}
job.class: com.linkedin.wordcount.WordCount
main.args: ${param.inData} ${param.hadoopOutData}
output.path: ${param.hadoopOutData}
- name: hive1
type: hive
config:
hive.script: src/main/hive/showdb.q
- name: NoOpTest1
type: noop
- name: hive2
type: hive
dependsOn:
- hive1
config:
hive.script: src/main/hive/showTables.sql
- name: java1
type: javaprocess
config:
Xms: 96M
java.class: com.linkedin.foo.HelloJavaProcessJob
- name: jobCommand1
type: command
config:
command: echo "hello world from job_command_1"
- name: jobCommand2
type: command
dependsOn:
- jobCommand1
config:
command: echo "hello world from job_command_2"
②内嵌流调度
nodes:
- name: jobC
type: flow
config:
prop: value
nodes:
- name: jobB
type: command
config:
command: echo "This is job B"
dependsOn:
- jobA
- name: jobA
type: command
config:
command: echo "This is job A"
(3) Yml格式
语法格式
数据格式: key: value
# 表示注释
--- 表示分段,用于多个yml文档放入一个文件
#规范
以空格缩进代表层级关系,相同层级的元素左对齐
不允许使用tab
大小写敏感
冒号和'-'后要有空格
4.2 打包和上传任务
(1) 将 项目中所有的 shell 脚本转码:find ./ -name "*.sh" | xargs dos2unix
(2) 打包:作业配置完成后打成Zip包.
(3) 上传:在Azkaban页面创建项目,上传Zip包.
4.3 运行和运维
将 项目中所有的 sh 脚本进行转码
(1) 运行:点击Execute Flow运行作业.
(2) 运维:查看当前正在运行的作业,查看历史作业信息.
5 参数
5.1 作业参数
在任务配置文件中,除了type、command这些参数外,还可以配置以下参数.
参数 | 说明 |
retries | 失败的job的自动重试的次数 |
retry.backoff | 重试的间隔(毫秒) |
working.dir | 指定命令被调用的目录.默认的working目录是executions/${execution_ID}目录 |
env.property | 指定在命令执行前需设置的环境变量.Property定义环境变量的名称,因此 env.VAR_NAME=VALUE就创建了一个$VAR_NAME环境变量并且指定了它的VALUE |
failure.emails | job失败时发送的邮箱,用逗号隔开 |
success.emails | job成功时发送的邮箱,用逗号隔开 |
notify.emails | job成功或失败都发送的邮箱,用逗号隔开 |
5.2 调度参数
在任务配置文件中,可以通过${参数名}的方式引用以下参数.
参数 | 说明 |
azkaban.job.attempt | job重试次数,从0开始增加 |
azkaban.job.id | 运行的job name |
azkaban.flow.flowid | 运行的job的flow name |
azkaban.flow.execid | flow的执行id |
azkaban.flow.projectid | 工程id |
azkaban.flow.projectversion | project上传的版本 |
azkaban.flow.uuid | flow uuid |
azkaban.flow.start.timestamp | flow start的时间戳 |
azkaban.flow.start.year | flow start的年份 |
azkaban.flow.start.month | flow start 的月份 |
azkaban.flow.start.day | flow start 的天 |
azkaban.flow.start.hour | flow start的小时 |
azkaban.flow.start.minute | start 分钟 |
azkaban.flow.start.second | start 秒 |
azkaban.flow.start.millseconds | start的毫秒 |
azkaban.flow.start.timezone | start 的时区 |
6 优化
①合理调整周期任务运行时刻,在任务低峰期运行,避免集群资源紧张;
②合理调整任务运行频率;
③设置任务运行的优先级,价值高的优先执行.
④合理调整上下游任务的逻辑,降低本任务处理的复杂度.
7 问题
7.1 任务运行失败
7.2 已到定时时间,但任务未运行
(1) 原因:上游任务未运行成功
解决方案:解决上游任务问题.
(2) 原因:上游任务运行时间长,当前任务的定时时间为12点,上游任务的定时时间早于12点但在12点后才运行成功
解决方案:无需解决或合理调整上下游任务的定时时间.
(3) 原因:上下游任务的定时时间设置不合理,如当前任务的定时时间为12点,上游任务定时时间却是15点
解决方案:合理调整上下游任务的定时时间.
(4) 原因:资源不足,任务正在等待资源
解决方案:
①增加资源;
②合理调整任务的定时时间.
7.3 任务运行成功,但运行时间变长
(1) 原因:数据正常变多,运行时间变长
解决方案:无需解决
(2) 原因:来源表逻辑异常或数据异常,导致数据变多.如表的关联关系为一对一,但有脏数据是一对多,引起数据翻倍
解决方案:排查异常逻辑和异常数据并解决.
(3) 原因:资源不足,任务等待资源花费时间
解决方案:
①增加资源;
②合理调整任务的定时时间.
7.4 软件问题
(1) 上传文件报错:ProjectManagerException: Error Chunking during uploading files to db...
Azkaban上传文件报错https://www.jianshu.com/p/3933fdf16160
(2) 上传文件报错:mapping values are not allowed here
multi.flow是Yaml格式,要求每个冒号后面都必须带有空格
(3) 任务一直处于preparing状态
原因:过滤器会检查Executor Server空闲内存,不足6G时不会将任务交由该主机执行.
解决方案:修改azkaban-web-server/conf/azkaban.properties: azkaban.executorselector.filters = StaticRemainingFlowSize,CpuStatus.