该文是基于python虚拟化环境来安装,非虚拟化也是一样,虚拟化我只是不想破环系统环境。

安装python虚拟环境

pip install virtualenv

设置环境变量

sudo vi /etc/profile

将如下内容添加到末尾

export PYTHON_HOME=/usr/local/python3

export PATH=$PATH:$PYTHON_HOME/bin

source /etc/profile

创建虚拟环境存储文件夹

mkdir /softwares/pyenv_for_airflow

cd pyenv_for_airflow/

创建python虚拟环境

virtualenv --no-site-packages airflow_env

赋权

chmod +x -R *

激活虚拟环境

cd bin

source ./activate

安装依赖组件

yum -y install gcc zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

yum -y install python-devel mysql-devel

yum -y install python3-devel

yum -y install cyrus-sasl cyrus-sasl-devel cyrus-sasl-lib

pip install paramiko

pip install pymysql

pip install sqlalchemy

vi /etc/profile

export AIRFLOW_HOME=/softwares/airflow

export SLUGIFY_USES_TEXT_UNIDECODE=yes

#即时生效

source /etc/profile

安装airflow,all全安装

pip install apache-airflow[all]

初始化数据库

cd /softwares/pyenv_for_airflow/airflow_env/lib/python3.7/site-packages/airflow/bin

./airflow initdb

查看其生成文件

cd /softwares/airflow/

创建mysql后台数据库

create database airflow_db default charset utf8 collate utf8_general_ci;

create user 'airflow'@'%' identified by 'airflow_db';

create user 'airflow'@'localhost' identified by 'airflow_db';

grant all on airflow_db.* to 'airflow'@'%';

flush privileges;

-----------------------------------------utf8mb4字符的---------------------------------------------------------------

create database airflow_db default charset utf8mb4 collate utf8mb4_unicode_ci;

create user 'airflow'@'%' identified by 'airflow_db';

create user 'airflow'@'localhost' identified by 'airflow_db';

grant all on airflow_db.* to 'airflow'@'%';

flush privileges;

配置airflow使用LocalExecutor执行器,及使用MySQL数据库

vi airflow/airflow.cfg

executor = LocalExecutor

sql_alchemy_conn = mysql://root:123456@airflow.mn01:3306/airflow_db

[webserver]

base_url = http://airflow.mn01:8085

web_server_port = 8085

时区

default_timezone = Asia/Shanghai

还需要修改3个文件

#1、修改webserver页面上右上角展示的时间:

vi ${PYTHON_HOME}/lib/python3.7/site-packages/airflow/www/templates/admin/master.html

var UTCseconds = (x.getTime() + x.getTimezoneOffset()*60*1000);

$("#clock").clock({

"dateFormat":"Y-m-d ",

"timeFormat":"H:i:s %UTC%",

"timestamp":UTCseconds

}).click(function(){

alert('{{ hostname }}');

});

改为:

var UTCseconds = x.getTime();

