๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Airflow

Mac Airflow local ์„ค์น˜

by forestlim 2022. 5. 14.
728x90
๋ฐ˜์‘ํ˜•

๐Ÿ“Œ ๋กœ์ปฌ ํ™˜๊ฒฝ์—์„œ Airflow ์„ค์น˜ํ•˜๊ธฐ

 

1) ์ผ๋‹จ airflow ์„ค์น˜ํ•  ๊ฐ€์ƒํ™˜๊ฒฝ์„ ์„ธํŒ…ํ•ด์ค€๋‹ค. ๋‚˜๊ฐ™์€ ๊ฒฝ์šฐ python venv ๊ฐ€์ƒํ™˜๊ฒฝ์œผ๋กœ ์ƒ์„ฑํ–ˆ๋‹ค.

$ python3 -m venv ~/{directory_name}/{myenv}

 

2) airflow์˜ ํ™ˆ ๋””๋ ‰ํ† ๋ฆฌ ๋””ํดํŠธ๊ฐ’์€ ~/airflow์ด๋‹ค. 

๋”ฐ๋ผ์„œ airflow๋ฅผ ๋‹ค๋ฅธ ๋””๋ ‰ํ† ๋ฆฌ ์•ˆ์—์„œ ์‹คํ–‰์‹œํ‚ค๊ณ  ์‹ถ์œผ๋ฉด ํ™˜๊ฒฝ๋ณ€์ˆ˜๋ฅผ ์„ธํŒ…ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค.

$ export airflow=~/{directory_name}/airflow

๋‚˜๊ฐ™์€ ๊ฒฝ์šฐ airflow_test ๋ผ๋Š” ๋””๋ ‰ํ† ๋ฆฌ ํ•˜์œ„์—์„œ airflow ๋ฅผ ์‹คํ–‰์‹œ์ผฐ๋‹ค.

 

3) ๊ฐ€์ƒํ™˜๊ฒฝ ํ™œ์„ฑํ™”

$ source {myenv}/bin/activate

 

4) airflow ์„ค์น˜
(๊ณต์‹ document: https://airflow.apache.org/docs/apache-airflow/2.3.0/installation/installing-from-pypi.html)

$ pip install "apache-airflow[celery]==2.3.0" --constraint "https://raw.githubusercontent.com/apache/airflow/constraints-2.3.0/constraints-3.7.txt"


5) DB ์ดˆ๊ธฐํ™”

Airflow๋Š” ๊ธฐ๋ณธ์œผ๋กœ sqllite๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

์•„๋ž˜ ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด Home Directory์— airflow ํด๋”๊ฐ€ ์ƒ์„ฑ์ด ๋˜๋Š”๋ฐ ์ด๋ฅผ ์›ํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ๋ผ๋ฉด ์œ„์— 2) ๋ฒˆ์„ ์‹คํ–‰ํ•˜๋ฉด ๋œ๋‹ค. 

$ airflow db init

 

6) ๊ณ„์ •์ƒ์„ฑ 

airflow users create \
 --username {LoginId} \
 --firstname {FIRST_NAME} \
 --lastname {LAST_NAME} \
 --role Admin \
 --password {password} \
 --email {email}

 

7) Airflow dags ํด๋” ์ƒ์„ฑ

Airflow ์„ค์น˜ ์‹œ ์ž๋™์œผ๋กœ ์ƒ์„ฑ๋˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— airflow ํ•˜์œ„ ํด๋”์— dags ํด๋”๋ฅผ ์ƒ์„ฑํ•ด์„œ ์ด ์•ˆ์— dag ํŒŒ์ผ์„ ์ž‘์„ฑํ•˜๋ฉด ๋œ๋‹ค.

 

8) Airflow Webserver ๋„์šฐ๊ธฐ

# ๊ธฐ๋ณธ(8080์ ‘์†)
$ airflow webserver
# ํฌํŠธ์„ค์ •
$ airflow webserver --port 8080

 

9) scheduler ์‹คํ–‰

$ airflow scheduler

 

10) localhost:8080 ์œผ๋กœ ์ ‘์†ํ•˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด Airflow UI ๊ฐ€ ๋œฌ๋‹ค. 

 

11) ๊ธฐํƒ€์„ค์ •

airflow.cfg ํŒŒ์ผ์— ์ ‘์†ํ•ด์„œ 

load_example=True -> load_example=False ๋กœ ๋ณ€๊ฒฝํ•˜๋ฉด dag example์ด ๋œจ์ง€ ์•Š๋Š”๋‹ค. 

728x90
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€