Airflow 테스트를 위해

Docker 로 Airflow 설치하는 방법을 설명함

 

Centos 7 을 사용하였고, Airflow 는 Sequential Executor 를 사용함.

 

 

 

Centos 7 Docker Image : https://eyeballs.tistory.com/543

 

위 Docker Image 를 만들어준 다음, 아래 명령어로 container 하나 띄움

 

$ docker run --name airflow -p 8080:8080 --privileged -d mycentos:7 init

 

아래 명령어로 docker container 들어가서 필요한 것들 설치 진행

$ docker exec -it airflow bash
$ yum upgrade -y
$ yum install python3 wget vim sudo gcc make -y

 

아래 명령어로 sqlite 최신 버전 설치 [참고]

( sqlite 다운로드 페이지 :https://www.sqlite.org/download.html )

만약 sqlite3 --version 이 3.7.17

$ cd /opt
$ wget https://www.sqlite.org/2023/sqlite-autoconf-3430100.tar.gz
$ tar -xzf sqlite-autoconf-3430100.tar.gz 
$ cd sqlite-autoconf-3430100
$ make
$ make install

위처럼 sqlite3 를 최신 버전으로 업그레이드 하는 경우는

pip 로 airflow 설치시 3.8.3 이상의 sqlite 버전을 필요로 하기 때문.

can't find new sqlite version? (SQLite 3.8.3 or later is required (found 3.7.17))

만약 sqlite3 버전이 3.8.3 이상이라면 위와 같이 최신 버전으로 업그레이드 하지 않아도 됨

 

 

airflow 라는 사용자를 만들어서 sudo 권한 부여

$ useradd airflow
$ usermod -aG wheel airflow

 

아래 명령어로 /etc/sudoers 편집 진행

아래 주석 처리되어있는 부분의 주석을 해제

$ visudo
전) #%wheel  ALL=(ALL)       NOPASSWD: ALL
후) %wheel  ALL=(ALL)       NOPASSWD: ALL

 

아래 명령어로 사용자 airflow 로 접근

지금부터 나오는 명령어들은 모두 airflow 계정으로 진행

$ su - airflow

 

아래 명령어로 pip3 업그레이드 진행 및 setuptool 설치

$ sudo -H pip3 install --upgrade --ignore-installed pip setuptools

 

 

아래 명령어로 airflow home 을 만듦

$ mkdir ~/airflow
$ export AIRFLOW_HOME=~/airflow

 

아래 명령어로 sqlite3 가 최신 버전(>3.7.17)으로 업그레이드 되었는지 확인

$ pyhon3
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.7.17'
$ export LD_LIBRARY_PATH="/usr/local/lib"
$ python3
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.43.1'

 

아래 명령어로 airflow 설치

나는 2.2.2를 설치하고 싶어서 직접 2.2.2를 넣었으니, 원하는 버전을 넣으면 됨.

$ AIRFLOW_VERSION=2.2.2
$ PYTHON_VERSION="$(python3 --version | cut -d " " -f 2 | cut -d "." -f 1-2)"
$ CONSTRAINT_URL=" https://raw.githubusercontent.com/apache/airflow/constraints-$ {AIRFLOW_VERSION}/constraints-${PYTHON_VERSION}.txt"
$ pip3 install "apache-airflow==${AIRFLOW_VERSION}" --constraint "${CONSTRAINT_URL}"

 

아래 명령어로 apache airflow 의 admin 유저 생성

$ airflow users  create --role Admin --username airflow --email airflow --firstname airflow --lastname airflow --password airflow

 

아래 명령어로 apache airflow 를 Sequential Executor 모드로 실행

$ airflow standalone

 

잠시 후 웹브라우저에서 localhost:8080 에 접근하여 WebUI 가 뜨는지 확인

id, pw 는 각각 airflow, airflow 로 접근 가능

 

dags 위치는 airflow.cfg 에서 찾아볼 수 있음 ($AIRFLOW_HOME/dags)

$ cat $AIRFLOW_HOME/airflow.cfg | grep dags_folder

 

 

 

 

 

 

 

참고

https://airflow.apache.org/docs/apache-airflow/2.2.2/start/local.html

https://www.webdesignsun.com/insights/upgrading-sqlite-on-centos/

https://musclebear.tistory.com/131

https://sun2day.tistory.com/216

 

+ Recent posts