airflow使用

【Airflow】光速入门指南 Airflow中最为关键的概念就是DAG,中文名称是有向无环图(Directed Acyclic Graph)一个DAG代表着一个较为完整的流程,其中的组成部分是执行不同步骤的Task。如果说DAG是一条珍珠项链,那么TASK就是其中的珍珠。珍珠项链可以有不同的形态、数量和组合方式,DAG和TASK也是同理。#方式一:类的实例化test_task = PythonOperator( #以PythonOperator为例,也可以定义使用其他的Operator。 阅读详情

 

转载:链接:https://www.jianshu.com/p/f3ead3a35526

工作原理

airflow是什么?

airflow是Airbnb开源的一个用python编写的调度工具,项目于2014年启动,2015年春季开源,2016年加入Apache软件基金会的孵化计划。

Airflow is a platform to programmatically author, schedule and monitor workflows.
airflow是一个可编程、调度和监控的工作流平台。

Use airflow to author workflows as directed acyclic graphs (DAGs) of tasks. The airflow scheduler executes your tasks on an array of workers while following the specified dependencies. Rich command line utilities make performing complex surgeries on DAGs a snap. The rich user interface makes it easy to visualize pipelines running in production, monitor progress, and troubleshoot issues when needed.
基于有向无环图(DAG),airflow可以定义一组有依赖的任务,按照依赖依次执行。airflow提供了丰富的命令行工具用于系统管控,而其web管理界面同样也可以方便的管控调度任务,并且对任务运行状态进行实时监控,方便了系统的运维和管理。

airflow能用来干什么?

在实际项目中,我们经常遇到以下场景:

  • 运维人员,定时对服务器执行脚本某些脚本,最简单的方式是添加一些crond任务,但如果想追溯各个任务的执行结果时?
  • 在大数据场景下,每隔一段时间需导出线上数据、导入到大数据平台、触发数据处理等多个子操作,且各个子操作含有依赖关系时?
  • 在管理大量主机时,想要一个统一的作业管理平台,能在上面定义各种任务来管理下面的设备?

airflow通过DAG配置文件,能轻松定义各种任务及任务之间的依赖关系和调度执行,并一个可视化的操作web界面。

airflow有什么优势?

  • 自带web管理界面,易上手;
  • 业务代码和调度代码完全解耦;
  • 通过python代码定义子任务,并支持各种Operate操作器,灵活性大,能满足用户的各种需求;
  • python开源项目,支持扩展operate等插件,便于二次开发;
    类似的工具有akzban,quart等;

 

详细安装步骤

实验环境:
centos7
python3.6
安装脚本:

yum install -y python36
yum install -y python36-pip
yum install -y python36-devel
pip3 install apache-airflow
pip3 install pymysql

设置airflow的根目录:

echo "export AIRFLOW_HOME=/data/airflow" >> /root/.bashrc
source /root/.bashrc

初始化

初始化数据库表(默认使用本地的sqlite数据库):

[root@VM_7_246_centos /data]# airflow initdb
[2019-08-05 19:23:29,691] {__init__.py:51} INFO - Using executor SequentialExecutor
DB: sqlite:////data/airflow/airflow.db
[2019-08-05 19:23:30,019] {db.py:350} INFO - Creating tables
INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
INFO  [alembic.runtime.migration] Running upgrade  -> e3a246e0dc1, current schema
INFO  [alembic.runtime.migration] Running upgrade e3a246e0dc1 -> 1507a7289a2f, create is_encrypted
/usr/local/lib/python3.6/site-packages/alembic/util/messaging.py:69: UserWarning: Skipping unsupported ALTER for creation of implicit constraint
  warnings.warn(msg)
