airflow安裝詳細(xì)步驟

如果文章中存在某些名詞不理解,不用太在意,可先放過(guò),先部署好 環(huán)境體驗(yàn)一下airflow功能,在后續(xù)學(xué)習(xí)中再深入理解。

更多airflow資料,可查看:airflow從入門到精通學(xué)習(xí)筆記系列

如安裝過(guò)程中遇到問(wèn)題,可查看 airflow安裝及使用的常見(jiàn)問(wèn)題

安裝

實(shí)驗(yàn)環(huán)境:
centos7
python3.6
安裝腳本:

yum install -y python36
yum install -y python36-pip
yum install -y python36-devel
pip3 install apache-airflow
pip3 install pymysql

設(shè)置airflow的根目錄:

echo "export AIRFLOW_HOME=/data/airflow" >> /root/.bashrc
source /root/.bashrc

初始化

初始化數(shù)據(jù)庫(kù)表(默認(rèn)使用本地的sqlite數(shù)據(jù)庫(kù)):

[root@VM_7_246_centos /data]# airflow initdb
[2019-08-05 19:23:29,691] {__init__.py:51} INFO - Using executor SequentialExecutor
DB: sqlite:////data/airflow/airflow.db
[2019-08-05 19:23:30,019] {db.py:350} INFO - Creating tables
INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
INFO  [alembic.runtime.migration] Running upgrade  -> e3a246e0dc1, current schema
INFO  [alembic.runtime.migration] Running upgrade e3a246e0dc1 -> 1507a7289a2f, create is_encrypted
/usr/local/lib/python3.6/site-packages/alembic/util/messaging.py:69: UserWarning: Skipping unsupported ALTER for creation of implicit constraint
  warnings.warn(msg)
