助力工业物联网,工业大数据之服务域:AirFlow的架构组件【三十二】_airflow大数据组件(2)

+ step1:架构
+ step2:组件
  • 实施

    • 架构

    image-20211005110933346

      - Client:开发AirFlow调度的程序的客户端,用于开发AirFlow的Python程序
      - Master:分布式架构中的主节点,负责运行WebServer和Scheduler
      - Worker:负责运行Execution执行提交的工作流中的Task
    
    • 组件

    image-20211005111759153

    A scheduler, which handles both triggering scheduled workflows, and submitting Tasks to the executor to run.
    An executor, which handles running tasks. In the default Airflow installation, this runs everything inside the scheduler, but most production-suitable executors actually push task execution out to workers.
    A webserver, which presents a handy user interface to inspect, trigger and debug the behaviour of DAGs and tasks.
    A folder of DAG files, read by the scheduler and executor (and any workers the executor has)
    A metadata database, used by the scheduler, executor and webserver to store state.
    
    
      - WebServer:提供交互界面和监控,让开发者调试和监控所有Task的运行
      - Scheduler:负责解析和调度Task任务提交到Execution中运行
      - Executor:执行组件,负责运行Scheduler分配的Task,运行在Worker中
      - DAG Directory:DAG程序的目录,将自己开发的程序放入这个目录,AirFlow的WebServer和Scheduler会自动读取
      	* airflow将所有程序放在一个目录中
      	* 自动检测这个目录有么有新的程序
      - MetaData DataBase:AirFlow的元数据存储数据库,记录所有DAG程序的信息
    
  • 小结

    • 了解AirFlow的架构组件

知识点06:AirFlow的开发规则

  • 目标掌握AirFlow的开发规则

  • 路径

    • step1:开发Python调度程序
    • step2:提交Python调度程序
  • 实施

    • 官方文档

      • 概念:http://airflow.apache.org/docs/apache-airflow/stable/concepts/index.html
    • 示例:http://airflow.apache.org/docs/apache-airflow/stable/tutorial.html

    • 开发Python调度程序

      • 开发一个Python程序,程序文件中需要包含以下几个部分
      • 注意:该文件的运行不支持utf8编码,不能写中文
      • step1:导包
      # 必选:导入airflow的DAG工作流
      from airflow import DAG
      # 必选:导入具体的TaskOperator类型
      from airflow.operators.bash import BashOperator
      # 可选:导入定时工具的包
      from airflow.utils.dates import days_ago
      
      

      image-20211015103936196

      • step2:定义DAG及配置
      # 当前工作流的基础配置
      default_args = {
          # 当前工作流的所有者
          'owner': 'airflow',
          # 当前工作流的邮件接受者邮箱
          'email': ['airflow@example.com'],
          # 工作流失败是否发送邮件告警
          'email\_on\_failure': True,
          # 工作流重试是否发送邮件告警
          'email\_on\_retry': True,
          # 重试次数
          'retries': 2,
          # 重试间隔时间
          'retry\_delay': timedelta(minutes=1),
      }
      
      # 定义当前工作流的DAG对象
      dagName = DAG(
          # 当前工作流的名称,唯一id
          'airflow\_name',
          # 使用的参数配置
          default_args=default_args,
          # 当前工作流的描述
          description='first airflow task DAG',
          # 当前工作流的调度周期:定时调度【可选】
          schedule_interval=timedelta(days=1),
          # 工作流开始调度的时间
          start_date=days_ago(1),
          # 当前工作流属于哪个组
          tags=['itcast\_bash'],
      )
      
      
        * 构建一个DAG工作流的实例和配置
      
      • step3:定义Tasks

        # 导入BashOperator
        from airflow.operators.bash import BashOperator
        # 定义一个Task的对象
        t1 = BashOperator(
        	# 指定唯一的Task的名称
            task_id='first\_bashoperator\_task',
        	# 指定具体要执行的Linux命令
            bash_command='echo "hello airflow"',
        	# 指定属于哪个DAG对象
            dag=dagName
        )
        
        
        • PythonOperator:定义一个Python代码的Task
        # 导入PythonOperator
        from airflow.operators.python import PythonOperator
        
        # 定义需要执行的代码逻辑
        def sayHello():
        
        
        

img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

需要这份系统化资料的朋友,可以戳这里获取

入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!**

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

需要这份系统化资料的朋友,可以戳这里获取

  • 7
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值