参见官网
若是虚拟机等,安装前可备份或快照,以免安装失败,导致不可用
Python-3.6.6.tgz
# 卸载 mariadb rpm -qa | grep mariadb mariadb-libs-5.5.65-1.el7.x86_64 mariadb-5.5.65-1.el7.x86_64 mariadb-devel-5.5.65-1.el7.x86_64 yum remove mariadb yum remove mariadb-libs # 安装依赖 rpm -ivh mysql57-community-release-el7-11.noarch.rpm yum install readline readline-devel -y yum install gcc -y yum install zlib* -y yum install openssl openssl-devel -y yum install sqlite-devel -y yum install python-devel mysql-devel -y # 提前到python官网下载好包 cd /opt/src tar -zxvf Python-3.6.6.tgz # 安装 python3 运行环境 cd Python-3.6.6/ # configure文件是一个可执行的脚本文件。如果配置了--prefix,安装后的所有 资源文件都会放在目录中 ./configure --prefix=/usr/local/python3.6 make && make install /usr/local/python3.6/bin/pip3 install virtualenv # 启动 python3 环境 cd /usr/local/python3.6/bin/ ./virtualenv env . env/bin/activate # 检查 python 版本 python -V
export AIRFLOW_HOME=/opt/app/servers/airflow
source /etc/profile
(env) [root@gcw2 bin]# pip install apache-airflow==1.10.11 -i https://pypi.douban.com/simple
pip install mysqlclient==1.4.6 airflow initdb
在执行 airflow initdb 命令时,如遇上如下报错:
ModuleNotFoundError: No module named 'sqlalchemy.ext.declarative.clsregistry'
这是由于 SQLAlchemy 模块版本低导致的错误。执行以下命令后,重新执行 airflow initdb 命令。
pip install SQLAlchemy==1.3.23
mysql数据库创建及用户权限
-- 创建数据库 SET GLOBAL explicit_defaults_for_timestamp = 1; create database airflowgcw2; -- 创建用户airflow,设置所有ip均可以访问 create user 'airflow'@'%' identified by 'xxx'; create user 'airflow'@'localhost' identified by 'xxx'; -- 用户授权,为新建的airflow用户授予Airflow库的所有权限 grant all on airflowgcw2.* to 'airflow'@'%'; flush privileges;
修改 $AIRFLOW_HOME/airflow.cfg:
# 约 75 行 sql_alchemy_conn = mysql://airflow:password@ip:port/airflowgcw2 # 重新执行 airflow initdb
(env) [root@gcw2 airflow]# pip install apache-airflow[password]
修改 airflow.cfg 配置文件(第一行修改,第二行增加):
## 约 281 行 [webserver] # 约 353行 authenticate = True auth_backend = airflow.contrib.auth.backends.password_auth
python中启动
输入python进入,然后执行下列
import airflow from airflow import models, settings from airflow.contrib.auth.backends.password_auth import PasswordUser user = PasswordUser(models.User()) user.username = 'airflow' user.email = 'xxx@xxx.com' user.password = 'xxx' session = settings.Session() session.add(user) session.commit() session.close() exit()
# 备注:要先进入python3的运行环境 cd /usr/local/python3.6/bin/ ./virtualenv env . env/bin/activate # 退出虚拟环境命令 deactivate # 启动scheduler调度器: airflow scheduler -D # 服务页面启动: airflow webserver -D
2021-09-09