-
DockerHub - https://hub.docker.com/r/bitnami/airflow/
Bitnami에서 제공하는 AirFlow
-
docker-compose의 버전을 올려야 하고, apt 설치로 불가능하다.
-
컨테이너 생성을 두 번에 나눠서 하므로 번거롭다.
-
컨테이너가 너무 많이 생성된다.
docker-compose.yml 다운로드
$ curl -LfO \
'https://github.com/bitnami/bitnami-docker-airflow/blob/master/2/debian-11/docker-compose.yml'
docker-compose.yml 수정
-
Docker 이미지 경로 - 사설 저장소를 사용하는 경우
-
공유 볼륨 경로 - 공유 볼륨을 다른 경로에 설정하려는 경우
-
연결 포트 변경 - 변경이 필요한 경우
-
Jupyter Notebook 설정 추가
-
AirFlow Webserver - 8080:8080
-
Jupyter Notebook - 8888:8888
-
공유 볼륨의 컨테이너 내부 경로
-
데이터베이스와 redis의 비밀번호
$ vi docker-compose.yaml
version: '2'
services:
### 추가 부분 시작 ###
jupyter:
image: jupyter/base-notebook:latest
volumes:
- ./dags:/usr/local/airflow/dags
ports:
- "8888:8888"
command: "start-notebook.sh \
--NotebookApp.password='sha1:b70a055565b1:854e3f96f91c51cc0c91da371ea5dfbf7c1a61a1' \
--sudo mkdir /usr/local/airflow/dags"
### 추가 부분 끝 ###
postgresql:
$ vi docker-compose.yaml
version: '2'
services:
jupyter:
image: 사설저장소경로:포트/jupyter/base-notebook:latest
## 중략 ##
postgresql:
image: 사설저장소경로:포트/bitnami/postgresql:10
## 중략 ##
redis:
image: 사설저장소경로:포트/bitnami/redis:6.0
## 중략 ##
airflow-scheduler:
image: 사설저장소경로:포트/bitnami/airflow-scheduler:2.3.2
## 중략 ##
airflow-worker:
image: 사설저장소경로:포트/bitnami/airflow-worker:2.3.2
## 중략 ##
airflow:
image: 사설저장소경로:포트/bitnami/airflow:2.3.2
$ vi docker-compose.yaml
version: '2'
services:
## 중략 ##
postgresql:
## 중략 ##
volumes:
- ./postgresql_data:/bitnami/postgresql
## 중략 ##
redis:
## 중략 ##
volumes:
- ./redis_data:/bitnami
## 중략 ##
airflow:
## 중략 ##
volumes:
- ./dags:/opt/bitnami/airflow/dags
volumes: # 아래 두개 남기고 나머지는 삭제
postgresql_data:
driver: local
redis_data:
driver: local
$ vi docker-compose.yaml
## 중략 ##
services:
jupyter:
## 중략 ##
ports: # 8888: 부분을 변경할포트: 형태로 변경한다.
- '8888:8888'
## 중략 ##
airflow:
## 중략 ##
ports: # 8080: 부분을 변경할포트: 형태로 변경한다.
- '8080:8080'
$ vi docker-compose.yaml
## 중략 ##
services:
## 중략 ##
airflow-scheduler:
## 중략 ##
environment:
## 중략 ##
- AIRFLOW__WEBSERVER__DEFAULT_UI_TIMEZONE=Asia/Seoul
- AIRFLOW__CORE__DEFAULT_TIMEZONE=Asia/Seoul
- TZ=Asia/Seoul
## 중략 ##
airflow-worker:
## 중략 ##
environment:
## 중략 ##
- AIRFLOW__WEBSERVER__DEFAULT_UI_TIMEZONE=Asia/Seoul
- AIRFLOW__CORE__DEFAULT_TIMEZONE=Asia/Seoul
- TZ=Asia/Seoul
## 중략 ##
airflow:
## 중략 ##
environment:
## 중략 ##
- AIRFLOW__WEBSERVER__DEFAULT_UI_TIMEZONE=Asia/Seoul
- AIRFLOW__CORE__DEFAULT_TIMEZONE=Asia/Seoul
- TZ=Asia/Seoul
## 중략 ##
airflow 컨테이너 실행
$ docker-compose up -d
$ docker ps
CONTAINER ID IMAGE NAMES
1d03ee0b176c jupyter/base-notebook:latest airflow_jupyter_1
09972e13486b bitnami/airflow-worker:2 airflow_airflow-worker_1
a27cc5e5a207 bitnami/airflow-scheduler:2 airflow_airflow-scheduler_1
d955e359667c bitnami/postgresql:10 airflow_postgresql_1
127b77b23a78 bitnami/airflow:2 airflow_airflow_1
f58e8a56f7af bitnami/redis:6.0 airflow_redis_1
redis 오류 해결
$ docker logs airflow_redis_1
## 중략 ##
mkdir: cannot create directory '/bitnami/redis': Permission denied when starting the Docker
$ chmod 677 ./redis_data
$ sudo umount /mnt/d
$ sudo mount -t drvfs D: /mnt/d -o metadata
Scheduler, Worker 오류 해결
$ docker logs airflow_airflow-scheduler_1 # 또는 airflow_airflow-worker_1
## 중략 ##
timeout reached before the port went into state "inuse"
$ vi docker-compose.yaml
## 중략 ##
airflow-scheduler:
## 중략 ##
environment:
## 중략 ##
- AIRFLOW_WEBSERVER_HOST=airflow
airflow-worker:
## 중략 ##
environment:
## 중략 ##
- AIRFLOW_WEBSERVER_HOST=airflow
timeout reached before the port went into state "inuse" - githubmemory
timeout reached before the port went into state "inuse"
githubmemory.com
DAG 실행시 로그 출력 오류
*** Log file does not exist:
/opt/bitnami/airflow/logs/tutorial/hello_task/2021-11-05T06:36:04.378967+00:00/1.log
*** Fetching from:
http://ac8721e912e5:8793/log/tutorial/hello_task/2021-11-05T06:36:04.378967+00:00/1.log
*** !!!! Please make sure that all your Airflow components
(e.g. schedulers, webservers and workers)
have the same 'secret_key' configured in 'webserver' section !!!!!
****** See more at
https://airflow.apache.org/docs/apache-airflow/stable/configurations-ref.html#secret-key
****** Failed to fetch log file from worker.
403 Client Error: FORBIDDEN for url:
http://ac8721e912e5:8793/log/tutorial/hello_task/2021-11-05T06:36:04.378967+00:00/1.log
For more information check: https://httpstatuses.com/403
airflow.cfg 설정 파일의 webserver 구역의 secret_key 값을 동일하게 적용해야 한다.
해당 설명은 다음을 참고한다.
Configuration Reference — Airflow Documentation
airflow.apache.org
환경 변수는 AIRFLOW__WEBSERVER__SECRET_KEY이다.
$ python -c 'import os; print(os.urandom(16))'
b'\xd0;G\xd1g()\xacU\x0ed\xd7\xban\xc8\xb0'
docker-compose.yml의 airflow 관련 컨테이너에 AIRFLOW__WEBSERVER__SECRET_KEY 환경 변수를 추가한다.
생성 된 문자열을 복사해서 해당 환경 변수의 값으로 전달한다.
$ vi docker-compose.yaml
## 중략 ##
services:
## 중략 ##
airflow-scheduler:
## 중략 ##
environment:
## 중략 ##
# 생성한 문자열 붙여넣기
- AIRFLOW__WEBSERVER__SECRET_KEY=b'\xd0;G\xd1g()\xacU\x0ed\xd7\xban\xc8\xb0'
## 중략 ##
airflow-worker:
## 중략 ##
environment:
## 중략 ##
# 생성한 문자열 붙여넣기
- AIRFLOW__WEBSERVER__SECRET_KEY=b'\xd0;G\xd1g()\xacU\x0ed\xd7\xban\xc8\xb0'
## 중략 ##
airflow:
## 중략 ##
environment:
## 중략 ##
# 생성한 문자열 붙여넣기
- AIRFLOW__WEBSERVER__SECRET_KEY=b'\xd0;G\xd1g()\xacU\x0ed\xd7\xban\xc8\xb0'
## 중략 ##
아래 사이트를 참고했다.
In airflow's configuration file `airflow.cfg` what is the `secret_key`, and do I have to set it?
As a comment above the value, it says # Secret key used to run your flask app, but that doesn't tell me much. Currently it is set to secret_key = temporary_key, but that seems unsafe. We have set up
serverfault.com
AirFlow CPU 과점유 현상 해결
$ docker exec -it airflow-airflow_worker_1 /bin/bash
# 또는 docker exec -it airflow-airflow_scheduler_1 /bin/bash
$ cat /opt/bitnami/airflow/airflow.cfg
scheduler_heartbeat_sec = 5
min_file_process_interval = 0
max_threads = 2
scheduler_heartbeat_sec = 5
min_file_process_interval = 30 # 0에서 30으로 변경
# max_threads Defrecated (없어짐)
$ vi docker-compose.yaml
## 중략 ##
services:
## 중략 ##
airflow-scheduler:
## 중략 ##
environment:
## 중략 ##
- AIRFLOW__SCHEDULER__SCHEDULER_HEARTBEAT_SEC=60
- AIRFLOW__SCHEDULER__MIN_FILE_PROCESS_INTERVAL=60
## 중략 ##
airflow-worker:
## 중략 ##
environment:
## 중략 ##
- AIRFLOW__SCHEDULER__SCHEDULER_HEARTBEAT_SEC=60
- AIRFLOW__SCHEDULER__MIN_FILE_PROCESS_INTERVAL=60
## 중략 ##
airflow:
## 중략 ##
environment:
## 중략 ##
- AIRFLOW__SCHEDULER__SCHEDULER_HEARTBEAT_SEC=60
- AIRFLOW__SCHEDULER__MIN_FILE_PROCESS_INTERVAL=60
## 중략 ##
AirFlow 웹서버 접속


Jupyter Notebook 접속


'::: IT인터넷 :::' 카테고리의 다른 글
Docker로 MongoDB 설정하기 (0) | 2022.03.24 |
---|---|
AirFlow Webserver에 SSL 적용하기 (0) | 2022.03.21 |
Docker로 AirFlow 설정하기 (Apache) (114) | 2022.03.14 |
AirFlow 소개와 구조 (2) | 2022.03.10 |
Docker로 PostgreSQL 사용하기 (0) | 2022.03.07 |