第一步、安装python开发包,用于编译Python第三方模块

yum install python-devel

第二步、安装Python的Mysql客户端模块

pip install mysqlclient

第三步、安装airflow、包括加密组件、用户登录组件

export AIRFLOW_HOME=~/airflow
export SLUGIFY_USES_TEXT_UNIDECODE=yes
pip install apache-airflow
pip install apache-airflow[mysql]
pip install apache-airflow[crypto]
pip install apache-airflow[password]

第四步、修改airflow.conf

# The executor class that airflow should use. Choices include
# SequentialExecutor, LocalExecutor, CeleryExecutor, DaskExecutor, KubernetesExecutor
executor = LocalExecutor
# The SqlAlchemy connection string to the metadata database.
# SqlAlchemy supports many different database engine, more information
# their website
sql_alchemy_conn = mysql://root:xxxxxx@localhost:3306/airflow

第五步、彻底卸载Mariadb,安装Mysql5.7
彻底卸载老的,卸载前请备份数据

mysqldump -u root -p --all-databases > alldb.sql
yum remove mysql MySQL-server MySQL-shared MySQL-shared-compat MariaDB-server MariaDB-client
rpm -qa|grep mariadb
rpm -e mariadb-embedded-devel-5.5.60-1.el7_5.x86_64
rpm -e mariadb-devel-5.5.60-1.el7_5.x86_64
rpm -e mariadb-embedded-5.5.60-1.el7_5.x86_64
rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64

添加Mysql5.7的yum

vim /etc/yum.repos.d/mysql-community.repo
wget https://repo.mysql.com//mysql80-community-release-el7-2.noarch.rpm
rpm -Uvh mysql80-community-release-el7-2.noarch.rpm
yum install mysql-community-server
systemctl start mysqld
systemctl status mysqld

mysql-community.repo内容如下:
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

上面步骤后Mysql5.7安装完成!
查看Mysql安装后的临时密码,并修改密码,并创建数据库airflow

grep 'temporary password' /var/log/mysqld.log
mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'xxxxxx'
FLUSH  PRIVILEGES;
CREATE DATABASE IF NOT EXISTS airflow  DEFAULT CHARSET utf8;

修改my.cnf

vim /etc/my.cnf

添加 explicit_defaults_for_timestamp = 1
重启Mysql

systemctl restart mysqld

第六步、初始化airflow数据库、启动web

airflow initdb

第七步、配置web登录

[webserver]
authenticate = True
auth_backend = airflow.contrib.auth.backends.password_auth

执行下面python初始化一个用户

import airflow
from airflow import models, settings
from airflow.contrib.auth.backends.password_auth import PasswordUser
user = PasswordUser(models.User())
user.username = 'youfangxi'
user.email = '951868171@qq.com'
user.password = 'xxxxxx'
# 超级管理员添加 user.superuser = True
session = settings.Session()
session.add(user)
session.commit()
session.close()
exit()

启动过程中若遇到MySQLdb ImportError: libmysqlclient.so.18  问题,可通过下面步骤解决

yum provides */libmysqlclient.so.18

查看那些包提供 libmysqlclient.so.18 然后安装

yum install mysql-community-libs-compat-5.7.25-1.el7.x86_64

这样最基本的一个带用户认证的airflow就基本安装完成!

打赏
CentOS上Airflow安装部署流程
Tagged on:

发表评论