DEV Community

Tanakrit Seangnet
Tanakrit Seangnet

Posted on • Updated on

คู่มือการใช้งาน Airflow

Alt Text

สิ่งที่ต้องมี

  • Docker

เปิดใช้งาน Airflow

ขั้นตอนที่ 1. แตกไฟล์โปรเจคที่ได้รับ

image

  • ./dags - สามารถใส่ไฟล์ DAG ของคุณได้ที่นี่
  • ./logs - บันทึกจาก execution และ scheduler
  • ./plugins - สามารถใส่ปลั๊กอินที่กำหนดเองได้ที่นี่
  • ./worker - ไฟล์ airflow.cfg

ขั้นตอนที่ 2. เรียกใช้งาน Terminal cd มาที่โฟลเดอร์

image

ใช้คำสั่งและรอจนกว่าขึ้นแบบในรูป

docker-compose up airflow-init
Enter fullscreen mode Exit fullscreen mode

image

ขั้นตอนที่ 3. ใช้คำสั่งเพื่อเริ่มต้นใช้งาน

ก่อนเริ่มใช้งานควรปรับแต่ง config ให้เรียบร้อย

docker-compose up
Enter fullscreen mode Exit fullscreen mode

ล็อกอินเพื่อเข้าใช้งาน web ui ได้ที่ http://localhost:8080.
ชื่อบัญชีผู้ใช้ที่ถูกสร้างขึ้นคือ airflow และรหัสผ่าน airflow สำหรับ admin

image


การปรับแต่ง Config

การปรับแต่งจะทำในไฟล์ ./worker/airflow.cfg

Timezone

#มี default เป็น UTC
[core]
default_timezone = Asia/Bangkok

[webserver]
default_ui_timezone = Asia/Bangkok
Enter fullscreen mode Exit fullscreen mode

SMTP Server

ใช้ SMTP Server Gmail สำหรับส่งอีเมล

[smtp]
smtp_host = smtp.gmail.com
smtp_starttls = True
smtp_ssl = False
# Example: smtp_user = airflow
smtp_user = your@gmail.com
# Example: smtp_password = airflow
smtp_password = your_password_gmail
smtp_port = 25 หรือ 587
smtp_mail_from = your@gmail.com
smtp_timeout = 30
smtp_retry_limit = 5
Enter fullscreen mode Exit fullscreen mode

การใช้งาน Web UI

การสร้าง Connection ID

image

ระบุข้อมูลเพื่อเชื่อมต่อกับฐานข้อมูล conn_id จะต้องตรงกับ CONN_ID ในไฟล์ python
image

การสร้าง Users

Screenshot (503)
กดปุ่ม + เพื่อเพิ่ม User
image

การสร้าง Roles

Screenshot (504)
กดปุ่ม + เพื่อเพิ่ม Roles
image

การเปิดใช้งาน Active DAG

image

การ Trigger DAG

image


Top comments (0)