INFO  [alembic.runtime.migration] Running upgrade 1507a7289a2f -> 13eb55f81627, maintain history for compatibility with earlier migrations
INFO  [alembic.runtime.migration] Running upgrade 13eb55f81627 -> 338e90f54d61, More logging into task_instance
INFO  [alembic.runtime.migration] Running upgrade 338e90f54d61 -> 52d714495f0, job_id indices
INFO  [alembic.runtime.migration] Running upgrade 52d714495f0 -> 502898887f84, Adding extra to Log
INFO  [alembic.runtime.migration] Running upgrade 502898887f84 -> 1b38cef5b76e, add dagrun
INFO  [alembic.runtime.migration] Running upgrade 1b38cef5b76e -> 2e541a1dcfed, task_duration
INFO  [alembic.runtime.migration] Running upgrade 2e541a1dcfed -> 40e67319e3a9, dagrun_config
INFO  [alembic.runtime.migration] Running upgrade 40e67319e3a9 -> 561833c1c74b, add password column to user
INFO  [alembic.runtime.migration] Running upgrade 561833c1c74b -> 4446e08588, dagrun start end
INFO  [alembic.runtime.migration] Running upgrade 4446e08588 -> bbc73705a13e, Add notification_sent column to sla_miss
INFO  [alembic.runtime.migration] Running upgrade bbc73705a13e -> bba5a7cfc896, Add a column to track the encryption state of the 'Extra' field in connection
INFO  [alembic.runtime.migration] Running upgrade bba5a7cfc896 -> 1968acfc09e3, add is_encrypted column to variable table
INFO  [alembic.runtime.migration] Running upgrade 1968acfc09e3 -> 2e82aab8ef20, rename user table
INFO  [alembic.runtime.migration] Running upgrade 2e82aab8ef20 -> 211e584da130, add TI state index
INFO  [alembic.runtime.migration] Running upgrade 211e584da130 -> 64de9cddf6c9, add task fails journal table
INFO  [alembic.runtime.migration] Running upgrade 64de9cddf6c9 -> f2ca10b85618, add dag_stats table
INFO  [alembic.runtime.migration] Running upgrade f2ca10b85618 -> 4addfa1236f1, Add fractional seconds to mysql tables
INFO  [alembic.runtime.migration] Running upgrade 4addfa1236f1 -> 8504051e801b, xcom dag task indices
INFO  [alembic.runtime.migration] Running upgrade 8504051e801b -> 5e7d17757c7a, add pid field to TaskInstance
INFO  [alembic.runtime.migration] Running upgrade 5e7d17757c7a -> 127d2bf2dfa7, Add dag_id/state index on dag_run table
INFO  [alembic.runtime.migration] Running upgrade 127d2bf2dfa7 -> cc1e65623dc7, add max tries column to task instance
INFO  [alembic.runtime.migration] Running upgrade cc1e65623dc7 -> bdaa763e6c56, Make xcom value column a large binary
INFO  [alembic.runtime.migration] Running upgrade bdaa763e6c56 -> 947454bf1dff, add ti job_id index
INFO  [alembic.runtime.migration] Running upgrade 947454bf1dff -> d2ae31099d61, Increase text size for MySQL (not relevant for other DBs' text types)
INFO  [alembic.runtime.migration] Running upgrade d2ae31099d61 -> 0e2a74e0fc9f, Add time zone awareness
INFO  [alembic.runtime.migration] Running upgrade d2ae31099d61 -> 33ae817a1ff4, kubernetes_resource_checkpointing
INFO  [alembic.runtime.migration] Running upgrade 33ae817a1ff4 -> 27c6a30d7c24, kubernetes_resource_checkpointing
INFO  [alembic.runtime.migration] Running upgrade 27c6a30d7c24 -> 86770d1215c0, add kubernetes scheduler uniqueness
INFO  [alembic.runtime.migration] Running upgrade 86770d1215c0, 0e2a74e0fc9f -> 05f30312d566, merge heads
INFO  [alembic.runtime.migration] Running upgrade 05f30312d566 -> f23433877c24, fix mysql not null constraint
INFO  [alembic.runtime.migration] Running upgrade f23433877c24 -> 856955da8476, fix sqlite foreign key
INFO  [alembic.runtime.migration] Running upgrade 856955da8476 -> 9635ae0956e7, index-faskfail
INFO  [alembic.runtime.migration] Running upgrade 9635ae0956e7 -> dd25f486b8ea
INFO  [alembic.runtime.migration] Running upgrade dd25f486b8ea -> bf00311e1990, add index to taskinstance
INFO  [alembic.runtime.migration] Running upgrade 9635ae0956e7 -> 0a2a5b66e19d, add task_reschedule table
INFO  [alembic.runtime.migration] Running upgrade 0a2a5b66e19d, bf00311e1990 -> 03bc53e68815, merge_heads_2
INFO  [alembic.runtime.migration] Running upgrade 03bc53e68815 -> 41f5f12752f8, add superuser field
INFO  [alembic.runtime.migration] Running upgrade 41f5f12752f8 -> c8ffec048a3b, add fields to dag
INFO  [alembic.runtime.migration] Running upgrade c8ffec048a3b -> a56c9515abdc, Remove dag_stat table
INFO  [alembic.runtime.migration] Running upgrade c8ffec048a3b -> dd4ecb8fbee3, Add schedule interval to dag
INFO  [alembic.runtime.migration] Running upgrade dd4ecb8fbee3 -> 939bb1e647c8, task reschedule fk on cascade delete
WARNI [airflow.utils.log.logging_mixin.LoggingMixin] cryptography not found - values will not be stored encrypted.
Done.

查看其生成文件:

[root@VM_7_246_centos /data]# ls $AIRFLOW_HOME
airflow.cfg  airflow.db  logs  unittests.cfg

配置

配置MySQL数据库(创建airflow数据库,并创建用户和授权,给airflow访问数据库使用):

# 新建airflow的数据库
MariaDB [(none)]> CREATE DATABASE airflow;
# 授权从localhost登录的root账号对airflow的所有操作
MariaDB [(none)]> GRANT all privileges on root.* TO 'root'@'localhost'  IDENTIFIED BY '123456'; 
MariaDB [(none)]> FLUSH PRIVILEGES;

配置airflow使用LocalExecutor执行器,及使用MySQL数据库:

 

vim airflow/airflow.cfg
# The executor class that airflow should use. Choices include
# SequentialExecutor, LocalExecutor, CeleryExecutor, DaskExecutor, KubernetesExecutor
#executor = SequentialExecutor
executor = LocalExecutor

# The SqlAlchemy connection string to the metadata database.
# SqlAlchemy supports many different database engine, more information
# their website
#sql_alchemy_conn = sqlite:////data/airflow/airflow.db
sql_alchemy_conn = mysql+pymysql://root:123456@localhost:3306/airflow

再次初始化数据库表(在MySQL中创建):

 

airflow initdb

查看创建的airflow数据表:

MariaDB [None] > use airflow;
MariaDB [airflow]> show tables;
+-------------------+
| Tables_in_airflow |
+-------------------+
| alembic_version  |
| chart            |
| connection        |
| dag              |
| dag_pickle        |
| dag_run          |
| dag_stats        |
| import_error      |
| job              |
| known_event      |
| known_event_type  |
| log              |
| sla_miss          |
| slot_pool        |
| task_fail        |
| task_instance    |
| users            |
| variable          |
| xcom              |
+-------------------+

服务启动

添加airflow-scheduler服务启动脚本:

 

/usr/lib/systemd/system/airflow-scheduler.service 
[Unit]
Description=Airflow Scheduler
Wants=network-online.target
After=network-online.target

[Service]
User=root
Group=root
Type=simple
Restart=on-failure
Environment=export AIRFLOW_HOME=/data/airflow
ExecStart=/usr/local/bin/airflow scheduler
LimitNOFILE=10000
TimeoutStopSec=20

[Install]
WantedBy=multi-user.target

启动airflow-scheduler服务:

 

systemctl start airflow-scheduler

添加airflow-webserver服务启动脚本:

 

/usr/lib/systemd/system/airflow-webserver.service 
[Unit]
Description=Airflow Scheduler
Wants=network-online.target
After=network-online.target

[Service]
User=root
Group=root
Type=simple
Restart=on-failure
Environment=export AIRFLOW_HOME=/data/airflow
ExecStart=/usr/local/bin/airflow webserver
LimitNOFILE=10000
TimeoutStopSec=20

[Install]
WantedBy=multi-user.target

启动airflow-webserver服务:

 

systemctl start airflow-webserver

使用

访问http://localhost:8080地址,看到首页界面即成功;

 

 
 
 

 

【入门Airflow】 使用Docker在本地快速搭建Airflow 本文主要参考官方文档编写。我将顺着官方文档的流程在本地安装Airflow ,并且附上安装过程的截图。 其实官方文档步骤写得都是比较详细,奈何这英语能力真的拉跨。 不过还是建议大家在使用过程中遇到的任何问题,优先去查看官方文档,有奇效。 ​ 官方文档: https://airflow.apache.org/docs/apache-airflow/stable/start/docker.html 生产准备 这里Airflow官方建议我们不要使用当前这种“快速入门”的方式用在生产环境。本文的这种方式就供我们 阅读详情

相关推荐

Airflow【部署 01】Airflow官网Quick Start实操(一篇学会部署Airflow)_apache airflow教程

【代码】Airflow【部署 01】Airflow官网Quick Start实操(一篇学会部署Airflow)_apache airflow教程。

2401_86454712的博客 1460

Airflow从入门到实战(万字长文)

Airflow 是一个以编程方式编写,安排和监视工作流的平台。使用 Airflow 将工作流编写任务的有向无环图(DAG)。Airflow 计划程序在遵循指定的依赖项,同时在一组工作线程上执行任务。丰富的命令实用程序使在 DAG 上执行复杂的调度变的轻而易举。丰富的用户界面使查看生产中正在运行的管道,监视进度以及需要时对问题进行故障排除变的容易。

weixin_45417821的博客 4万+

Airflow 介绍

官网 http://airflow.apache.org/ 关健概念:http://airflow.apache.org/concepts.html BashOperator:- 执行bash命令(executes a bash command) BranchPythonOperator:- 跟据条件执行下游任务,如果条件不符合,则不执行下游 PythonOperator:- 执行任意pytho...

T_Janey 3028

airflow二次开发

airflow list_dags airflow list_tasks data_track --tree 1 编写 任务: """ Code that goes along with the Airflow located at: http://airflow.readthedocs.org/en/latest/tutorial.html """ from airf...

leexiehui的博客 2727

AIRFLOW使用总结

由于机器学习各流程时长较长,并且流程比较复杂,经过选型对比,决定选用airflow作为流程调度器 一、选型对比 网上有较详细的各种流程调度器特性对比:https://www.jdon.com/workflow/Airflow-vs-Azkaban-vs-Conductor-vs-Oozie-vs-Amazon-Step-Functions.html 个人选择airlfow作为机器学习流程调...

peking1987的专栏 5868

airflow调度使用心得

从第一次接触airflow到生产投产使用已经有近两个月的时间了,从部署到开发到运维调优,期间也遇到各种各样的问题,自己也从听说到熟悉。这篇博客主要从三个方面着手。 一、安装部署airflow 调度工具airflow安装使用 一、安装airflow 1.环境准备: 1.1.安装mysql数据库 解压 mariadb包: tar -xzvf mariadb-10.2.14-linux-x86_64.t...

qqq932778763的博客 2909

全流程调度-Airflow介绍和使用

Airflow是一个以编程方式编写,安排和监视工作流的平台。使用Airflow将工作流编写任务的有向无环图(DAG)。Airflow计划程序在遵循指定的依赖项,同时在一组工作线程上执行任务。丰富的命令实用程序使在DAG上执行复杂的调度变的轻而易举。丰富的用户界面使查看生产中正在运行的管道,监视进度以及需要时对问题进行故障排除变的容易。

迷雾总会解 1万+

Airflow【部署 01】Airflow官网Quick Start实操(一篇学会部署Airflow)_apache airflow教程(1)

【代码】Airflow【部署 01】Airflow官网Quick Start实操(一篇学会部署Airflow)_apache airflow教程(1)

2401_86454699的博客 1521

大数据调度平台Airflow(五):Airflow使用

以上python文件就是Airflowpython脚本,使用代码方式指定DAG的结构。

lisheng19870305的专栏 1万+

Airflow安装部署

1. airflow需要python2.7以上的版本,安装前请检查python版本 python -V 2. 安装相关依赖 使用root用户进行如下操作: yum groupinstall "Development tools" yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel pyt

L的博客 2768

Arm CCA架构:硬件级机密计算与安全隔离技术解析

机密计算(Confidential Computing)通过硬件级隔离技术构建可信执行环境(TEE),是当前云安全和数据隐私保护的核心方案。Armv9-A引入的CCA架构采用物理地址空间隔离和Granule保护表(GPT)机制,实现4KB颗粒度的内存访问控制。该技术通过标准化的RMI/RSI接口规范,为虚拟化环境和安全敏感应用提供硬件级保护,特别适用于金融交易、医疗数据处理等需要严格隔离的场景。相比传统TEE方案,Arm CCA在隔离等级和动态权限管理方面具有显著优势,其Realm World设计为机密计算

weixin_30905133的博客 566

Airflow简介

1、什么是Airflow Airflow 是一个 Airbnb 的 Workflow 开源项目,使用Python编写实现的任务管理、调度、监控工作流平台。Airflow 是基于DAG(有向无环图)的任务管理系统,可以简单理解为是高级版的crontab,但是它解决了crontab无法解决的任务依赖问题。与crontab相比Airflow可以方便查看任务的执行状况(执行是否成功、执行时间、执行依 赖等),可追踪任务历史执行情况,任务执行失败时可以收到邮件通知,查看错误日志。 2、Airflow与同类产品的

fighting 3万+

Sigrity XtractIM实战:5步搞定IC封装宽带模型提取(附BGA案例)

本文通过一个典型BGA封装案例,详细介绍了使用Cadence Sigrity XtractIM工具进行IC封装宽带模型提取的五步实战流程。内容涵盖从环境准备、参数设置、结果验证到模型导出的完整操作,重点阐述了如何利用XtractIM生成高精度、紧凑的宽带SPICE模型,以解决高速电路设计中因封装模型不准导致的信号与电源完整性问题,助力工程师提升仿真精度与设计效率。

a1b2c的博客 320

airflow 使用Celery Executor

airflow 下配置使用Celery Executor

zhujisoft的专栏 4964

Python离线断网情况下安装numpy、pandas和matplotlib等常用第三方包

联网情况下在命令终端CMD中输入“pip install numpy”即可自动安装,pandas和matplotlib同理一样方法进行自动安装。 工作的电脑不能上外网,所以不能通过直接输入pip命令来安装。 环境:电脑上已经安装了Python(没有安装的请参考其他教程)。 Python离线断网情况下安装numpy、pandas和matplotlib等常用第三方包的步骤如下: ...

dayou7738的博客 4944

jieba分词

jieba

sikh_0529的博客 1万+

Airflow教程-使用Airflow实现ETL调度

一、Airflow是什么 airflow 是一个编排、调度和监控workflow的平台,由Airbnb开源,现在在Apache Software Foundation 孵化。airflow 将workflow编排为由tasks组成的DAGs(有向无环图),调度器在一组workers上按照指定的依赖关系执行tasks。同时,airflow 提供了丰富的命令行工具和简单易用的用户界面以便用户...

weixin_30522183的博客 2864

在 NVIDIA DGX Spark 上运行 vLLM + Open WebUI

DGX Spark 和 GX10 都是性能强大的机器,但只有将它们视为交互式工作站而非精简版服务器,才能真正发挥它们的优势。合理利用共享资源,规划并发工作负载,并谨慎控制内存限制。做到这些,vLLM 与 Open WebUI 的结合就能成为可靠​​的日常工具,而不是脆弱的实验品。DGX平台本身价格不菲,但这并非体验此类硬件的唯一途径。多家厂商提供基于相同核心架构、价格更为亲民的系统,这些系统通常配备容量较小的固态硬盘或配置更为简化,但基本性能并未改变。

iCloudEnd的博客 1751

Airflow搭建与使用

Airflow 是一个编排、调度和监控workflow的平台,由Airbnb开源,现在在Apache Software Foundation 孵化

6525

手把手教你学Simulink——基于Simulink的无感FOC(滑模观测器+PLL)实战

本文详细介绍了基于Simulink的无感FOC(滑模观测器+PLL)实现方法。主要内容包括:1)SMO+PLL原理精讲,阐述滑模观测器核心思想和PLL的作用;2)系统架构全景图展示;3)Simulink建模全流程,从基础FOC框架到SMO和PLL模块的实现;4)关键参数整定指南和工程实践要点;5)仿真结果分析及常见问题解决方案。该方法可有效替代机械传感器,降低成本并提高可靠性,适用于空调压缩机、电动汽车水泵等工业场景。文章还提供了详细的调试建议和动手实践指导。

