Airflow installation guide for running locally on M1 Mac
· 약 5분
Env
- python version: 3.10.14
Install python 3.10.4
pyenv install 3.10.14
pyenv local 3.10.14
Create python venv
python3.10 -m venv .venv
source .venv/bin/activate
Note Check python path and version
which python
python --version
Installation
Set AIRFLOW_HOME
Create a directory for airflow home directory whose config file(e.g. airflow.cfg) and logs. After that, set the directory as AIRFLOW_HOME.
export AIRFLOW_HOME=[path of the directory]
Example
export AIRFLOW_HOME=$(pwd)/airflow-home
Setup constraint url
AIRFLOW_VERSION=2.9.0
PYTHON_VERSION="$(python --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"
Install airflow
pip install "apache-airflow[postgres,celery]==${AIRFLOW_VERSION}" --constraint "${CONSTRAINT_URL}"
Note If there is any problem then install airflow without any plugin first, then install plugins.
pip install "apache-airflow==${AIRFLOW_VERSION}" --constraint "${CONSTRAINT_URL}"
pip install "apache-airflow[postgres,celery]" --constraint "${CONSTRAINT_URL}"Please remember that
--constrainthas to be in second installation
Setup airflow database (PostgreSQL)
CREATE USER airflow WITH PASSWORD 'airflow';
GRANT ALL PRIVILEGES ON DATABASE airflow TO airflow;
ALTER DATABASE airflow OWNER TO airflow;
ALTER ROLE airflow SET client_encoding TO 'utf8';
ALTER ROLE airflow SET default_transaction_isolation TO 'read committed';
ALTER ROLE airflow SET timezone TO 'Asia/Seoul';
Init airflow
First check version of the installed airflow, and it will be 2.9.0
airflow version
Init airflow DB
airflow db init
After run db init, should check there are files and directories in $AIRFLOW_HOME.
- airflow.cfg
- webserver_config.py (optional, if it is not, it's fine)
- logs
Create admin user
airflow users create --username admin --role Admin --firstname admin --lastname user --email admin@example.com
Update airflow config
Modify airflow.cfg
[core]
executor = LocalExecutor
[database]
sql_alchemy_conn = postgresql+psycopg2://airflow:airflow@localhost:5432/airflow
Note After updating
airflow.cfg, should runairflow db initagain.
Run
run scheduler
airflow scheduler
run web-server
airflow webserver --port [port number]
ETC
NO sample dags
If you don't need sample dags, then update airflow.cfg like below.
[core]
load_samples = False
Uninstall
Uninstall airflow
pip uninstall apache-airflow
Reset airflow DB
airflow db reset
Uninstall packages
pip freeze | grep apache-airflow | xargs pip uninstall -y
Remove airflow home directory
rm -rf ~/airflow
Refs
Installation
Trouble shoot
WARNING: There was an error checking the latest version of pip.
certifi issue
pip install --upgrade certifi
Proxy issue
pip install --proxy=http://your.proxy:port --upgrade pip
운영 환경 설정 가이 드 (추가)
1. 네트워크 환경 설정
공공 데이터 API 호출 시 M1/M2 환경에서 requests 라이브러리의 NO_PROXY 관련 이슈가 발생할 수 있습니다.
NO_PROXY 환경 변수를 반드시 설정해 주세요.
export NO_PROXY="*"
