用Airflow调度数仓(CK)的ETL脚本

#安装

前提:安装了python,我这里是python3

下载

按照官网:
pip3 install apache-airflow
包太多,下载太慢
改为清华的镜像:
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple apache-airflow
又有包找不到
最后用豆瓣的镜像(注意要加trusted):
pip3 install apache-airflow -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
下载非常快。
【报错】
unable to execute ‘gcc’: No such file or directory
error: command ‘gcc’ failed with exit status 1

【解决办法】

yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make

【报错】
psutil/_psutil_common.c:9:20: fatal error: Python.h: No such file or directory
#include
^
compilation terminated.
error: command ‘gcc’ failed with exit status 1

【解决办法】

yum install python3-devel

修改后台数据库

  • 首次运行
    安装完以后,先运行一次:
    airflow initdb
    这时会创建好默认的配置文件,在~/airflow.cfg。
  • 修改配置
    将~/airflow.cfg中的:
1.executor = LocalExecutor
2.sql_alchemy_conn =  mysql://root:[email protected]/airflow?charset=utf8mb4
(**注意:需要提前在mysql中把数据库airflow创建好**)
(如果用pgsql,连接串为:postgresql+psycopg2://user:password@hostname/database_name)
  • 然后再次initdb
    airflow initdb
    【报错】
    ModuleNotFoundError: No module named 'MySQLdb’
    【解决办法】
    pip3 install mysqlclient
    【又报错】
    OSError: mysql_config not found
    【解决办法】

yum install mysql-devel
pip install mysqlclient

启动web GUI

airflow webserver -p 8090 -D
(因为8080被占用了)
![启动成功](https://upload-images.jianshu.io/upload_images/20370486-6ddfcde76c5087fe.png?
imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
这时候就可以在web页面管理了:登录http://127.0.0.1:8090
用Airflow调度数仓(CK)的ETL脚本_第1张图片

启动调度器

airflow scheduler -D
airflow scheduler

启停


重启webserver和scheduler

su airflow
 ps -ef|egrep ‘scheduler|airflow-webserver’|grep -v grep|awk ‘{print $2}’|xargs kill -9
 rm -rf /root/airflow/airflow-scheduler.pid 
 airflow webserver -p 8080 -D
  airflow scheduler -D
tail -f /root/airflow/airflow-scheduler.err

重启worker
su airflow
ps -ef|egrep ‘serve_logs|cele

你可能感兴趣的:(Airflow)