简体   繁体   English

Airflow 网络服务器无法识别 docker-compose 中的 Airflow 调度程序

[英]Airflow webserver can't recognize Airflow Scheduler in docker-compose

version: "3.7"
services:
    postgres:
        image: "postgres:13"
        container_name: "postgres"
        environment:
          - POSTGRES_USER=airflow
          - POSTGRES_PASSWORD=airflow
          - POSTGRES_DB=airflow
        ports:
        - "5431:5431"
        volumes:
        - ./data/postgres:/var/lib/postgresql/data


   webserver:
        image: jh111/airflow-hadoop-spark:test
        restart: always
        networks:
            - default_net
        environment:
            - AIRFLOW_HOME=/home/airflow
            - AIRFLOW__CORE__LOAD_EXAMPLES=False
            - AIRFLOW__CORE__dags_folder=/home/airflow/dags
        volumes:
            - ../dags:/home/airflow/dags #DAG folder
        ports:
            - "7777:7777"
        depends_on:
            - postgres
        command: bash -c "airflow webserver --port 7777"
    scheduler:
        image: jh111/airflow-hadoop-spark:test
        restart: always
        networks:
            - default_net
        environment:
            - AIRFLOW_HOME=/home/airflow
            - AIRFLOW__CORE__LOAD_EXAMPLES=False
            - AIRFLOW__CORE__dags_folder=/home/airflow/dags
            - AIRFLOW_WEBSERVER_HOST=webserver
        volumes:
            - ../dags:/home/airflow/dags #DAG folder
        depends_on:
            - postgres
        command: bash -c "airflow scheduler"

networks:
    default_net:

I checked that airflow webserver and scheduler is running on the server.我检查了 airflow 网络服务器和调度程序正在服务器上运行。 However, when I get into webserver UI, I cannot find any dags in the web UI even if I have dag in the folder.但是,当我进入网络服务器 UI 时,即使文件夹中有 dag,我也无法在 web UI 中找到任何 dag。

The scheduler does not appear to be running.调度程序似乎没有运行。

How can I solve this problem?我怎么解决这个问题?

The default airflow executor is SequentialExecutor , with this executor the airflow scheduler and webserver should be running in the same host, which means the same docker image, and they use sqlite as a database (the postgres service which you created is not used, and AIRFLOW_WEBSERVER_HOST is not an airflow config). The default airflow executor is SequentialExecutor , with this executor the airflow scheduler and webserver should be running in the same host, which means the same docker image, and they use sqlite as a database (the postgres service which you created is not used, and AIRFLOW_WEBSERVER_HOST不是 airflow 配置)。

To connect airflow to postgres server and to decouple airflow webserver and scheduler, you can use LocalExecutor , in this case you can run each component in a separate container, and they will interact with the database to communicate between each other.要将 airflow 连接到 postgres 服务器并解耦 airflow webserver 和调度程序,您可以使用LocalExecutor ,在这种情况下您可以在单独的容器中运行每个组件,它们将与数据库交互以相互通信。

You can do that by adding this two environment variables to the webserver and scheduler services:您可以通过将这两个环境变量添加到webserverscheduler服务来做到这一点:

AIRFLOW__CORE__SQL_ALCHEMY_CONN=postgresql+psycopg2://airflow:airflow@postgres/airflow
AIRFLOW__CORE__EXECUTOR=LocalExecutor

You can check this project , it can help you to create and run a custom airflow image with LocalExecutor .您可以查看这个项目,它可以帮助您使用 LocalExecutor 创建和运行自定义LocalExecutor映像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM