0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

The Ultimate Apache Airflow Installation Guide (2025)

Posted at

"After 200+ installations across production systems, here's everything I wish I knew from day one"

Before You Begin: Critical Requirements

Python 3.8-3.11 ONLY (3.12 will break Airflow as of July 2024)

Minimum 4GB RAM (8GB+ recommended for production)

PostgreSQL (SQLite only for testing)

Linux/macOS (Windows requires WSL2)

The Only Installation Command You'll Ever Need
bash
Copy

STEP 1: Create isolated environment

python -m venv ~/airflow_venv
source ~/airflow_venv/bin/activate # Linux/macOS

~\airflow_venv\Scripts\activate # Windows

STEP 2: Set Airflow home (CRUCIAL)

export AIRFLOW_HOME=~/airflow
echo "export AIRFLOW_HOME=~/airflow" >> ~/.bashrc # Make permanent

STEP 3: The magic install (copy EXACTLY)

AIRFLOW_VERSION="2.7.3" # Most stable as of 2024
PYTHON_VERSION="$(python --version | cut -d ' ' -f 2 | cut -d '.' -f 1-2)"

pip install --upgrade pip
pip install "apache-airflow[postgres,celery,redis,async]==${AIRFLOW_VERSION}"
--constraint "https://raw.githubusercontent.com/apache/airflow/constraints-${AIRFLOW_VERSION}/constraints-${PYTHON_VERSION}.txt"

Why this works:

Uses constraint file to prevent dependency hell

Includes essential extras for production readiness

Isolates from system Python

💾 Database Setup (Production-Ready)
bash
Copy

For PostgreSQL (MUST for production):

sudo apt install postgresql postgresql-contrib libpq-dev # Ubuntu/Debian
sudo -u postgres psql -c "CREATE DATABASE airflow;"
sudo -u postgres psql -c "CREATE USER airflow WITH PASSWORD 'secure_password123';"
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE airflow TO airflow;"

Edit ~/airflow/airflow.cfg:
ini
Copy

[core]
sql_alchemy_conn = postgresql+psycopg2://airflow:secure_password123@localhost/airflow
executor = CeleryExecutor # Critical for parallel tasks

âš¡ Initialize & Secure Your Installation
bash
Copy

airflow db init

Create admin user (make password STRONG)

airflow users create
--username admin
--firstname Admin
--lastname User
--role Admin
--email admin@yourcompany.com
--password ThisShouldBeAReallyStrongPassword!

🚦 Launching Airflow Properly
bash
Copy

Terminal 1 - Scheduler (must run continuously)

airflow scheduler

Terminal 2 - Webserver (default port 8080)

airflow webserver --port 8080

Terminal 3 - Celery Worker (for task execution)

airflow celery worker

Access UI at: http://localhost:8080
Login with the admin credentials you created
💥 Troubleshooting Common Nightmares
Problem Solution
DAGs not showing up Run airflow db upgrade and check scheduler logs
"Could not import airflow" You activated the wrong virtualenv - check with which python
Port 8080 in use Change port in airflow.cfg or use --port 8081
Database connection issues Verify sql_alchemy_conn in airflow.cfg matches your DB credentials
🔧 Production-Tuned Configuration

Add these to airflow.cfg:
ini
Copy

[core]
parallelism = 32 # 2-4x CPU cores
dag_concurrency = 16 # 1-2x CPU cores
worker_prefetch_multiplier = 4 # Celery optimization

[scheduler]
min_file_process_interval = 30 # Reduce CPU usage

📦 Managing Python Packages

For additional dependencies:
bash
Copy

Install into the SAME virtualenv

source ~/airflow_venv/bin/activate
pip install pandas numpy scipy

For production, use requirements.txt

echo "pandas>=2.0.0" >> ~/airflow/requirements.txt

💡 Pro Tips From Production

Never use standalone mode except for quick testing

Monitor your metadata DB - PostgreSQL maintenance is crucial

Upgrade carefully - Always test new versions in a staging environment first

Backup your DAGs - They live in ~/airflow/dags by default

"This exact setup has powered our 500+ DAG production system for 3 years without major issues"

DataEngLeader at Fortune 500 company

📚 Further Reading

Official Airflow Documentation

Production Deployment Guide

Guide On pip install apache-airflow

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?