airflow 是一个python写的调度平台,大致的认识是 : 定义一些任务(脚本、命令、连接...),airflow调度平台可以自动去运行,后面会给出运行日志(UI界面)等,这个UI界面(WEB端)有一些复杂的分析图谱,可以做的事情就很多了。

下面是介绍airflow使用非默认的数据库,默认是SQLite ,官方的介绍不够仔细,这篇是个人总结。

官方地址:http://airflow.apache/docs/stable/installation.html

一、登陆MySQL、创建数据库、创建用户密码、更新策略

mysql> create database airflow;
mysql> GRANT all privileges on airflow.* TO 'airflow'@'%' IDENTIFIED BY 'xE!D95Exxx';
mysql> FLUSH PRIVILEGES;

 二、设置MySQL对null的处理,重启服务器(可有可无)

mysql> set explicit_defaults_for_timestamp = 1;

重启服务器(可有可无)
[root@VM_0_16_centos airflow]# systemctl restart mysqld

 这个设置是官方文档提出的,下面是一篇文章关于此属性的介绍:https://www.jianshu/p/dfa0380eb6b9

 三、对airflow配置文件(airflow.cfg)的设置

#打开你安装airflow的文件夹
[root@VM_0_16_centos airflow]# 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 = mysql+pymysql://airflow:xxxxxxx@127.0.0.1/airflow


#注意pymysql库是否安装
[root@VM_0_16_centos airflow]# pip3 install pymysql

一些小坑提示:数据库连接路径要注意是否还是使用mysql的驱动 ,现在已经使用pymysql,没有安装会报错,找不到驱动。

四、重置数据库、初始化数据库

[root@VM_0_16_centos airflow]# airflow resetdb
[root@VM_0_16_centos airflow]# airflow initdb

 

更多推荐

airflow使用MySQL数据库(第三方数据库详解)