文章目录
apache-airflow
Airflow是一个以编程方式编写,安排和监视工作流的平台。
使用Airflow将工作流创作为任务的有向无环图(DAG)。Airflow调度程序在遵循指定的依赖项的同时,在一组工作线程上执行任务。丰富的命令行实用程序使在DAG上执行复杂的手术变得轻而易举。丰富的用户界面使查看生产中正在运行的管道,监视进度以及在需要时对问题进行故障排除变得容易。
将工作流定义为代码时,它们将变得更具可维护性,可版本化,可测试和协作性。
用于定时任务管理
文档地址
安装
pip版本 20.3.3 python3.7
pip install apache-airflow --use-deprecated legacy-resolver
碰到的问题
libmkl_core.dylib, 9): image not found.
airflow db init
碰到问题
INTEL MKL ERROR: dlopen(/Users/jicaihong/miniconda3/envs/py37/lib/libmkl_core.dylib, 9): image not found.
解决方案
https://discuss.pytorch.org/t/intel-mkl-fatal-error-cannot-load-libmkl-core-dylib/67710/3
conda install nomkl numpy scipy scikit-learn numexpr
conda remove mkl mkl-service
缺失No module named ‘kubernetes’
WARNING - Could not import DAGs in example_kubernetes_executor_config.py: No module named ‘kubernetes’
解决方案
pip install apache-airflow-providers-cncf-kubernetes
快速开始
# 0,可做可不做,非必选项
# airflow needs a home, ~/airflow is the default,
# but you can lay foundation somewhere else if you prefer
# (optional)
export AIRFLOW_HOME=~/airflow
# 1,初始化
airflow db init
airflow users create \
--username admin \
--firstname Peter \
--lastname Parker \
--role Admin \
--email spiderman@superhero.org
# 密码:
# 123456
# start the web server, default port is 8080
airflow webserver --port 8081
# 后台启动 airflow 前端
airflow webserver --port 8081 -D
# start the scheduler
# open a new terminal or else run webserver with ``-D`` option to run it as a daemon
# 启动 scheduler
airflow scheduler
运行这些命令后,Airflow将创建 $AIRFLOW_HOME 文件夹并使用默认设置创建“ airflow.cfg”文件,以使您快速入门。
您可以在$AIRFLOW_HOME/airflow.cfg中或通过Admin->Configuration菜单中的UI检查文件。
针对网络服务器的PID文件将被存储在$AIRFLOW_HOME/airflow-webserver.pid 或者 如果由systemd开始, /run/airflow/webserver.pid ,
Airflow默认使用 sqlite 数据库,但是使用此数据库后端无法进行并行化。
sqlite 与 airflow.executors.sequential_executor.SequentialExecutor 一起使用,后者只会按顺序运行任务实例。尽管这是非常有限的,但它允许您快速启动并运行,并浏览UI和命令行实用程序。
这里有一些命令将触发一些任务实例。example_bash_operator运行以下命令时,您应该能够在DAG中查看作业的状态更改。
# run your first task instance
airflow tasks run example_bash_operator runme_0 2015-01-01
# run a backfill over 2 days
airflow dags backfill example_bash_operator \
--start-date 2015-01-01 \
--end-date 2015-01-02
airflow架构
airflow组件
1,Metadata Database: Airflow 使用sql数据库存储原数据,比如Postgres,MySQL
2,Web Server and Scheduler: Airflow Web服务器 和 Scheduler 是在本地计算机上运行(在本例中)并与上述数据库进行交互的独立进程。
3,Executor: Executor在现实中它不是一个单独的进程,在 Scheduler调度程序内运行
4,Worker(s): Worker是单独的进程,还与airflow其它部件和元数据存储库交互。
5,airflow.cfg: 是Web服务器,Scheduler调度程序和Workers工作程序的配置文件。
6,DAGs: DAGs是指包含Python代码的DAG文件,代表着要由Airflow运行的数据管道。这些文件的位置在Airflow配置文件中指定,Web服务器,调度程序和工作程序都会访问它们。
附上pip freeze
alembic==1.4.3
apache-airflow==2.0.0
apache-airflow-providers-cncf-kubernetes==1.0.0
apache-airflow-providers-ftp==1.0.0
apache-airflow-providers-http==1.0.0
apache-airflow-providers-imap==1.0.0
apache-airflow-providers-sqlite==1.0.0
apispec==3.3.2
argcomplete==1.12.2
attrs==20.3.0
Babel==2.9.0
cached-property==1.5.2
cachetools==4.2.0
cattrs==1.1.2
certifi==2020.12.5
cffi==1.14.4
chardet==3.0.4
click==7.1.2
clickclick==20.10.2
colorama==0.4.4
colorlog==4.0.2
commonmark==0.9.1
connexion==2.7.0
croniter==0.3.37
cryptography==3.3.1
defusedxml==0.6.0
dill==0.3.3
dnspython==2.1.0
docutils==0.16
email-validator==1.1.2
Flask==1.1.2
Flask-AppBuilder==3.1.1
Flask-Babel==1.0.0
Flask-Caching==1.9.0
Flask-JWT-Extended==3.25.0
Flask-