Airflow 2.5.0配置Dask调度器/Worker后UI提示调度器未运行
Airflow 2.5.0 替换为Dask Executor后调度器异常的修复方案
核心问题分析
- 遗漏Airflow自身调度器:你错误地用Dask调度器替代了Airflow调度器——Airflow的
DaskExecutor逻辑是让Airflow调度器将任务提交给Dask集群执行,Airflow自身的scheduler进程必须保留,UI提示的心跳缺失就是因为这个核心进程未启动。 - 残留无用配置:配置中仍保留
AIRFLOW__CELERY__RESULT_BACKEND、AIRFLOW__CELERY__BROKER_URL等Celery相关变量,使用DaskExecutor时这些配置完全无效。 - 数据库连接错误:
mysql+mysqlconnector://airflow:localhost@3306/airflow中的localhost指向容器自身,若MySQL部署在宿主机或其他容器,该地址无法建立连接。 - Dask服务配置冗余:Dask调度器/Worker无需继承Airflow的环境变量和卷,且
dask-worker服务存在YAML缩进语法错误。 - 缺少Dask依赖:Airflow容器需安装
dask和distributed库才能与Dask集群通信。
修复后的Docker Compose配置
# Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. The ASF licenses this file # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. # # Airflow 2.5.0 with DaskExecutor configuration --- version: '3' x-airflow-common: &airflow-common image: ${AIRFLOW_IMAGE_NAME:-apache/airflow:2.5.0} environment: &airflow-common-env AIRFLOW__CORE__EXECUTOR: DaskExecutor # 修正数据库连接:替换为实际MySQL地址(宿主机IP/容器服务名)和密码 AIRFLOW__DATABASE__SQL_ALCHEMY_CONN: mysql+mysqlconnector://airflow:your_mysql_password@your_mysql_host:3306/airflow AIRFLOW__CORE__SQL_ALCHEMY_CONN: mysql+mysqlconnector://airflow:your_mysql_password@your_mysql_host:3306/airflow # 配置Dask集群地址 AIRFLOW__DASK__CLUSTER_ADDRESS: tcp://127.0.0.1:8786 AIRFLOW__CORE__FERNET_KEY: '' AIRFLOW__CORE__DAGS_ARE_PAUSED_AT_CREATION: 'true' AIRFLOW__CORE__LOAD_EXAMPLES: 'true' AIRFLOW__API__AUTH_BACKENDS: 'airflow.api.auth.backend.basic_auth' # 添加Dask依赖库 _PIP_ADDITIONAL_REQUIREMENTS: ${_PIP_ADDITIONAL_REQUIREMENTS:- mysql mysql-connector-python dask distributed} volumes: - ./dags:/opt/airflow/dags - ./logs:/opt/airflow/logs - ./plugins:/opt/airflow/plugins user: "${AIRFLOW_UID:-50000}:0" depends_on: &airflow-common-depends-on redis: condition: service_healthy # 若MySQL为容器部署,在此添加MySQL服务的依赖 services: redis: image: redis:latest network_mode: "host" expose: - 6379 healthcheck: test: ["CMD", "redis-cli", "ping"] interval: 5s timeout: 30s retries: 50 restart: always airflow-webserver: <<: *airflow-common network_mode: "host" command: webserver healthcheck: test: ["CMD", "curl", "--fail", "http://localhost:8080/health"] interval: 10s timeout: 10s retries: 5 restart: always depends_on: <<: *airflow-common-depends-on airflow-init: condition: service_completed_successfully # 新增Airflow自身调度器进程,必须保留 airflow-scheduler: <<: *airflow-common network_mode: "host" command: scheduler healthcheck: test: ["CMD-SHELL", 'airflow jobs check --job-type SchedulerJob --hostname 127.0.0.1'] interval: 10s timeout: 10s retries: 5 restart: always depends_on: <<: *airflow-common-depends-on airflow-init: condition: service_completed_successfully # 简化Dask调度器配置 dask-scheduler: image: daskdev/dask:latest network_mode: "host" command: dask-scheduler restart: always # 修复缩进错误,简化Dask Worker配置 dask-worker: image: daskdev/dask:latest network_mode: "host" command: ["dask worker", "tcp://127.0.0.1:8786"] restart: always depends_on: - dask-scheduler airflow-triggerer: <<: *airflow-common network_mode: "host" command: triggerer healthcheck: test: ["CMD-SHELL", 'airflow jobs check --job-type TriggererJob --hostname 127.0.0.1'] interval: 10s timeout: 10s retries: 5 restart: always depends_on: <<: *airflow-common-depends-on airflow-init: condition: service_completed_successfully airflow-init: <<: *airflow-common network_mode: "host" entrypoint: /bin/bash command: - -c - | function ver() { printf "%04d%04d%04d%04d" $${1//./ } } airflow_version=$$(AIRFLOW__LOGGING__LOGGING_LEVEL=INFO && gosu airflow airflow version) airflow_version_comparable=$$(ver $${airflow_version}) min_airflow_version=2.2.0 min_airflow_version_comparable=$$(ver $${min_airflow_version}) if (( airflow_version_comparable < min_airflow_version_comparable )); then echo echo -e "\033[1;31mERROR!!!: Too old Airflow version $${airflow_version}!\e[0m" echo "The minimum Airflow version supported: $${min_airflow_version}. Only use this or higher!" echo exit 1 fi if [[ -z "${AIRFLOW_UID}" ]]; then echo echo -e "\033[1;33mWARNING!!!: AIRFLOW_UID not set!\e[0m" echo "If you are on Linux, you SHOULD follow the instructions below to set " echo "AIRFLOW_UID environment variable, otherwise files will be owned by root." echo "For other operating systems you can get rid of the warning with manually created .env file:" echo " See: https://airflow.apache.org/docs/apache-airflow/stable/howto/docker-compose/index.html#setting-the-right-airflow-user" echo fi one_meg=1048576 mem_available=$$(( $$(getconf _PHYS_PAGES) * $$(getconf PAGE_SIZE) / one_meg )) cpus_available=$$(grep -cE 'cpu[0-9]+' /proc/stat) disk_available=$$(df / | tail -1 | awk '{print $$4}') warning_resources="false" if (( mem_available < 4000 )) ; then echo echo -e "\033[1;33mWARNING!!!: Not enough memory available for Docker.\e[0m" echo "At least 4GB of memory required. You have $$(numfmt --to iec $$((mem_available * one_meg)))" echo warning_resources="true" fi if (( cpus_available < 2 )); then echo echo -e "\033[1;33mWARNING!!!: Not enough CPUS available for Docker.\e[0m" echo "At least 2 CPUs recommended. You have $${cpus_available}" echo warning_resources="true" fi if (( disk_available < one_meg * 10 )); then echo echo -e "\033[1;33mWARNING!!!: Not enough Disk space available for Docker.\e[0m" echo "At least 10 GBs recommended. You have $$(numfmt --to iec $$((disk_available * 1024 )))" echo warning_resources="true" fi if [[ $${warning_resources} == "true" ]]; then echo echo -e "\033[1;33mWARNING!!!: You have not enough resources to run Airflow (see above)!\e[0m" echo "Please follow the instructions to increase amount of resources available:" echo " https://airflow.apache.org/docs/apache-airflow/stable/howto/docker-compose/index.html#before-you-begin" echo fi mkdir -p /sources/logs /sources/dags /sources/plugins chown -R "${AIRFLOW_UID}:0" /sources/{logs,dags,plugins} exec /entrypoint airflow version environment: <<: *airflow-common-env _AIRFLOW_DB_UPGRADE: 'true' _AIRFLOW_WWW_USER_CREATE: 'true' _AIRFLOW_WWW_USER_USERNAME: ${_AIRFLOW_WWW_USER_USERNAME:-airflow} _AIRFLOW_WWW_USER_PASSWORD: ${_AIRFLOW_WWW_USER_PASSWORD:-airflow} _PIP_ADDITIONAL_REQUIREMENTS: '' user: "0:0" volumes: - .:/sources airflow-cli: <<: *airflow-common profiles: - debug environment: <<: *airflow-common-env CONNECTION_CHECK_MAX_COUNT: "0" command: - bash - -c - airflow
额外操作步骤
- 将配置中的
your_mysql_password和your_mysql_host替换为实际的MySQL密码和地址 - 若MySQL为容器部署,需在
services节点下添加MySQL服务,并在airflow-common的depends_on中补充依赖 - 启动前清理旧容器和卷:
docker compose down -v,再执行docker compose up -d
内容的提问来源于stack exchange,提问作者s misra
相关产品推荐
相关产品推荐

