2021년/개발공부

apache Airflow

위지원 2021. 4. 22. 14:57

1.Airflow?

아래문서의 예제를 따라하려 한다. airflow는 아래 문서에 따르면 다음과 같이 설명해두었다. 

 

Get started developing workflows with Apache Airflow - Michał Karzyński

Apache Airflow is an open-source tool for orchestrating complex computational workflows and data processing pipelines. If you find yourself running cron task which execute ever longer scripts, or keeping a calendar of big data processing batch jobs then Ai

michal.karzynski.pl

 

" 복잡한 계산 작업흐름과 데이터 처리 파이프라인을  조직하기 위해 만든 오픈소스 도구 "

is an open-source tool for orchestrating complex computational workflows and data processing pipelines

 

  • 작업흐름은 DAG(Directed Acyclic Graph)로 설계됨
  • DAG는 Task로 구성됨
  • 각 Task는 Oerator class instance로 만듬 my_task = MyOperator()
  • DAG 시작 => Task Instance 생성, Airflow는 DB에 DAG RUN 항목 생성( 특정 DAG RUN 맥락에서 Task 실행 시 Task Instance 생성 )

 

*가상환경에서 파이썬 경로 잡아주고 시작할 것!!!!!!

 

2. Airflow설치 및 디비 초기화

위에 설명되어있듯이 DAG 시작 시 airflow는 db에 DAG run 항목을 생성해야하기때문에 db가 필요하다.

- 다른 db를 연결하지 않는이상 default는 sqlite(airflow는 전부 python으로 작성되어있음)

pip3 install airflow
mkdir airflow_home
export AIRFLOW_HOME=`pwd`/airflow_home
airflow version
airflow db init

 

그럼 요롷게 db가 생성된다.

 ⚙ jiwonwee@jiwon  ~/airflow  ls -l
-rw-r--r--  1 jiwonwee  staff  557056  4 22 14:28 airflow.db

 

3. 계정 생성 및 airflow 시작

아래 명령어를 이용하여 우선 계정을 생성해주어야한다.

airflow users create \
 --username admin \
 --firstname jiwon \
 --lastname wee \
 --role Admin \
 --password 123123 \
 --email upsdejiwon@gmail.com

 

이후, 웹서버를 실행시켜주면 로그인창이 뜬다. 위에서 만든 계정으로 로그인해주자

airflow webserver -p 8080

그럼 아래와같이 예제가 엄첨 많다.  하나를 작동시켜보았다.

airflow.cfg에서 False로 설정하면 예제를 불러오지않게 할 수 있다.

 

위에서 살펴보았던 것과 같이 DAG를 이용해 확인할 수 있다. 

 

4. Hello Wolrd 예제 실행

위 문서에서 주어진 예제를 돌려보았다. log를 보면 아래와같이 출력되는것을 확인할 수 있다.

mkdir dags
cd dags 
vi hell_world.py

airflow scheduler

 

REFERENCES

aldente0630.github.io/data-engineering/2018/06/17/developing-workflows-with-apache-airflow.html

haereeroo.tistory.com/6

pbj0812.tistory.com/389