成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

聊聊 Airflow 2.2.3 容器化安裝

開發 前端
安裝Docker可參考官方文檔[1],純凈系統,就沒必要卸載舊版本了,因為是云上平臺,為防止配置搞壞環境,你可以先提前進行快照。

上文簡單的了解了airflow的概念與使用場景,今天就通過Docker安裝一下Airflow,在使用中在深入的了解一下airflow有哪些具體的功能。

1Airflow容器化部署

阿里云的宿主機環境:

  • 操作系統: Ubuntu 20.04.3 LTS
  • 內核版本: Linux 5.4.0-91-generic

安裝docker

安裝Docker可參考官方文檔[1],純凈系統,就沒必要卸載舊版本了,因為是云上平臺,為防止配置搞壞環境,你可以先提前進行快照。

  1.  # 更新repo 
  2.  sudo apt-get update 
  3.  sudo apt-get install \ 
  4.     ca-certificates \ 
  5.     curl \ 
  6.     gnupg \ 
  7.     lsb-release 
  8.      
  9. # 添加docker gpg key 
  10. curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg 
  11.  
  12. # 設置docker stable倉庫地址 
  13. echo \ 
  14.   "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \ 
  15.   $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null 
  16.    
  17. # 查看可安裝的docker-ce版本 
  18. root@bigdata1:~# apt-cache madison docker-ce 
  19.  docker-ce | 5:20.10.12~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages 
  20.  docker-ce | 5:20.10.11~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages 
  21.  docker-ce | 5:20.10.10~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages 
  22.  docker-ce | 5:20.10.9~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages 
  23.  
  24. # 安裝命令格式 
  25. #sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io 
  26. # 安裝指定版本 
  27. sudo apt-get install docker-ce=5:20.10.12~3-0~ubuntu-focal docker-ce-cli=5:20.10.12~3-0~ubuntu-focal containerd.io 

優化Docker配置

  1.     "data-root""/var/lib/docker"
  2.     "exec-opts": [ 
  3.         "native.cgroupdriver=systemd" 
  4.     ], 
  5.     "registry-mirrors": [ 
  6.         "https://****.mirror.aliyuncs.com" #此處配置一些加速的地址,比如阿里云的等等... 
  7.     ], 
  8.     "storage-driver""overlay2"
  9.     "storage-opts": [ 
  10.         "overlay2.override_kernel_check=true" 
  11.     ], 
  12.     "log-driver""json-file"
  13.     "log-opts": { 
  14.         "max-size""100m"
  15.         "max-file""3" 
  16.     } 

配置開機自己

  1. systemctl daemon-reload 
  2. systemctl enable --now docker.service 

容器化安裝Airflow

數據庫選型

