yum -y install zlib zlib-devel
yum -y install bzip2 bzip2-devel
yum -y install ncurses ncurses-devel
yum -y install readline readline-devel
yum -y install openssl openssl-devel
yum -y install openssl-static
yum -y install xz lzma xz-devel
yum -y install sqlite sqlite-devel
yum -y install gdbm gdbm-devel
yum -y install tk tk-devel
yum install gcc
yum -y install wget
wget -P /root https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
tar -zxvf Python-3.6.5.tgz
cd
/root/Python-3.6.5
./configure --with-ssl --prefix=/service/python3
make install
mv
/usr/bin/python /usr/bin/python2.backup
ln
-s /service/python3/bin/python3 /usr/bin/python
ln
-s /service/python3//bin/pip3 /usr/bin/pip
python -V
pip install --upgrade pip
whereis yum
vi /usr/bin/yum /etc/yum /etc/yum.conf /usr/share/man/man8/yum.8
/usr/libexec/urlgrabber-ext-down
复制代码
3.安装MySQL
rpm -qa | grep mariadb
rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64
rpm -qa | grep mariadb
复制代码
#下载mysql的repo源
wget -P /root http:
#通过rpm安装
rpm -ivh mysql-community-release-el7-5.noarch.rpm
#安装mysql
yum install mysql-server
chown -R mysql:mysql /var/lib/mysql
#开启Mysql服务
service mysqld start
#用root用户连接登录mysql:
mysql -uroot
#重置mysql密码
use mysql;
update user set password=password('root') where user='root';
flush privileges;
#为Airflow建库、建用户
create database airflow;
#建用户:
create user 'airflow'@'%' identified by 'airflow';
create user 'airflow'@'localhost' identified by 'airflow';
#为用户授权:
grant all on airflow.* to 'airflow'@'%';
grant all on airflow.* to 'root'@'%';
flush privileges;
exit;
复制代码
4.安装Airflow
export SLUGIFY_USES_TEXT_UNIDECODE=yes
vi /etc/profile
----》
export PS1="[\u@\h \w]\$ "
export PYTHON_HOME=/service/python3
export PATH=$PATH:$PYTHON_HOME/bin
export AIRFLOW_HOME=/root/airflow
export SITE_AIRFLOW_HOME=/service/python3/lib/python3.6/site-packages/airflow
export PATH=$PATH:$SITE_AIRFLOW_HOME/bin
----》
source /etc/profile
pip install apache-airflow===1.10.0
复制代码
airflow会被安装到python3下的site-packages目录下,完整目录为:
${PYTHON_HOME}/lib/python3.6/site-packages/airflow
#绝对路径/service/python3/lib/python3.6/site-packages/airflow
复制代码
执行
airflow
命令做初始化操作
airflow
[2019-07-17 04:40:01,565] {__init__.py:51} INFO - Using executor SequentialExecutor
usage: airflow [-h]
{backfill,list_tasks,clear,pause,unpause,trigger_dag,delete_dag,pool,variables,kerberos,render,run,initdb,list_dags,dag_state,task_failed_deps,task_state,serve_logs,test,webserver,resetdb,upgradedb,scheduler,worker,flower,version,connections,create_user}
airflow: error: the following arguments are required: subcommand
[2019-07-17 04:40:01,565] {__init__.py:51} INFO - Using executor SequentialExecutor
usage: airflow [-h]
{backfill,list_tasks,clear,pause,unpause,trigger_dag,delete_dag,pool,variables,kerberos,render,run,initdb,list_dags,dag_state,task_failed_deps,task_state,serve_logs,test,webserver,resetdb,upgradedb,scheduler,worker,flower,version,connections,create_user}
airflow: error: the following arguments are required: subcommand
[root@test01 ~]$ cd airflow/
[root@test01 ~/airflow]$ ll
total 28
-rw-r--r--. 1 root root 20572 Jul 17 04:40 airflow.cfg
drwxr-xr-x. 3 root root 23 Jul 17 04:40 logs
-rw-r--r--. 1 root root 2299 Jul 17 04:40 unittests.cfg
复制代码
pip install 'apache-airflow[mysql]'
ERROR: Complete output from command python setup.py egg_info:
ERROR: /bin/sh: mysql_config: command not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-dq81ujxt/mysqlclient/setup.py", line 16, in <module>
metadata, options = get_config()
File "/tmp/pip-install-dq81ujxt/mysqlclient/setup_posix.py", line 51, in get_config
libs = mysql_config("libs")
File "/tmp/pip-install-dq81ujxt/mysqlclient/setup_posix.py", line 29, in mysql_config
raise EnvironmentError("%s not found" % (_mysql_config_path,))
OSError: mysql_config not found
----------------------------------------
ERROR: Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-dq81ujxt/mysqlclient/
[root@test01 ~]$ find / -name mysql_config
[root@test01 ~]$ yum -y install mysql-devel
find / -name mysql_config
pip install mysqlclient
pip install MySQLdb
Collecting MySQLdb
ERROR: Could not find a version that satisfies the requirement MySQLdb (from versions: none)
ERROR: No matching distribution found for MySQLdb
pip install pymysql
pip install cryptography
python -c "from cryptography.fernet import Fernet;
print(Fernet.generate_key().decode())"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'cryptography'
pip install cryptography
cd ${AIRFLOW_HOME}
vi airflow.cfg
/fernet_net
sql_alchemy_conn = mysql+mysqldb://airflow:airflow@localhost:3306/airflow
mysql --help | grep my.cnf
vi /etc/my.cnf
explicit_defaults_for_timestamp=true
#重启mysql服务使配置生效
service mysqld restart
#检查配置是否生效
mysql -uroot -proot
mysql> select @@global.explicit_defaults_for_timestamp;
+
| @@global.explicit_defaults_for_timestamp |
+
| 1 |
+
1 row in set (0.00 sec)
复制代码
Ⅰ.通过修改airflow.cfg调整配置
1修改webserver地址
base_url = http://192.168.150.128:8085
web_server_port = 8085
2修改executor
executor = CeleryExecutor
default_timezone = Asia/Shanghai
vi ${PYTHON_HOME}/lib/python3.6/site-packages/airflow/www/templates/admin/master.html
-----------------------------------
{% block tail_js %}
{{ super() }}
<script src="{{ url_for('static', filename='jqClock.min.js') }}" type="text/javascript"></script>
<script>
x = new Date()
// var UTCseconds = (x.getTime() + x.getTimezoneOffset()*60*1000)
var UTCseconds = x.getTime()
$("
vi ${PYTHON_HOME}/lib/python3.6/site-packages/airflow/models.py
-----------------------------------》
def utc2local(self,utc):
import time
epoch = time.mktime(utc.timetuple())
offset = datetime.fromtimestamp(epoch) - datetime.utcfromtimestamp(epoch)
return utc + offset
vi ${PYTHON_HOME}/lib/python3.6/site-packages/airflow/www/templates/airflow/dags.html
dag.utc2local(last_run.execution_date).strftime("%Y-%m-%d %H:%M")
dag.utc2local(last_run.start_date).strftime("%Y-%m-%d %H:%M")
4添加用户认证(暂时不做这一步,还没懂)
sudo pip install apache-airflow[password]
[webserver]
authenticate = True
auth_backend = airflow.contrib.auth.backends.password_auth
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 = 'test_airflow@wps.cn'
user.password = 'airflow'
session = settings.Session()
session.add(user)
session.commit()
session.close()
exit()
python add_account.py
复制代码
5修改scheduler线程数控制并发量
parallelism = 32
复制代码
6修改检测新DAG间隔
min_file_process_interval = 5
复制代码
Ⅱ.初始化源数据库及启动组件
pip install celery
pip install apache-airflow['kubernetes']
airflow initdb
#准备操作
#关闭linux防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
#同时需要关闭windows防火墙
#数据库设置
mysql -uroot -proot
mysql> set password for 'root'@'localhost' =password('');
Query OK, 0 rows affected (0.00 sec)
mysql> grant all on airflow.* to 'airflow'@'%';
Query OK, 0 rows affected (0.00 sec)
mysql> grant all on airflow.* to 'root'@'%';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit;
#启动组件:
airflow webserver -D
#airflow scheduler -D
#airflow worker -D
#airflow flower -D
复制代码
Ⅲ.Web页面查看
192.168.150.128:8085/admin/
可以选择airflow_db数据库简单查询进行测试
select * from log;
5.可能出现的ERROR
Error: 'python:airflow.www.gunicorn_config' doesn‘t exist
复制代码
安装指定版本的gunicorn即可:
(1) Airflow1.10版本对应gunicorn的19.4.0版本:
sudo pip install gunicorn==19.4.0
复制代码
(2) Airflow1.8版本安装gunicorn的19.3.0版本:
sudo pip install gunicorn==19.3.0
复制代码