mysql初始化实例报错,百度云安装airflow初体验(2019-12-12)

项目要搞个airflow来做任务排布,自己先在百度云上做实验(不要用1*1的服务器,带不动,哭。。。)

下面是流水账,开始。。。

百度云安装:

1.重装的新系统,Centos7.5。个人喜欢Centos系统,如果要用到项目上,建议和项目环境一致。

2.重装python3

a.make install python3安装包的时候提示ModuleNotFoundError: No module named '_ctypes',需要yum install libffi-devel -y,然后再重新make install

b.安装完了并软连接Python3-Python,记得要改yum,vim /usr/bin/yum 在Python后面加上2.7(是因为centos7.5上的python是2.7版本的)

vim /usr/libexec/urlgrabber-ext-down,vim /usr/bin/yum-config-manager,都是在python后面加2.7

c. 百度云居然没有装pip,重新安装python3后需要重新指定软连接,sudo ln -sf /service/python3/bin/pip3 /usr/bin/pip (sf是覆盖原有的)

d. 开始安装,提示pip要升级,并且速度奇慢,换到清华源(怎么换可以度娘,这里就不哔哔了)

3.安装airflow

a. 安装中提示OSError: mysql_config not found,解决方案sudo yum install mysql-devel

b. 安装pydruid报错( distutils.errors.DistutilsError: Could not find suitable distribution for Requirement.parse('pytest-runner')),解决方案,pip install pytest-runner

c. 安装报错distutils.errors.DistutilsError: Could not find suitable distribution for Requirement.parse('Cython!=0.25,<0.30,>=0.20'),解决方案pip install Cython

d. 安装webencodings报错 gcc: error trying to exec 'cc1plus': execvp: No such file or directory,解决方案yum install gcc-c++

e. 隐藏的坑,安装webencodings报error,缺少google-cloud-spanner 1.9.0,google-cloud-bigtable 0.33.0,moto 1.3.5,snowflake-connector-python 2.0.3解决方案安装airflow几次会装上的,联网状态看脸。

f. 报错sasl/saslwrapper.h:22:23: fatal error: sasl/sasl.h: No such file or directory,解决方案yum install -y gcc-c++,yum -y install cyrus-sasl cyrus-sasl-devel cyrus-sasl-lib

4.初始化

a. 安装完成后初始化元数据库信息(其实也就是新建airflow依赖的表)airflow initdb,提示没有airflow命令,汗。。。

vi /etc/profile ;结尾添加一行export PATH=$PATH:/service/python3/bin;之后source /etc/profile 。

run起来了。。。,如果不修改配置文件只是单进程运行,可用于测试环境.

修改时区,默认是utc.(可以参考https://blog.csdn.net/crazy__hope/article/details/83688986)

配置篇记录:

1.如果不修改airflow 配置文件 $AIRFLOW_HOME/airflow.cfg,直接启动 webserver 和 scheduler,一个基于 sqilte 数据库的 airflow 服务已经启动,且可以添加任务运行,执行器为 SequentialExecutor,常用于测试环境。

2.Executor

SequentialExecutor:单进程顺序执行任务,默认执行器,通常只用于测试

LocalExecutor:多进程本地执行任务

CeleryExecutor:分布式调度,生产常用

DaskExecutor :动态任务调度,主要用于数据分析

a. 配置mysql数据库后重新初始化,报错:Exception: Global variable explicit_defaults_for_timestamp needs to be on (1) for mysql

解决方案:Set explicit_defaults_for_timestamp = 1 under the mysqld section in your my.cnf file.

(https://airflow.readthedocs.io/en/stable/faq.html#how-to-fix-exception-global-variable-explicit-defaults-for-timestamp-needs-to-be-on-1)

重启mysql (systemctl restart mysqld.service)

3.启动webserver(airflow webserver -p 8080)

4.启动scheduler (airflow scheduler)

5.AIRFLOW_HOME下创建文件夹dags,用来放dag脚本

4.删除实例dags:

删除/usr/lib/python2.7/site-packages/airflow/example_dags下 .py和 .pyc文件

airflow resetdb,重启数据库

启动airflow webserver

5.远程连接mysql报1045错:

mysql默认远程关闭,登录mysql,grant all privileges on *.* to 'root' @'%' identified by 'root'; flush privileges;

6.配置报警邮箱:

****@163.com

---参考https://blog.csdn.net/shujuelin/article/details/100693485

配置报警邮件中log连接:

修改/site-packages/airflow/models下的taskinstance.py,def log_url(self): #base_url = conf.get('webserver', 'BASE_URL')

base_url = 'http://localhost:8080',换成ip地址

7.修改时区(改airflow源码)(参考https://blog.csdn.net/crazy__hope/article/details/83688986)

a.在airflow home目录下修改airflow.cfg,设置 default_timezone = Asia/Shanghai

b.进入airflow包的安装位置,也就是site-packages的位置,以下修改文件均为相对位置/home/seanyang/.local/lib/python3.6/site-packages

c.修改airflow/utils/timezone.py

在 utc = pendulum.timezone(‘UTC’) 这行(第27行)代码下添加

from airflow import configuration as conf

try:

tz = conf.get("core", "default_timezone")

if tz == "system":

utc = pendulum.local_timezone()

else:

utc = pendulum.timezone(tz)

except Exception:

pass

修改utcnow()函数 (在第69行)

原代码 d = dt.datetime.utcnow()

修改为 d = dt.datetime.now()

d.修改airflow/utils/sqlalchemy.py

在utc = pendulum.timezone(‘UTC’) 这行(第37行)代码下添加

from airflow import configuration as conf

try:

tz = conf.get("core", "default_timezone")

if tz == "system":

utc = pendulum.local_timezone()

else:

utc = pendulum.timezone(tz)

except Exception:

pass

e.修改airflow/www/templates/admin/master.html(第31行)

把代码 var UTCseconds = (x.getTime() + x.getTimezoneOffset()*60*1000);

改为 var UTCseconds = x.getTime();

把代码 "timeFormat":"H:i:s %UTC%",

改为  "timeFormat":"H:i:s",

f.最后重启airflow-webserver即可

体验:

1.Dag脚本模板

当ailflow在DAG中找到循环或当依赖项被引用不止一次时,会引发异常。

2.测试脚本

脚本没有异常。---python ~/airflow/dags/tutorial.py

验证执行中的dag的元素:

# print the list of active DAGs

airflow list_dags

# prints the list of tasks the "tutorial" dag_id

airflow list_tasks tutorial

# prints the hierarchy of tasks in the tutorial DAG

airflow list_tasks tutorial --tree

3.*坑* DAG的开始时间,比如这里就是从2015年6月1日开始执行第一个DAG。这个参数会影响到部署上线时回填DAG的数量。一般建议写成上线时间的前一天(因为这里的start_date指的是execute_date,而Airflow执行的逻辑是,今天的同一时间执行昨天的任务,比如execute_date=2018-03-01, 每天凌晨3点执行,则会在2018-03-02 03:00:00启动这个DAG。

4.dag参数中增加catchup=False,可以关闭回填。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值