$("#clock").clock({

"dateFormat":"Y-m-d ",

"timeFormat":"H:i:s",

"timestamp":UTCseconds

}).click(function(){

alert(

#2、修改airflow/utils/timezone.py

#在 utc = pendulum.timezone('UTC') 这行(第27行)代码下添加

from airflow import configuration as conf

try:

tz = conf.get("core", "default_timezone")

if tz == "system":

utc = pendulum.local_timezone()

else:

utc = pendulum.timezone(tz)

except Exception:

pass

#修改utcnow()函数 (在第69行)

#d = dt.datetime.utcnow()

d = dt.datetime.now()

#3、修改airflow/utils/sqlalchemy.py

#在utc = pendulum.timezone('UTC') 这行(第37行)代码下添加

from airflow import configuration as conf

try:

tz = conf.get("core", "default_timezone")

if tz == "system":

utc = pendulum.local_timezone()

else:

utc = pendulum.timezone(tz)

except Exception:

pass

重新初始化数据库

./airflow initdb

启动服务

cd /softwares/pyenv_for_airflow/airflow_env/lib/python3.7/site-packages/airflow/bin

./airflow webserver -D

可能错误

错误1:启动可能报错:FileNotFoundError: [Errno 2] No such file or directory: 'gunicorn' ,找不到gunicorn。

airflow webserver启动时,会调用subprocess.Popen创建子进程,webserver使用gunicorn,启动参数:

1: ['gunicorn', '-w', '4', '-k', 'sync', '-t', '120', '-b', '0.0.0.0:8080', '-n', 'airflow-webserver', '-p', '/home/admin/airflow/airflow-webserver.pid', '-c', 'airflow.www.gunicorn_config', '--access-logfile', '-', '--error-logfile', '-', 'airflow.www.app:cached_app()']

执行gunicorn启动时,因为在PATH中找不到该命令报错。

创建gunicorn软连接

ln –fs /home/admin/python3.6/bin/gunicorn/bin/gunicorn /bin/gunicorn

或者将/usr/local/python3/bin添加到PATH,export PATH=$PATH:/usr/local/python3/bin

#即使生效

source /etc/profile

错误2:有可能会启动不了,可以查看err日志,

一般报错什么pid已经存在,这时候需要删除airflow目录下的airflow-webserver-monitor.pid文件

启动其它服务

./airflow scheduler -D

./airflow worker -D

#启动flower

./airflow flower-D

默认的端口为 5555,您可以在浏览器地址栏中输入 "http://hostip:5555" 来访问 flower ,对 celery 消息队列进行监控。

设置开机启动服务

#1、创建启动shell脚本

cd /softwares/

mkdir shellscripts

cd shellscripts/

touch startairflow.sh

vi startairflow.sh

#!/bin/bash

# chkconfig: 2345 10 90

# description:airflow开机自启脚本

#因为pid文件存在启动会报错,所以启动服务前先判定是否存在pid文件,存在删除先

airflow_path="/softwares/airflow/"

airflow_webserver_monitor_name="airflow-webserver-monitor.pid"

airflow_webserver_pid_name="airflow-webserver.pid"

airflow_scheduler_pid_name="airflow-scheduler.pid"

airflow_worker_pid_name="airflow-worker.pid"

if [ -x "$airflow_path" ]; then

echo "$airflow_path existed"

cd "$airflow_path"

if [ -f "$airflow_webserver_monitor_name" ]; then

echo "$airflow_webserver_monitor_name existed, i can delete it"

rm -rf "$airflow_webserver_monitor_name"

fi

if [ -f "$airflow_webserver_pid_name" ]; then

echo "$airflow_webserver_pid_name existed, i can delete it"

rm -rf "$airflow_webserver_pid_name"

fi

if [ -f "$airflow_scheduler_pid_name" ]; then

echo "$airflow_scheduler_pid_name existed, i can delete it"

rm -rf "$airflow_scheduler_pid_name"

fi

if [ -f "$airflow_worker_pid_name" ]; then

echo "$airflow_worker_pid_name existed, i can delete it"

rm -rf "$airflow_worker_pid_name"

fi

fi

#进入python虚拟环境

cd /softwares/pyenv_for_airflow/airflow_env/bin

#激活虚拟环境

source ./activate

#启动相应的airflow 服务

/softwares/pyenv_for_airflow/airflow_env/lib/python3.7/site-packages/airflow/bin/airflow webserver -D

/softwares/pyenv_for_airflow/airflow_env/lib/python3.7/site-packages/airflow/bin/airflow scheduler -D

#LocalExecutor模式不需要启动worker

#/softwares/pyenv_for_airflow/airflow_env/lib/python3.7/site-packages/airflow/bin/airflow worker -D

#2、将bash脚本cp到inti.d

sudo cp startairflow.sh /etc/init.d/startairflow

#3、加入到自启动中

#增加执行权限

cd /etc/init.d/

sudo chmod +x startairflow

#加入自动启动

sudo chkconfig startairflow on

#查看是否增加到自启动,2345为on即设置OK

chkconfig --list

将airflow命令加入PATH系统变量中,不需要每次指定到airflow bin目录下执行

sudo vi /etc/profile

#增加如下内容到末尾

export AIRFLOW_CLI_HOME=/usr/local/python3/lib/python3.7/site-packages/airflow/

export PATH=$PATH:$AIRFLOW_CLI_HOME/bin

#立即生效

source /etc/profile

如果您觉得此文章对您有帮助,请点击右下方【推荐】让更多人看到,thanks!

【原创】CentOS 7 安装airflow的更多相关文章

  1. CentOS 7 安装 vmware-tools

    [原创]标题:<CentOS 7 安装 vmware-tools>:作者:肖雪峰,QQ:35360657. 用 VMware Workstation 11 新安装了CentOS 7虚拟机, ...

  2. 如何在centos上安装epel源

    一.EPEL是什么? EPEL (Extra Packages for Enterprise Linux,企业版Linux的额外软件包) 是Fedora小组维护的一个软件仓库项目,为RHEL/Cent ...

  3. 于CentOS 6 安装 Wordpress

    1.两种方式给Wordpress 首先,你可以去wordpress最新的官方网站看看wordpress多少下载.例wordpress 3.9.1下载地址: http://cn.wordpress.or ...

  4. centos 下安装jdk、tomcat 以及tomcat无法从外部访问的解决办法

    centos 下安装jdk.tomcat 以及tomcat无法从外部访问的解决办法 原创 2014年08月28日 10:24:33 标签: selinux enforce cent 2223 昨天在c ...

  5. (转)CentOS 7 安装 Docker

    原文:http://www.cnblogs.com/stulzq/p/7743073.html http://www.cnblogs.com/stulzq/p/8629165.html-------- ...

  6. CentOS 下安装 LEMP 服务(nginx、MariaDB/MySQL 和 php)

    转载自:https://linux.cn/article-4314-1.html 编译自:http://xmodulo.com/install-lemp-stack-centos.html 作者: D ...

  7. [乐意黎原创]Centos 7里apache(httpd)自启动

    最近,Aerchi在折腾 ECS服务器 (Centos 7),每次重启后都要手动开启apache服务,好繁琐. 仔细研究了下:Apache 的服务第一.启动.终止.重启systemctl start ...

  8. CentOS7安装Airflow

    实验环境: centos7python3.6 安装配置: 1.看看是否有gcc,没有的话需要进行安装: yum install gcc  (后续安装airflow如果不成功,可以再次执行,它会更新包) ...

  9. [转帖]CentOS 7安装并启动Google浏览器(★firecat亲测有效★)

    CentOS 7安装并启动Google浏览器(★firecat亲测有效★) https://blog.csdn.net/libaineu2004/article/details/82821405 自己 ...

随机推荐

  1. bayaim_今晚打老虎

    bayaim_2018年11月22日11:01:14 <<<--- 再牛逼的肖邦,也尼玛弹奏不出我内心的悲伤.--->>> 艹,今天想骂人,艹TMD自己,不小心把自 ...

  2. iPad替代midi键盘

    下载安装rtpMIDI (网络MIDI驱动程序) 打开rtpMIDI,在“My session”那里按下+,就会自动显示你的电脑的名字 检查Bonjour服务正常运行,iPad与pc网络正常连接 iP ...

  3. 3、mongoDB索引

    创建索引: db.imooc_collection.getIndexes() 查看索引情况 db.imooc_collection.ensureIndex({x:1}) 创建索引,x:1代表正向排序, ...

  4. ue4 FString 中文乱码问题

    使用FString出现乱码,最简单的情况,FString Str = "你好"; 这时候就会出现乱码,解决方法是改成这样 FString Str = TEXT("你好&q ...

  5. linux下查看程序占用多少内存

    执行 ps auxVSZ(或VSS)列 表示,程序占用了多少虚拟内存:RSS列 表示, 程序占用了多少物理内存:虚拟内存可以不用考虑,它并不占用实际物理内存. 或执行top 命令 VIRT(或VSS) ...

  6. C C++ ARM X86 函数 方法 的调用约定

    参考:https://bbs.pediy.com/thread-224583.htm 整理成表格方便查询 cdecl(C规范), stdcall(WinAPI默认), fastcall, ATPCS( ...

  7. alertmanager

    alertmanager主要用于接收prometheus发送的告警信息: wget下载,解压, 配置alertmanager.yml,内容如下: 在prometheus文件下添加rules.yml内容 ...

  8. C++中的C

    前言 因为C++是以C为基础的,所以要用C++编程就必须熟悉C的语法. C语言的学习可以学习K & R C的<C程序设计语言> 创建函数 Q: 函数原型? A: 标准C/C++有一 ...

  9. Log日志级别从高到低排序 ERROR、WARN、INFO、DEBUG

    Log4j建议只使用四个级别,优先级从高到低分别是 ERROR.WARN.INFO.DEBUG.通过在这里定义的级别,您可以控制到应用程序中相应级别的日志信息的开关.比如在这里定义了INFO级别,则应 ...

  10. 对比3种接口测试的工具:jmeter+ant;postman;python的requests+unittest或requests+excel

    这篇随笔主要是对比下笔者接触过的3种接口测试工具,从实际使用的角度来分析下3种工具各自的特点 分别为:jmeter.postman.python的requests+unittest或requests+ ...