airFlow入门-环境安装

安装流程

step1 在本地创建文件夹,并安装 Python virtualenv      

         python3 -m venv /path/to/new/virtual/environment

    说明:macos 最新系统是默认安装了 Python3 的版本 ,通过命令 python3查看

Python 3.9.6 (default, Oct 18 2022, 12:41:40) 
[Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

      说明本地已经安装了 Python3 的环境,不要重复安装  

 

step2 按照官网提供的脚本,在本地安装airflow

        https://airflow.apache.org/docs/apache-airflow/stable/start/local.html

 1、设置 airflow的目录  

  export AIRFLOW_HOME=~/airflow

2、查看是否正确设置 

  echo $AIRFLOW_HOME

3、复制命令并安装环境 

# Install Airflow using the constraints file
AIRFLOW_VERSION=2.5.1
PYTHON_VERSION="$(python --version | cut -d " " -f 2 | cut -d "." -f 1-2)"
# For example: 3.7
CONSTRAINT_URL="https://raw.githubusercontent.com/apache/airflow/constraints-${AIRFLOW_VERSION}/constraints-${PYTHON_VERSION}.txt"

4、装置 airflow

 执行:pip install "apache-airflow==${AIRFLOW_VERSION}" --constraint "${CONSTRAINT_URL}"

提示 :bash: pip: command not found  说明:这个错误是表示还未安装pip,因为mac上的python不自带pip(一种python包的安装工具)
安装 pip 参照链接:https://blog.csdn.net/yincodes/article/details/81709162

mac自带的Python的安装路径:
/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9

安装并升级 pip
 cd  /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9
 python3 -m pip install --upgrade pip

  执行 python3 -m pip install --upgrade pip  后提示 :说明更新成功

bash-3.2#  python3 -m pip install --upgrade pip
Requirement already satisfied: pip in ./lib/python3.9/site-packages (21.2.4)
Collecting pip
  Downloading pip-23.0.1-py3-none-any.whl (2.1 MB)
     |████████████████████████████████| 2.1 MB 11 kB/s 
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 21.2.4
    WARNING: Value for bin_prefix does not match. Please report this to <https://github.com/pypa/pip/issues/10151>
    distutils: /Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/bin
    sysconfig: /usr/local/bin
    WARNING: Additional context:
    user = False
    home = None
    root = None
    prefix = None
    Uninstalling pip-21.2.4:
      Successfully uninstalled pip-21.2.4
Successfully installed pip-23.0.1
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
bash-3.2# pwd
/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9
bash-3.2# pip version
ERROR: unknown command "version"
bash-3.2# pip --version
pip 23.0.1 from /Library/Python/3.9/site-packages/pip (python 3.9)
bash-3.2# pwd
/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9
bash-3.2# 

  执行 :pip install "apache-airflow==${AIRFLOW_VERSION}" --constraint "${CONSTRAINT_URL}" 提示 :

ERROR: 404 Client Error: Not Found for url: https://raw.githubusercontent.com/apache/airflow/constraints-2.5.1/constraints-.txt

原因 :mac电脑上安装的是 Python 3.9.6  获取版本的方式 是 python3 --version 而不是 python --version ,所以这一步应改为

AIRFLOW_VERSION=2.5.1
PYTHON_VERSION="$(python3 --version | cut -d " " -f 2 | cut -d "." -f 1-2)"
# For example: 3.7
CONSTRAINT_URL="https://raw.githubusercontent.com/apache/airflow/constraints-${AIRFLOW_VERSION}/constraints-${PYTHON_VERSION}.txt"

然后再执行 ,便可安装成功

pip install "apache-airflow==${AIRFLOW_VERSION}" --constraint "${CONSTRAINT_URL}"

下一步:初始化数据库 执行命令 :airflow db init
提示
bash-3.2# airflow db init
/Library/Python/3.9/site-packages/airflow/models/base.py:49 MovedIn20Warning: [31mDeprecated API features detected! These feature(s) are not compatible with SQLAlchemy 2.0. [32mTo prevent incompatible upgrades prior to updating applications, ensure requirements files are pinned to "sqlalchemy<2.0". [36mSet environment variable SQLALCHEMY_WARN_20=1 to show all deprecation warnings.  Set environment variable SQLALCHEMY_SILENCE_UBER_WARNING=1 to silence this message.[0m (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
DB: sqlite:////var/root/airflow/airflow.db
[2023-03-12 16:55:46,793] {migration.py:205} INFO - Context impl SQLiteImpl.
[2023-03-12 16:55:46,793] {migration.py:208} INFO - Will assume non-transactional DDL.
INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
INFO  [alembic.runtime.migration] Running stamp_revision  -> 290244fb8b83
WARNI [airflow.models.crypto] empty cryptography key - values will not be stored encrypted.
Initialization done

 下一步:创建一个admin的管理员

airflow users create \
--username admin \
--firstname test \
--lastname lu \
--role Admin \
--email test.lu@xxx.com

执行后会提示输入密码:输入两次确认密码即可。

 12345678

step3   启动和停止airflow 的 webserver / scheduler

启动 webserver 执行: airflow webserver --port 8080 -D 

输入 localhost:8080 即可启动airflow   输入 用户 admin, 密码 自己输入的密码 

启动 scheduler  :执行  airflow scheduler

 

=====================

dags folder 

/Library/Python/3.9/site-packages/airflow/example_dags

 

 

mac 本地安装 gsutil 

https://cloud.google.com/storage/docs/gsutil_install?hl=zh-cn

1、下载 google-cloud-sdk   https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-428.0.0-darwin-arm.tar.gz?hl=zh-cn

      1. 将归档解压缩到文件系统上的任意位置(最好是解压缩到您的主目录)。在 macOS 上,此操作可通过打开下载到首选位置的 .tar.gz 归档文件来实现。

        如需替换现有安装,请移除现有的 google-cloud-sdk 目录,然后将归档解压缩到同一位置。

      2. (可选)使用安装脚本将 gcloud CLI 工具添加到您的 PATH。您还可以选择为 shell 启用命令补全功能、使用情况统计信息收集功能,并安装 Python 3.7。

        使用以下命令运行脚本(从您在上一步中解压缩的文件夹的根目录运行):

         
        ./google-cloud-sdk/install.sh
        也可以通过提供偏好设置作为标志以非交互方式(例如使用脚本)完成此操作。如需描述可用标志,请运行以下命令:
         
        ./google-cloud-sdk/install.sh --help
        如需在开启屏幕阅读器模式的情况下运行安装脚本,请运行以下命令:
         
        ./google-cloud-sdk/install.sh --screen-reader=true
        打开新终端,以使更改生效。
      3. 如需初始化 gcloud CLI,请运行 gcloud init
 
./google-cloud-sdk/bin/gcloud init
    1. 可选。使用组件管理器安装其他组件。

使用 components update 命令执行更新操作:gcloud components update

如需了解如何使用 gsutil,请参阅《快速入门:使用 gsutil 工具》练习,或运行 gsutil help

 

posted @ 2023-03-11 13:49  二叉树的博客  阅读(1126)  评论(0编辑  收藏  举报