centos7 大數據任務調度系統airflow的安裝(單機或分佈式)


本文使用的安裝環境是python3, 建議單獨設置虛擬環境進行安裝。airflow server端目前只支持Linux

1. 設置airflow的家目錄位置

在/etc/profile添加如下代碼
export AIRFLOW_HOME=~/airflow
export SLUGIFY_USES_TEXT_UNIDECODE=yes

修改完畢,在shell中執行 source /etc/profile

2. 安裝airflow

pip install apache-airflow

3. 初始化airflow

airflow initdb

################################ 可忽略 ###########################################
初始化以後,默認使用sqlite和SequentialExecutor,無法並行化任務
airflow webserver 啓動web頁面,默認端口8080 直接訪問 ip:8080即可觀看效果
airflow scheduler 啓動調度
單純的玩玩還是可以的,安裝配置到此爲止
不過線上更推薦使用LocalExecutor或者CeleryExecutor

4. mysql服務器配置

創建airflow的數據庫

create database airflow charset=utf8;

修改mysql服務器的配置文件 my.cnf,在[mysqld]下添加如下參數

explicit_defaults_for_timestamp=1

至於爲什麼設置,官方原解釋說明: We rely on more strict ANSI SQL settings for MySQL in order to have sane defaults
修改完畢,重啓mysql服務器

service mysqld restart

5. airflow建議兩種運行方案 LocalExecutor或者CeleryExecutor

  • 5.1 LocalExecutor 配置 (單機版調度)
    修改airflow.cfg配置文件
    executor = LocalExecutor
    sql_alchemy_conn = mysql://user:[email protected]:3306/airflow #連接mysql的地址

  • 5.2 CeleryExecutor 配置(可實現分佈式調度)

# 安裝必要的包
pip install apache-airflow[celery]
pip install apache-airflow[redis]
pip install redis

# 修改airflow.cfg配置文件
executor = CeleryExecutor
sql_alchemy_conn = mysql://user:[email protected]:3306/airflow  #連接mysql的地址
broker_url=redis://192.168.115.101:6379/0
result_backend = db+mysql://user:[email protected]:3306/airflow

6. 再次初始化數據庫

airflow initdb

7. 啓動web服務和調度服務

airflow webserver
airflow scheduler
airflow worker   # CeleryExecutor 執行這個,  LocalExecutor不用執行

8. 添加web認證

  1. 安裝web認證包
pip install apache-airflow[password]
  1. 修改airflow.cfg配置文件
[webserver]
authenticate = True
auth_backend = airflow.contrib.auth.backends.password_auth
  1. 添加賬號
# 啓動一個python命令窗
>>> import airflow
>>> from airflow import models, settings
>>> from airflow.contrib.auth.backends.password_auth import PasswordUser
>>> user = PasswordUser(models.User())
>>> user.username = 'new_user_name'
>>> user.email = '[email protected]'
>>> user.password = 'set_the_password'
>>> session = settings.Session()
>>> session.add(user)
>>> session.commit()
>>> session.close()
>>> exit()
  1. 重啓web即可

參考airflow官方文檔
[1]: https://airflow.incubator.apache.org/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章