
Apache Airflow is an open-source workflow management platform that manages data pipelines and automates workflows such as Extract, Transform, and Load (ETL) processes. If you want to install Apache Airflow on Ubuntu 24.04, it utilizes Python-based Directed Acyclic Graphs (DAGs) to schedule and execute tasks while streamlining the management of all required dependencies for error-free execution.
This article explains how to install Apache Airflow on Ubuntu 24.04, configure a secure environment, and test your deployment with a sample Directed Acyclic Graph (DAG).
Before you begin, you need to:
Apache Airflow is available as a Python package you can install using a package manager such as Pip. Follow the steps below to install Python if it's not available on your system, create a new virtual environment, and install Apache Airflow.
Update the server's package index.
View the available Python version on your server.
Your output should be similar to the one below.
Install Python if it's not available on your server.
Install the python3-venv Python virtual environment module and the PostgreSQL development library.
Create a new virtual environment such as airflow_env.
Activate the airflow_env virtual environment.
Verify that your shell prompt changes to the airflow_env virtual environment.
Use Pip to install Apache Airflow with support for PostgresQL.
Install PostgreSQL.
Start the PostgreSQL service.
Access the PostgreSQL console using the postgres user.
Your output should be similar to the one below:
Create a new airflow PostgreSQL user with a strong password. Replace YourStrongPassword with your desired password.
Create a new database, for example, airflowdb.
Grant the airflow user full privileges to all tables in the public schema.
Grant the airflow user ownership privileges to the airflowdb database.
Grant the airflow user all privileges on the public schema.
Exit the PostgreSQL console.
Open the airflow.cfg file in your Airflow installation directory.
Temporarily initialize the database and start the Airflow scheduler to create the necessary directories if the airflow directory is missing.
Press Ctrl+C to stop the scheduler.
Replace the default executor and sql_alchemy_conn values with the following configuration to enable parallel execution and set PostgreSQL as the metadata database.
Save and close the file.
Initialize the Airflow metadata database to apply the changes.
Your output should be similar to the one below:
Create a new administrative user to use with Apache Airflow. Replace admin with your desired username.
Start the Airflow web server on port 8080 as a background process and redirect all logs to the webserver.log file.
Start the Airflow scheduler and redirect all logs to the scheduler.log file.
Apache Airflow listens for connections using the default port 8080. Follow the steps below to secure Apache Airflow's port using Nginx and serve requests over HTTP and HTTPS.
Install Nginx.
Create a new airflow Nginx virtual host configuration file.
Add the following configurations to the file. Replace airflow.example.com with your actual domain.
Save and close the file.
The above Nginx configuration listens for incoming connections using your airflow.example.com domain and forwards all connections to the Apache Airflow port 8080.
Link the Airflow configuration to the Nginx sites-enabled directory to enable it.
Test the Nginx configuration for errors.
Your output should be similar to the one below.
Reload Nginx to apply the configuration changes.
Allow connections to the HTTP port 80 through the firewall.
Reload UFW to apply the firewall configuration changes.
Access your airflow.example.com domain using a web browser such as Chrome and verify that the Airflow login page displays.
SSL certificates encrypt the connection between a client and the Apache Airflow server. Follow the steps below to generate Let's Encrypt SSL certificates using Certbot to secure connections to Apache Airflow.
Install the Certbot Let's Encrypt Client.
Install Snap if it's not available on your workstation.
Move the Certbot binary to the /usr/bin path to enable it as a system-wide command.
Request a new Let's Encrypt SSL certificate using the Nginx plugin and your domain. Replace aiflow.example.com with your actual domain and admin@example.com with your active email address.
Your output should be similar to the one below when the certificate request is successful.
Verify that Certbot auto-renews the SSL certificate before it expires.
Restart Nginx to apply the SSL configuration changes.
Follow the steps below to access the Apache Airflow interface and run DAGs of your server.
Access the Apache Airflow web interface using your domain.
https://airflow.example.com ```
credentials you set earlier to log in to Apache Airflow.
Follow the steps below to create and run a sample DAG using Apache Airflow.
Create the dags directory in the Airflow installation directory.
Create a new my_first_dag.py Python application file in the dags directory.
Add the following code to the my_first_dag.py file to define a new DAG.
Save and close the file.
The above application code creates a my_first_dag sample DAG that runs daily and prints a Greetings from Vultr.
Navigate to the DAGs within the Apache Airflow interface. Find and enable the DAG to manually trigger it.
Use the Graph View and Event Log to monitor the DAG.
You have installed Apache Airflow on Ubuntu 24.04 and secured access to the application using Nginx as a reverse proxy. You can use Apache Airflow to create multiple workflows and DAGs to match your project needs. For more information, visit the Airflow documentation.
0 Comments
Be the first to comment and share your perspective with the community.