根據官網的說明,數據庫建議使用MySQL8+和postgresql 9.6+,在官方的docker-compose腳本[2]中使用是PostgreSQL,因此我們需要調整一下docker-compose.yml的內容

  1. --- 
  2. version: '3' 
  3. x-airflow-common: 
  4.   &airflow-common 
  5.   # In order to add custom dependencies or upgrade provider packages you can use your extended image. 
  6.   # Comment the image line, place your Dockerfile in the directory where you placed the docker-compose.yaml 
  7.   # and uncomment the "build" line below, Then run `docker-compose build` to build the images. 
  8.   image: ${AIRFLOW_IMAGE_NAME:-apache/airflow:2.2.3} 
  9.   # build: . 
  10.   environment: 
  11.     &airflow-common-env 
  12.     AIRFLOW__CORE__EXECUTOR: CeleryExecutor 
  13.     AIRFLOW__CORE__SQL_ALCHEMY_CONN: mysql+mysqldb://airflow:aaaa@mysql/airflow # 此處替換為mysql連接方式 
  14.     AIRFLOW__CELERY__RESULT_BACKEND: db+mysql://airflow:aaaa@mysql/airflow # 此處替換為mysql連接方式 
  15.     AIRFLOW__CELERY__BROKER_URL: redis://:xxxx@redis:6379/0 # 為保證安全,我們對redis開啟了認證,因此將此處xxxx替換為redis密碼 
  16.     AIRFLOW__CORE__FERNET_KEY: '' 
  17.     AIRFLOW__CORE__DAGS_ARE_PAUSED_AT_CREATION: 'true' 
  18.     AIRFLOW__CORE__LOAD_EXAMPLES: 'true' 
  19.     AIRFLOW__API__AUTH_BACKEND: 'airflow.api.auth.backend.basic_auth' 
  20.     _PIP_ADDITIONAL_REQUIREMENTS: ${_PIP_ADDITIONAL_REQUIREMENTS:-} 
  21.   volumes: 
  22.     - ./dags:/opt/airflow/dags 
  23.     - ./logs:/opt/airflow/logs 
  24.     - ./plugins:/opt/airflow/plugins 
  25.   user"${AIRFLOW_UID:-50000}:0" 
  26.   depends_on: 
  27.     &airflow-common-depends-on 
  28.     redis: 
  29.       condition: service_healthy 
  30.     mysql: # 此處修改為mysql service名稱 
  31.       condition: service_healthy 
  32.  
  33. services: 
  34.   mysql: 
  35.     image: mysql:8.0.27 # 修改為mysql最新版鏡像 
  36.     environment: 
  37.       MYSQL_ROOT_PASSWORD: bbbb # MySQL root賬號密碼 
  38.       MYSQL_USER: airflow 
  39.       MYSQL_PASSWORD: aaaa # airflow用戶的密碼 
  40.       MYSQL_DATABASE: airflow 
  41.     command: 
  42.       --default-authentication-plugin=mysql_native_password # 指定默認的認證插件 
  43.       --collation-server=utf8mb4_general_ci # 依據官方指定字符集 
  44.       --character-set-server=utf8mb4 # 依據官方指定字符編碼 
  45.     volumes: 
  46.       - /apps/airflow/mysqldata8:/var/lib/mysql # 持久化MySQL數據 
  47.       - /apps/airflow/my.cnf:/etc/my.cnf # 持久化MySQL配置文件 
  48.     healthcheck: 
  49.       test:  mysql --user=$$MYSQL_USER --password=$$MYSQL_PASSWORD -e 'SHOW DATABASES;' # healthcheck command 
  50.       interval: 5s 
  51.       retries: 5 
  52.     restart: always 
  53.  
  54.   redis: 
  55.     image: redis:6.2 
  56.     expose: 
  57.       - 6379 
  58.     command: redis-server --requirepass xxxx # redis-server開啟密碼認證 
  59.     healthcheck: 
  60.       test: ["CMD""redis-cli","-a","xxxx","ping"] # redis使用密碼進行healthcheck 
  61.       interval: 5s 
  62.       timeout: 30s 
  63.       retries: 50 
  64.     restart: always 
  65.  
  66.   airflow-webserver: 
  67.     <<: *airflow-common 
  68.     command: webserver 
  69.     ports: 
  70.       - 8080:8080 
  71.     healthcheck: 
  72.       test: ["CMD""curl""--fail""http://localhost:8080/health"
  73.       interval: 10s 
  74.       timeout: 10s 
  75.       retries: 5 
  76.     restart: always 
  77.     depends_on: 
  78.       <<: *airflow-common-depends-on 
  79.       airflow-init: 
  80.         condition: service_completed_successfully 
  81.  
  82.   airflow-scheduler: 
  83.     <<: *airflow-common 
  84.     command: scheduler 
  85.     healthcheck: 
  86.       test: ["CMD-SHELL"'airflow jobs check --job-type SchedulerJob --hostname "$${HOSTNAME}"'
  87.       interval: 10s 
  88.       timeout: 10s 
  89.       retries: 5 
  90.     restart: always 
  91.     depends_on: 
  92.       <<: *airflow-common-depends-on 
  93.       airflow-init: 
  94.         condition: service_completed_successfully 
  95.  
  96.   airflow-worker: 
  97.     <<: *airflow-common 
  98.     command: celery worker 
  99.     healthcheck: 
  100.       test: 
  101.         - "CMD-SHELL" 
  102.         - 'celery --app airflow.executors.celery_executor.app inspect ping -d "celery@$${HOSTNAME}"' 
  103.       interval: 10s 
  104.       timeout: 10s 
  105.       retries: 5 
  106.     environment: 
  107.       <<: *airflow-common-env 
  108.       # Required to handle warm shutdown of the celery workers properly 
  109.       # See https://airflow.apache.org/docs/docker-stack/entrypoint.html#signal-propagation 
  110.       DUMB_INIT_SETSID: "0" 
  111.     restart: always 
  112.     depends_on: 
  113.       <<: *airflow-common-depends-on 
  114.       airflow-init: 
  115.         condition: service_completed_successfully 
  116.  
  117.   airflow-triggerer: 
  118.     <<: *airflow-common 
  119.     command: triggerer 
  120.     healthcheck: 
  121.       test: ["CMD-SHELL"'airflow jobs check --job-type TriggererJob --hostname "$${HOSTNAME}"'
  122.       interval: 10s 
  123.       timeout: 10s 
  124.       retries: 5 
  125.     restart: always 
  126.     depends_on: 
  127.       <<: *airflow-common-depends-on 
  128.       airflow-init: 
  129.         condition: service_completed_successfully 
  130.  
  131.   airflow-init: 
  132.     <<: *airflow-common 
  133.     entrypoint: /bin/bash 
  134.     # yamllint disable rule:line-length 
  135.     command: 
  136.       - -c 
  137.       - | 
  138.         function ver() { 
  139.           printf "%04d%04d%04d%04d" $${1//./ } 
  140.         } 
  141.         airflow_version=$$(gosu airflow airflow version) 
  142.         airflow_version_comparable=$$(ver $${airflow_version}) 
  143.         min_airflow_version=2.2.0 
  144.         min_airflow_version_comparable=$$(ver $${min_airflow_version}) 
  145.         if (( airflow_version_comparable < min_airflow_version_comparable )); then 
  146.           echo 
  147.           echo -e "\033[1;31mERROR!!!: Too old Airflow version $${airflow_version}!\e[0m" 
  148.           echo "The minimum Airflow version supported: $${min_airflow_version}. Only use this or higher!" 
  149.           echo 
  150.           exit 1 
  151.         fi 
  152.         if [[ -z "${AIRFLOW_UID}" ]]; then 
  153.           echo 
  154.           echo -e "\033[1;33mWARNING!!!: AIRFLOW_UID not set!\e[0m" 
  155.           echo "If you are on Linux, you SHOULD follow the instructions below to set " 
  156.           echo "AIRFLOW_UID environment variable, otherwise files will be owned by root." 
  157.           echo "For other operating systems you can get rid of the warning with manually created .env file:" 
  158.           echo "    See: https://airflow.apache.org/docs/apache-airflow/stable/start/docker.html#setting-the-right-airflow-user" 
  159.           echo 
  160.         fi 
  161.         one_meg=1048576 
  162.         mem_available=$$(($$(getconf _PHYS_PAGES) * $$(getconf PAGE_SIZE) / one_meg)) 
  163.         cpus_available=$$(grep -cE 'cpu[0-9]+' /proc/stat) 
  164.         disk_available=$$(df / | tail -1 | awk '{print $$4}'
  165.         warning_resources="false" 
  166.         if (( mem_available < 4000 )) ; then 
  167.           echo 
  168.           echo -e "\033[1;33mWARNING!!!: Not enough memory available for Docker.\e[0m" 
  169.           echo "At least 4GB of memory required. You have $$(numfmt --to iec $$((mem_available * one_meg)))" 
  170.           echo 
  171.           warning_resources="true" 
  172.         fi 
  173.         if (( cpus_available < 2 )); then 
  174.           echo 
  175.           echo -e "\033[1;33mWARNING!!!: Not enough CPUS available for Docker.\e[0m" 
  176.           echo "At least 2 CPUs recommended. You have $${cpus_available}" 
  177.           echo 
  178.           warning_resources="true" 
  179.         fi 
  180.         if (( disk_available < one_meg * 10 )); then 
  181.           echo 
  182.           echo -e "\033[1;33mWARNING!!!: Not enough Disk space available for Docker.\e[0m" 
  183.           echo "At least 10 GBs recommended. You have $$(numfmt --to iec $$((disk_available * 1024 )))" 
  184.           echo 
  185.           warning_resources="true" 
  186.         fi 
  187.         if [[ $${warning_resources} == "true" ]]; then 
  188.           echo 
  189.           echo -e "\033[1;33mWARNING!!!: You have not enough resources to run Airflow (see above)!\e[0m" 
  190.           echo "Please follow the instructions to increase amount of resources available:" 
  191.           echo "   https://airflow.apache.org/docs/apache-airflow/stable/start/docker.html#before-you-begin" 
  192.           echo 
  193.         fi 
  194.         mkdir -p /sources/logs /sources/dags /sources/plugins 
  195.         chown -R "${AIRFLOW_UID}:0" /sources/{logs,dags,plugins} 
  196.         exec /entrypoint airflow version 
  197.     # yamllint enable rule:line-length 
  198.     environment: 
  199.       <<: *airflow-common-env 
  200.       _AIRFLOW_DB_UPGRADE: 'true' 
  201.       _AIRFLOW_WWW_USER_CREATE: 'true' 
  202.       _AIRFLOW_WWW_USER_USERNAME: ${_AIRFLOW_WWW_USER_USERNAME:-airflow} 
  203.       _AIRFLOW_WWW_USER_PASSWORD: ${_AIRFLOW_WWW_USER_PASSWORD:-airflow} 
  204.     user"0:0" 
  205.     volumes: 
  206.       - .:/sources 
  207.  
  208.   airflow-cli: 
  209.     <<: *airflow-common 
  210.     profiles: 
  211.       - debug 
  212.     environment: 
  213.       <<: *airflow-common-env 
  214.       CONNECTION_CHECK_MAX_COUNT: "0" 
  215.     # Workaround for entrypoint issue. See: https://github.com/apache/airflow/issues/16252 
  216.     command: 
  217.       - bash 
  218.       - -c 
  219.       - airflow 
  220.  
  221.   flower: 
  222.     <<: *airflow-common 
  223.     command: celery flower 
  224.     ports: 
  225.       - 5555:5555 
  226.     healthcheck: 
  227.       test: ["CMD""curl""--fail""http://localhost:5555/"
  228.       interval: 10s 
  229.       timeout: 10s 
  230.       retries: 5 
  231.     restart: always 
  232.     depends_on: 
  233.       <<: *airflow-common-depends-on 
  234.       airflow-init: 
  235.         condition: service_completed_successfully 

在官方docker-compose.yaml基礎上只修改了x-airflow-common,MySQL,Redis相關配置,接下來就應該啟動容器了,在啟動之前,需要創建幾個持久化目錄:

  1. mkdir -p ./dags ./logs ./plugins 
  2. echo -e "AIRFLOW_UID=$(id -u)" > .env # 注意,此處一定要保證AIRFLOW_UID是普通用戶的UID,且保證此用戶有創建這些持久化目錄的權限 

如果不是普通用戶,在運行容器的時候,會報錯,找不到airflow模塊

  1. docker-compose up airflow-init #初始化數據庫,以及創建表 
  2. docker-compose up -d #創建airflow容器 

當出現容器的狀態為unhealthy的時候,要通過docker inspect $container_name查看報錯的原因,至此airflow的安裝就已經完成了。

參考資料

[1]Install Docker Engine on Ubuntu: https://docs.docker.com/engine/install/ubuntu/

[2]官方docker-compose.yaml: https://airflow.apache.org/docs/apache-airflow/2.2.3/docker-compose.yaml

 

責任編輯:武曉燕 來源: 云原生生態圈
相關推薦

2024-05-09 09:55:08

2020-06-10 08:55:36

Docker容器工具

2022-01-05 19:34:18

AirflowCeleryMYSQL

2024-08-05 11:14:45

2020-07-14 07:27:48

容器IoCSpring

2023-04-28 08:43:46

2023-03-27 08:49:51

2022-03-04 08:45:11

Docker開源Linux

2023-07-03 09:59:00

并發編程并發容器

2023-11-28 07:55:05

Calico容器網絡

2019-01-09 13:20:28

GPU虛擬化應用

2023-09-11 07:25:52

2020-06-10 08:28:51

Kata容器I

2022-05-09 08:34:01

FeignhttpJava

2018-04-24 09:05:09

容器存儲接口

2022-01-19 08:01:13

Linuxdocker容器

2024-07-26 09:47:28

2021-09-14 13:25:23

容器pod僵尸進程

2017-07-04 13:37:57

調度工具Airflow開源

2021-08-11 10:50:35

AirFlow MaxCompute阿里云
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 欧美一区二区三区 | 成人精品国产免费网站 | 欧洲成人| 高清不卡毛片 | 福利在线观看 | 欧美日韩国产在线 | 国产在线观看一区二区三区 | 国产成人免费视频 | 一本色道精品久久一区二区三区 | 天天操夜夜操免费视频 | 亚洲精品久久久久久久久久吃药 | 欧美日韩亚洲一区二区 | 免费精品| 无码国模国产在线观看 | 最新av片| www.婷婷 | 国产婷婷色综合av蜜臀av | 免费一区二区三区 | 一二三区av | 国产精品久久久久aaaa九色 | 一级免费毛片 | 一级黄色毛片子 | av免费网址 | 日日骚av | 超碰97av| 男人久久天堂 | 国内毛片毛片毛片毛片 | 日日摸夜夜添夜夜添精品视频 | 国产一区三区在线 | 日本 欧美 三级 高清 视频 | 一级免费在线视频 | 另类在线 | 久久久精品视频免费看 | 国产精品久久久久久久免费大片 | 国产精成人| 久久九九99 | 国产激情片在线观看 | 九九久久精品 | 特黄小视频 | 网色| 亚洲高清一区二区三区 |