前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >airflow 配置 CeleryExecutor

airflow 配置 CeleryExecutor

作者头像
somenzz
发布2020-12-10 11:20:34
2.3K0
发布2020-12-10 11:20:34
举报
文章被收录于专栏:Python七号Python七号

阅读本文大概需要 3 分钟

celery 是分布式任务队列,与调度工具 airflow 强强联合,可实现复杂的分布式任务调度,这就是 CeleryExecutor,有了 CeleryExecutor,你可以调度本地或远程机器上的作业,实现分布式任务调度。本文介绍如何配置 airflow 的 CeleryExecutor。

操作步骤

CeleryExecutor 需要 Python 环境安装有 celery。

第一步: 安装celery

代码语言:javascript
复制
pip install celery

Celery 需要一个发送和接受消息的传输者 broker。RabbitMQ 和 Redis 官方推荐的生产环境级别的 broker,这里我们选用 Redis,只是因为安装起来非常方便,而 RabbitMQ 的安装需要 再安装 erlang 。

第二步:安装 redis

先从 https://redis.io/download 下载稳定版本,目前是 redis-4.0.11.tar.gz。

代码语言:javascript
复制
tar -zxvf redis-4.0.11.tar.gz
cd redis-4.0.11
make      #编译
make test  #验证
cp redis.conf src/  #将配置文件复制以可执行文件同一目录
cd src
./redis-server redis.conf #按默认方式启动 redis-server ,仅监听 127.0.0.1 ,若监听其他 ip 修改为 bind 0.0.0.0

运行后的输出如下所示:

代码语言:javascript
复制
7359:C 16 Aug 21:19:26.539 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
7359:C 16 Aug 21:19:26.539 # Redis version=4.0.11, bits=64, commit=00000000, modified=0, pid=7359, just started
7359:C 16 Aug 21:19:26.539 # Configuration loaded
7359:M 16 Aug 21:19:26.541 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 4.0.11 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 7359
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

7359:M 16 Aug 21:19:26.544 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
7359:M 16 Aug 21:19:26.544 # Server initialized
7359:M 16 Aug 21:19:26.544 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
7359:M 16 Aug 21:19:26.545 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
7359:M 16 Aug 21:19:26.545 * Ready to accept connections

实际应用时需要在后台持续运行:

代码语言:javascript
复制
nohup ./redis-server redis.conf 2>1&

第三步:配置 airflow.cfg

修改 airflow.cfg

代码语言:javascript
复制
#修改 3 处:
executor = CeleryExecutor
broker_url = redis://127.0.0.1:6379/0
celery_result_backend = redis://127.0.0.1:6379/0

第四步:安装 python 的 redis 包,为启动 worker 作准备

代码语言:javascript
复制
pip install redis

第五步:运行 airflow

代码语言:javascript
复制
#启动webserver
#后台运行  airflow webserver -p 8080 -D
airflow webserver -p 8080

#启动scheduler
#后台运行  airflow scheduler -D
airflow scheduler
#启动worker
#后台运行  airflow worker -D
#如提示addres already use ,则查看 worker_log_server_port = 8793 是否被占用,如是则修改为 8974 等
#未被占用的端口
airflow worker
#启动flower -- 可以不启动
#后台运行  airflow flower -D
airflow flower

运行成功后如下所示:

END

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2018-08-16,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 Python七号 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 操作步骤
    • 第一步: 安装celery
      • 第二步:安装 redis
        • 第三步:配置 airflow.cfg
          • 第四步:安装 python 的 redis 包,为启动 worker 作准备
            • 第五步:运行 airflow
            相关产品与服务
            云数据库 Redis
            腾讯云数据库 Redis(TencentDB for Redis)是腾讯云打造的兼容 Redis 协议的缓存和存储服务。丰富的数据结构能帮助您完成不同类型的业务场景开发。支持主从热备,提供自动容灾切换、数据备份、故障迁移、实例监控、在线扩容、数据回档等全套的数据库服务。
            领券
            问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档