【原創】大數據基礎之Airflow(2)生產環境部署airflow研究


一 官方

airflow官方分布式部署結構圖

airflow進程

  • webserver
  • scheduler
  • flower(非必須)
  • worker

airflow缺點

  • scheduler單點
  • 通過在scheduler的dags目錄變動dag文件來提交流程

官方分布式部署方案

  • 多個webserver
  • 多個worker
    • CeleryExecutor(依賴redis或rabbitmq)
    • MesosExecutor(依賴mesos)

第三方開源方案ASFC

針對scheduler單點問題,有第三方方案:https://github.com/teamclairvoyant/airflow-scheduler-failover-controller

 

The Airflow Scheduler Failover Controller (ASFC) is a mechanism that ensures that only one Scheduler instance is running in an Airflow Cluster at a time. This way you don't come across the issues we described in the "Motivation" section above.

You will first need to startup the ASFC on each of the instances you want the scheduler to be running on. When you start up multiple instances of the ASFC one of them takes on the Active state and the other takes on a Standby state. There is a heart beat mechanism setup to track if the Active ASFC is still active. If the Active ASFC misses multiple heart beats, the Standby ASFC becomes active.

The Active ASFC will poll every 10 seconds to see if the scheduler is running on the desired node. If it is not, the ASFC will try to restart the daemon. If the scheduler daemons still doesn't startup, the daemon is started on another node in the cluster.

 

Airflow Scheduler Failover Controller (ASFC),實現方式為:多個實例中只有一個處於active狀態,處於active狀態的實例會每10s檢查一下scheduler進程是否存活並根據需要重啟進程;

壞消息是該方案和airflow新版本1.10不兼容

二 基於mesos+hdfs的airflow生產環境部署方案研究

相同部分

和官方一致

  • 使用mysql數據庫作為元數據庫

和官方不一致1

  • 所有對dags目錄的修改同步到hdfs上,保證dags目錄的高可用
  • 使用HDFS NFSGateway,將hdfs掛載到所有可能的scheduler節點上的,無論scheduler被部署在哪個節點上,都使用同一個dags目錄
  • 使用nginx+marathon-lb向外暴露airflow的webserver,可以操作流程或查看流程執行情況等

1 airflow單實例容器部署方案

和官方不一致2

  • webserver、scheduler、worker作為docker容器運行,在多個節點上只部署一個實例,由marathon保證可用性,由marathon-lb做服務發現
  • worker使用LocalExecutor,即所有的任務都使用子進程執行
    • 為了使容器內的worker的LocalExecutor能夠訪問外部集群功能,一種可行的方式是將各種組件的父目錄掛載到容器中(比如各個組件目錄為/app/java、/app/hive、/app/spark、/app/hdfs,則掛載/app目錄到容器內),然后所有的任務腳本一開始統一引入執行一個初始化環境變量的公共腳本,設置各種Home和Path,然后就可以在容器內使用各種組件的客戶端,比如java、hive、spark、hdfs等

2 airflow分布式容器部署方案

和官方不一致2

  • webserver和scheduler作為docker容器運行,在多個節點上只部署一個實例,由marathon保證可用性,由marathon-lb做服務發現
  • worker使用MesosExecutor:
    • 直接在mesos agent上執行airflow任務,好處是可以保證具體任務能夠訪問到集群的功能,比如impala/flink,缺點是需要在所有mesos agent節點的宿主機上部署airflow
    • 在mesos agent上部署airflow worker的docker容器,然后在容器中執行airflow任務,好處是部署0成本,缺點是docker容器內只包含worker,不能使用外部集群的功能,不過這個缺點可以使用上一方案中LocalExecutor相同的方式解決

 

airflow docker image:https://github.com/puckel/docker-airflow 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM