安装Mysql (否则后面 pip install mysql) 无法安装
#ubuntu
sudo apt-get install libmysqlclient-dev
pip 依赖:
pip install apache-airflow[celery,crypto,mysql,password,redis]
airflow-LocalExecutor
mysql-airflow
pip install mysqlclient
在mysql上执行
create database airflow; —— 创建数据库
GRANT all privileges on airflow.* TO 'airflow'@'%' IDENTIFIED BY '123456'; —— 将数据库airflow的所有权限授权airflow用户,密码123456且该用户可在任何IP段登录操作
FLUSH PRIVILEGES; —— 刷新权限
set explicit_defaults_for_timestamp = 1;
修改airflow配置文件airflow.cfg
sql_alchemy_conn = mysql://airflow:123456@mysqlIP/airflow
修改执行器,使airflow并发调度任务
修改配置文件airflow.cfg
executor = LocalExecutor
重启scheduler即可(默认并发调度16)
初始化数据库
airflow initdb
若之前使用sqllite初始化过可使用airflow resetdb
irflow initdb :
出现异常:Exception: Global variable explicit_defaults_for_timestamp needs to be on (1) for mysql
解决方式:
https://airflow.readthedocs.io/en/stable/faq.html#how-to-fix-exception-global-variable-explicit-defaults-for-timestamp-needs-to-be-on-1
出现异常:Exception: Global variable explicit_defaults_for_timestamp needs to be on (1) for mysql
解决方式:
https://airflow.readthedocs.io/en/stable/faq.html#how-to-fix-exception-global-variable-explicit-defaults-for-timestamp-needs-to-be-on-1
docker exec -it meu_mysql /bin/bash cd /etc/mysql/ root@8ab0b9bd6a08:/etc/mysql/conf.d# cat mysql.cnf [mysql] root@8ab0b9bd6a08:/etc/mysql/conf.d# echo '[mysqld]' >> mysql.cnf root@8ab0b9bd6a08:/etc/mysql/conf.d# echo 'explicit_defaults_for_timestamp = 1' >> mysql.cnf root@8ab0b9bd6a08:/etc/mysql/conf.d# cat mysql.cnf [mysql] [mysqld] explicit_defaults_for_timestamp = 1max_allowed_packet= 500M
分布式问题
1.需要使用同步方式解决dags目录与worker的同步问题——待解决
2.需要解决scheduler的单点问题,可参考 apache-airflow 调度系统 https://blog.csdn.net/somezz/article/details/82749495