INFO  [alembic.runtime.migration] Running upgrade 1507a7289a2f -> 13eb55f81627, maintain history for compatibility with earlier migrations
INFO  [alembic.runtime.migration] Running upgrade 13eb55f81627 -> 338e90f54d61, More logging into task_instance
INFO  [alembic.runtime.migration] Running upgrade 338e90f54d61 -> 52d714495f0, job_id indices
INFO  [alembic.runtime.migration] Running upgrade 52d714495f0 -> 502898887f84, Adding extra to Log
INFO  [alembic.runtime.migration] Running upgrade 502898887f84 -> 1b38cef5b76e, add dagrun
INFO  [alembic.runtime.migration] Running upgrade 1b38cef5b76e -> 2e541a1dcfed, task_duration
INFO  [alembic.runtime.migration] Running upgrade 2e541a1dcfed -> 40e67319e3a9, dagrun_config
INFO  [alembic.runtime.migration] Running upgrade 40e67319e3a9 -> 561833c1c74b, add password column to user
INFO  [alembic.runtime.migration] Running upgrade 561833c1c74b -> 4446e08588, dagrun start end
INFO  [alembic.runtime.migration] Running upgrade 4446e08588 -> bbc73705a13e, Add notification_sent column to sla_miss
INFO  [alembic.runtime.migration] Running upgrade bbc73705a13e -> bba5a7cfc896, Add a column to track the encryption state of the 'Extra' field in connection
INFO  [alembic.runtime.migration] Running upgrade bba5a7cfc896 -> 1968acfc09e3, add is_encrypted column to variable table
INFO  [alembic.runtime.migration] Running upgrade 1968acfc09e3 -> 2e82aab8ef20, rename user table
INFO  [alembic.runtime.migration] Running upgrade 2e82aab8ef20 -> 211e584da130, add TI state index
INFO  [alembic.runtime.migration] Running upgrade 211e584da130 -> 64de9cddf6c9, add task fails journal table
INFO  [alembic.runtime.migration] Running upgrade 64de9cddf6c9 -> f2ca10b85618, add dag_stats table
INFO  [alembic.runtime.migration] Running upgrade f2ca10b85618 -> 4addfa1236f1, Add fractional seconds to mysql tables
INFO  [alembic.runtime.migration] Running upgrade 4addfa1236f1 -> 8504051e801b, xcom dag task indices
INFO  [alembic.runtime.migration] Running upgrade 8504051e801b -> 5e7d17757c7a, add pid field to TaskInstance
INFO  [alembic.runtime.migration] Running upgrade 5e7d17757c7a -> 127d2bf2dfa7, Add dag_id/state index on dag_run table
INFO  [alembic.runtime.migration] Running upgrade 127d2bf2dfa7 -> cc1e65623dc7, add max tries column to task instance
INFO  [alembic.runtime.migration] Running upgrade cc1e65623dc7 -> bdaa763e6c56, Make xcom value column a large binary
INFO  [alembic.runtime.migration] Running upgrade bdaa763e6c56 -> 947454bf1dff, add ti job_id index
INFO  [alembic.runtime.migration] Running upgrade 947454bf1dff -> d2ae31099d61, Increase text size for MySQL (not relevant for other DBs' text types)
INFO  [alembic.runtime.migration] Running upgrade d2ae31099d61 -> 0e2a74e0fc9f, Add time zone awareness
INFO  [alembic.runtime.migration] Running upgrade d2ae31099d61 -> 33ae817a1ff4, kubernetes_resource_checkpointing
INFO  [alembic.runtime.migration] Running upgrade 33ae817a1ff4 -> 27c6a30d7c24, kubernetes_resource_checkpointing
INFO  [alembic.runtime.migration] Running upgrade 27c6a30d7c24 -> 86770d1215c0, add kubernetes scheduler uniqueness
INFO  [alembic.runtime.migration] Running upgrade 86770d1215c0, 0e2a74e0fc9f -> 05f30312d566, merge heads
INFO  [alembic.runtime.migration] Running upgrade 05f30312d566 -> f23433877c24, fix mysql not null constraint
INFO  [alembic.runtime.migration] Running upgrade f23433877c24 -> 856955da8476, fix sqlite foreign key
INFO  [alembic.runtime.migration] Running upgrade 856955da8476 -> 9635ae0956e7, index-faskfail
INFO  [alembic.runtime.migration] Running upgrade 9635ae0956e7 -> dd25f486b8ea
INFO  [alembic.runtime.migration] Running upgrade dd25f486b8ea -> bf00311e1990, add index to taskinstance
INFO  [alembic.runtime.migration] Running upgrade 9635ae0956e7 -> 0a2a5b66e19d, add task_reschedule table
INFO  [alembic.runtime.migration] Running upgrade 0a2a5b66e19d, bf00311e1990 -> 03bc53e68815, merge_heads_2
INFO  [alembic.runtime.migration] Running upgrade 03bc53e68815 -> 41f5f12752f8, add superuser field
INFO  [alembic.runtime.migration] Running upgrade 41f5f12752f8 -> c8ffec048a3b, add fields to dag
INFO  [alembic.runtime.migration] Running upgrade c8ffec048a3b -> a56c9515abdc, Remove dag_stat table
INFO  [alembic.runtime.migration] Running upgrade c8ffec048a3b -> dd4ecb8fbee3, Add schedule interval to dag
INFO  [alembic.runtime.migration] Running upgrade dd4ecb8fbee3 -> 939bb1e647c8, task reschedule fk on cascade delete
WARNI [airflow.utils.log.logging_mixin.LoggingMixin] cryptography not found - values will not be stored encrypted.
Done.

查看其生成文件:

[root@VM_7_246_centos /data]# ls $AIRFLOW_HOME
airflow.cfg  airflow.db  logs  unittests.cfg

配置

配置MySQL數(shù)據(jù)庫(kù)(創(chuàng)建airflow數(shù)據(jù)庫(kù),并創(chuàng)建用戶和授權(quán),給airflow訪問(wèn)數(shù)據(jù)庫(kù)使用):

# 新建airflow的數(shù)據(jù)庫(kù)
MariaDB [(none)]> CREATE DATABASE airflow;
# 授權(quán)從localhost登錄的root賬號(hào)對(duì)airflow的所有操作
MariaDB [(none)]> GRANT all privileges on root.* TO 'root'@'localhost'  IDENTIFIED BY '123456'; 
MariaDB [(none)]> FLUSH PRIVILEGES;

配置airflow使用LocalExecutor執(zhí)行器,及使用MySQL數(shù)據(jù)庫(kù):

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 = sqlite:////data/airflow/airflow.db
sql_alchemy_conn = mysql+pymysql://root:123456@localhost:3306/airflow

再次初始化數(shù)據(jù)庫(kù)表(在MySQL中創(chuàng)建):

airflow initdb

查看創(chuàng)建的airflow數(shù)據(jù)表:

MariaDB [None] > use airflow;
MariaDB [airflow]> show tables;
+-------------------+
| Tables_in_airflow |
+-------------------+
| alembic_version  |
| chart            |
| connection        |
| dag              |
| dag_pickle        |
| dag_run          |
| dag_stats        |
| import_error      |
| job              |
| known_event      |
| known_event_type  |
| log              |
| sla_miss          |
| slot_pool        |
| task_fail        |
| task_instance    |
| users            |
| variable          |
| xcom              |
+-------------------+

服務(wù)啟動(dòng)

添加airflow-scheduler服務(wù)啟動(dòng)腳本:

/usr/lib/systemd/system/airflow-scheduler.service 
[Unit]
Description=Airflow Scheduler
Wants=network-online.target
After=network-online.target

[Service]
User=root
Group=root
Type=simple
Restart=on-failure
Environment=export AIRFLOW_HOME=/data/airflow
ExecStart=/usr/local/bin/airflow scheduler
LimitNOFILE=10000
TimeoutStopSec=20

[Install]
WantedBy=multi-user.target

啟動(dòng)airflow-scheduler服務(wù):

systemctl start airflow-scheduler

添加airflow-webserver服務(wù)啟動(dòng)腳本:

/usr/lib/systemd/system/airflow-webserver.service 
[Unit]
Description=Airflow Scheduler
Wants=network-online.target
After=network-online.target

[Service]
User=root
Group=root
Type=simple
Restart=on-failure
Environment=export AIRFLOW_HOME=/data/airflow
ExecStart=/usr/local/bin/airflow webserver
LimitNOFILE=10000
TimeoutStopSec=20

[Install]
WantedBy=multi-user.target

啟動(dòng)airflow-webserver服務(wù):

systemctl start airflow-webserver

使用

訪問(wèn)http://localhost:8080地址,看到首頁(yè)界面即成功;

首頁(yè)

更多airflow資料,可查看:airflow從入門到精通學(xué)習(xí)筆記系列

如發(fā)現(xiàn)文中有錯(cuò)誤,望留言指明,萬(wàn)分感激;
如對(duì)此文章內(nèi)容感興趣,想進(jìn)一步探討,可以留言交流;
如想轉(zhuǎn)發(fā)此文章,請(qǐng)留言協(xié)商一下,切勿不指明出處的轉(zhuǎn)發(fā),尊重原創(chuàng);
如閱讀過(guò)程中有收獲,并想感謝一下,歡迎打賞;
----小林幫

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • 什么是airflow Airflow是Airbnb開(kāi)發(fā)的用于管理工作流的開(kāi)源項(xiàng)目,自帶ui和調(diào)度,目前已成為Apa...
    星辰fml閱讀 1,957評(píng)論 0 0
  • 桃之夭夭,灼灼其花。 之子于歸,宜其室家。 桃之夭夭,其葉蓁蓁。 之子于歸,宜其家人。
    五月的荷閱讀 286評(píng)論 0 3
  • 2018年我個(gè)人成就50件事 目的:見(jiàn)大家都在分享自己2018年的事件,我的目標(biāo)是再小的事情都寫出來(lái),力爭(zhēng)100件...
    劉妞兒的書屋閱讀 715評(píng)論 0 0
  • 世人盡嘆夕陽(yáng)美, 無(wú)人駐足燈光悲。 如今我為籠中鳥(niǎo), 想念過(guò)往之翔飛。
    2ef6580de603閱讀 127評(píng)論 0 0
  • 早起方法論 轉(zhuǎn)眼間,冬天已經(jīng)過(guò)去快半,眼下正是最冷時(shí)節(jié),杭州最低氣溫已經(jīng)零下7℃。我很早之前就開(kāi)始工作日早上7點(diǎn)鐘...
    Luffy_Zhu閱讀 147評(píng)論 0 1