MHD0815的博客 83

多标签图像分类:标签依赖关系建模的最新论文解读与实战应用

多标签图像分类:标签依赖关系建模的最新论文解读与实战应用 ,人工智能,计算机视觉,大模型,AI,本文解读了最新相关论文,包括基于图神经网络(GCN)的ML-GCN方法,通过构建标签相关矩阵建模依赖关系;区域潜在语义依赖的RLSD模型,定位关键区域并利用RNN建模语义依赖;以及语义图表示学习的SSGRL框架,结合语义解耦与交互模块。通过实战应用,展示了基于PyTorch的ML-GCN模型实现,包括图像特征提取、标签依赖建模及训练评估流程,为多标签图像分类提供了有效解决方案。

不踩坑,不知道坑有多深;不总结,踩过的坑白踩。 18万+

Apache Airflow 安装

安装环境: ubuntu 14.04 root:root用户 darren:普通用户(有sudo权限) 安装: 第一步:安装python sudo apt-get update sudo apt-get install python3 如果已经安装过python3,可以跳过此步。 第二步:配置软连接 sudo ln -s /usr/bin/python3.4 /usr/bin...

三丰的专栏 6267

YOLOv11【第二十章:模型迭代与生态闭环篇·第1节】在线增量学习——部署后新数据自动回流重训!

🏆 本文收录于专栏 《YOLOv11实战:从入门到深度优化》。本专栏围绕 YOLOv11 的改进、训练、部署与工程优化 展开,系统梳理并复现当前主流的 YOLOv11 实战案例与优化方案,内容目前已覆盖 分类、检测、分割、追踪、关键点、OBB 检测 等多个方向。

**My Coding Family** 433

Airflow 中文文档:使用systemd运行Airflow

Airflow可以与基于系统的系统集成。 这使得观察您的守护进程变得容易,因为systemd可以在失败时重新启动守护进程。 在scripts/systemd目录中,您可以找到已在基于Redhat的系统上测试过的单元文件。 您可以将它们复制到/usr/lib/systemd/system 。 假设Airflow将在airflow:airflow下运行airflow:airflow 。 如果不是(或者...

龙哥盟 4万+

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

上一篇: 漫画HDFS工作原理
下一篇: airflow 相关资料
lcl_bigdata
博客等级 码龄11年 268粉丝 67原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值