airflow使用MySQL數據庫(第三方數據庫詳解)

airflow 是一個python寫的調度平臺,大致的認識是 : 定義一些任務(腳本、命令、連接...),airflow調度平臺可以自動去運行,後面會給出運行日誌(UI界面)等,這個UI界面(WEB端)有一些複雜的分析圖譜,可以做的事情就很多了。

下面是介紹airflow使用非默認的數據庫,默認是SQLite ,官方的介紹不夠仔細,這篇是個人總結。

官方地址:http://airflow.apache.org/docs/stable/installation.html

一、登陸MySQL、創建數據庫、創建用戶密碼、更新策略

mysql> create database airflow;
mysql> GRANT all privileges on airflow.* TO 'airflow'@'%' IDENTIFIED BY 'xE!D95Exxx';
mysql> FLUSH PRIVILEGES;

 二、設置MySQL對null的處理,重啓服務器(可有可無)

mysql> set explicit_defaults_for_timestamp = 1;

重啓服務器(可有可無)
[root@VM_0_16_centos airflow]# systemctl restart mysqld

 這個設置是官方文檔提出的,下面是一篇文章關於此屬性的介紹:https://www.jianshu.com/p/dfa0380eb6b9

 三、對airflow配置文件(airflow.cfg)的設置

#打開你安裝airflow的文件夾
[root@VM_0_16_centos airflow]# vim ~/airflow/airflow.cfg

#設置兩個屬性
The executor class that airflow should use. Choices include
# SequentialExecutor, LocalExecutor, CeleryExecutor, DaskExecutor, KubernetesExecutor
#executor = SequentialExecutor
executor = LocalExecutor

# The SqlAlchemy connection string to the metadata database.
# SqlAlchemy supports many different database engine, more information
# their website
sql_alchemy_conn = mysql+pymysql://airflow:[email protected]/airflow


#注意pymysql庫是否安裝
[root@VM_0_16_centos airflow]# pip3 install pymysql

一些小坑提示:數據庫連接路徑要注意是否還是使用mysql的驅動 ,現在已經使用pymysql,沒有安裝會報錯,找不到驅動。

四、重置數據庫、初始化數據庫

[root@VM_0_16_centos airflow]# airflow resetdb
[root@VM_0_16_centos airflow]# airflow initdb

 

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