# 원하는 가상환경 실행(아나콘다사용)
conda create -n airflow python=3.9
conda activate airflow
mkdir airflow
cd airflow
# 설치전 환경변수 설정
# airflow 프로젝트 dir
export AIRFLOW_HOME=~/airflow
# // 공식문서 참고 //
# Install Airflow using the constraints file
AIRFLOW_VERSION=2.5.0
PYTHON_VERSION="$(python --version | cut -d " " -f 2 | cut -d "." -f 1-2)"
# For example: 3.7
CONSTRAINT_URL="https://raw.githubusercontent.com/apache/airflow/constraints-${AIRFLOW_VERSION}/constraints-${PYTHON_VERSION}.txt"
# For example: https://raw.githubusercontent.com/apache/airflow/constraints-2.5.0/constraints-3.7.txt
pip install "apache-airflow==${AIRFLOW_VERSION}" --constraint "${CONSTRAINT_URL}"
# 이 명령어는 DB를 세팅한 후에 실행하여야 한다.
airflow standalone
# Visit localhost:8080 in the browser and use the admin account details
# shown on the terminal to login.
# Enable the example_bash_operator dag in the home page
mysqlclient 설치안되는 문제 : https://bobbyhadz.com/blog/python-failed-building-wheel-for-mysqlclient
리눅스 설치 공식문서 : https://dev.mysql.com/doc/mysql-apt-repo-quick-guide/en/
# mysql 설치
sudo apt-get install mysql-server
# mysqlclient 관련
sudo apt-get install libmysqlclient21
# mysqlclient 설치 안될 시
# 👇️ for macOS
brew install mysql
pip install mysqlclient
# 👇️ for Debian/Ubuntu
sudo apt-get install python3-dev default-libmysqlclient-dev build-essential
pip install mysqlclient
# 👇️ for Red Hat/CentOS
sudo yum install python3-devel mysql-devel
pip install mysqlclient
# 👇️ for Anaconda
conda install -c conda-forge mysqlclient
# 👇️ for Jupyter Notebook
!pip install mysqlclient
CREATE DATABASE airflow_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'airflow_user' IDENTIFIED BY 'airflow_pass';
GRANT ALL PRIVILEGES ON airflow_db.* TO 'airflow_user';
# shell
cd airflow
airflow db init
vi airflow.cfg
[database]
...
sql_alchemy_conn = mysql+mysqldb://<user>:<password>@<host>[:<port>]/<dbname>
...
[webserver]
default_ui_timezone = Asia/Seoul
...
# 다시 db 초기화
airflow db init
# 초기 폴더 생성
cd $AIRFLOW_HOME
sudo mkdir ~/airflow/dags ~/airflow/plugins
# 관리자 계정 생성
airflow users create \
--username airflow \
**--firstname airflow \**
--lastname airflow \
--role Admin \
--email airflow@example.org
# 실행하면 password 입력하라고 뜸 비밀번호 설정하는 것이니, 원하는 비밀번호 두 번 입력
# 웹서버 싱행
airflow webserver --port 8080 -D