Docker를 이용하여 airflow설치
airflow 에서 docker-compose.yaml을 가져온다
curl -LfO 'https://airflow.apache.org/docs/apache-airflow/2.7.2/docker-compose.yaml'
를 이용하여 가져오든 다운로드 받든 상관 없다.- 사용할 공유 디렉토리 생성
mkdir -p ./dags ./logs ./plugins ./config
를 이용하여 생성하든, 하나 씩 만들든 상관 없다
- 사용할 env 파일 생성해준다
- 공홈에서 다운 받은 yaml을 보면 설정할 수 있는 변수 값들이 있다. 필요에 따라 설정하자
- 초기 설정
docker compose up airflow-init
를 이용하여 작성한 변수 값 등을 적용한 airflow 초기화
- 설치 검증
docker compose run airflow-worker airflow info
를 이용하여 설치 검증
- 실행
docker compose up -d
를 이용하여 도커 실행- -d를 붙인 이유는 background로 실행시키기 위해 추가함
직접설치
설치하고자 하는 airflow의 버전에 맞춰 python 설치 후 아래 명령어 실행
sqlite도 필요하니 그것도 설치해준다.
Quick Start를 따라하면 된다.
# sqlite도 경로 설정해준다.
export LD_LIBRARY_PATH=$sqlite_HOME/lib:$LD_LIBRARY_PATH
export AIRFLOW_HOME=~/airflow
AIRFLOW_VERSION=2.7.2
# Python 버전 설정
# 아래와 같이 shell명령어 사용하지 말고, 직접 삽입해도 됨.
PYTHON_VERSION="$(python --version | cut -d " " -f 2 | cut -d "." -f 1-2)"
# 아래와 같이 constraint명령어를 성성
# E.g
# airflow 2.7.2 버전은 Python 3.8, 3.9, 3.10, 3.11 을 지원한
# https://raw.githubusercontent.com/apache/airflow/constraints-2.7.2/constraints-3.8.txt
CONSTRAINT_URL="https://raw.githubusercontent.com/apache/airflow/constraints-${AIRFLOW_VERSION}/constraints-${PYTHON_VERSION}.txt"
pip install "apache-airflow==${AIRFLOW_VERSION}" --constraint "${CONSTRAINT_URL}"
# 유저 생성, 초기
airflow db migrate
airflow users create \
--username admin \ # 접속 id라고 보면된다
--firstname Peter \
--lastname Parker \
--role Admin \ # 역할
--password admin \ # 접속 비밀번호
--email spiderman@superhero.org
# 실행
airflow webserver --port 8080 -D
airflow scheduler -D
에러
PermissionError: [Errno 13] Permission denied: 'airflow'
self._execute_child(args, executable, preexec_fn, close_fds,
File "/home/airflow/python_env/lib/python3.9/subprocess.py", line 1837, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
PermissionError: [Errno 13] Permission denied: 'airflow'
raise child_exception_type(errno_num, err_msg, err_filename)
PermissionError: [Errno 13] Permission denied: 'airflow'
만약 위와 같은 에러가 발생하면 권한 문제긴 하지만
ln -s airflow경로 /usr/bin/airflow
와 같이 링크를 걸지 않아 발생한 것 일 수 있다.
[ Reference ]
개인적으로 공부한 내용 포스팅 중
잘못된 정보는 지적해주시면 좋겠습니다!