# 使用 Mesos 擴展(社區貢獻)
> 貢獻者:[@ImPerat0R\_](https://github.com/tssujt)、[@ThinkingChen](https://github.com/cdmikechen)
有兩種方法可以將 Airflow 作為 mesos 框架運行:
1. 想要直接在 mesos slaves 上運行 Airflow 任務,要求每個 mesos slave 安裝和配置 Airflow。
2. 在安裝了 Airflow 的 docker 容器內運行 Airflow 任務,該容器在 mesos slave 上運行。
## 任務直接在 mesos slave 上執行
`MesosExecutor`允許您在 Mesos 群集上調度 Airflow 任務。為此,您需要一個正在運行的 mesos 集群,并且必須執行以下步驟 -
1. 在可以運行 web server 和 scheduler 的 mesos slave 上安裝 Airflow,讓我們將其稱為“Airflow server”。
2. 在 Airflow server 上,從[mesos 下載](http://open.mesosphere.com/downloads/mesos/)安裝 mesos python eggs。
3. 在 Airflow server 上,使用可以被所有 mesos slave 訪問的數據庫(例如 mysql),并在`airflow.cfg`添加配置。
4. 將您的`airflow.cfg`里 executor 的參數指定為*MesosExecutor*,并提供相關的 Mesos 設置。
5. 在所有 mesos slave 上,安裝 Airflow。 從 Airflow 服務器復制`airflow.cfg` (以便它使用相同的 sqlalchemy 連接)。
6. 在所有 mesos slave 上,運行以下服務日志:
```py
airflow serve_logs
```
7. 在 Airflow server 上,如果想要開始在 mesos 上處理/調度 DAG,請運行:
```py
airflow scheduler -p
```
注意:我們需要-p 參數來挑選 DAG。
您現在可以在 mesos UI 中查看 Airflow 框架和相應的任務。Airflow 任務的日志可以像往常一樣在 Airflow UI 中查看。
有關 mesos 的更多信息,請參閱[mesos 文檔](http://mesos.apache.org/documentation/latest/)。 有關 MesosExecutor 的任何疑問/錯誤,請聯系[@kapil-malik](https://github.com/kapil-malik)。
## 在 mesos slave 上的容器中執行的任務
[此 gist](https://gist.github.com/sebradloff/f158874e615bda0005c6f4577b20036e)包含實現以下所需的所有文件和配置更改:
1. 使用安裝了 mesos python eggs 的軟件環境創建一個 dockerized 版本的 Airflow。
> 我們建議利用 docker 的多階段構建來實現這一目標。我們有一個 Dockerfile 定義從源(Dockerfile-mesos)構建特定版本的 mesos,以便創建 python eggs。在 Airflow Dockerfile(Dockerfile-airflow)中,我們從 mesos 鏡像中復制 python eggs。
2. 在`airflow.cfg`創建一個 mesos 配置塊。
> 配置塊保持與默認 Airflow 配置(default_airflow.cfg)相同,但添加了一個選項`docker_image_slave`。 這應該設置為您希望 mesos 在運行 Airflow 任務時使用的鏡像的名稱。確保您具有適用于您的 mesos 主服務器的 DNS 記錄的正確配置以及任何類型的授權(如果存在)。
3. 更改`airflow.cfg`以將執行程序參數指向 MesosExecutor(executor = SequentialExecutor)。
4. 確保您的 mesos slave 可以訪問您`docker_image_slave`的 docker 存儲庫。
> [mesos 文檔中提供了相關說明。](https://mesos.readthedocs.io/en/latest/docker-containerizer/)
其余部分取決于您以及您希望如何使用 dockerized Airflow 配置。