Skip to content

Instantly share code, notes, and snippets.

@diggzhang
Created August 10, 2018 04:17
Show Gist options
  • Save diggzhang/08b8a41d906ae7800ada04e24daff8a1 to your computer and use it in GitHub Desktop.
Save diggzhang/08b8a41d906ae7800ada04e24daff8a1 to your computer and use it in GitHub Desktop.

基础依赖安装

为了防止系统依赖污染,选择使用virtualenv方式安装。

基础工具组主要是pyenv + pyenv-virtualenv:

git clone https://github.com/pyenv/pyenv.git ~/.pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshenv
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshenv
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.zshenv
exec "$SHELL"
pyenv
git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.zshenv
exec "$SHELL"

然后通过pyenv安装合适版本的python,CentOS 7下直接装2.7会有问题,选用2.7.10:

pyenv install 2.7.10
pyenv virtualenv 2.7.10 airflow_env_py27

退出一次当前的shell环境,在airflow home下执行:

cd ~/airflow || exit 1
pyenv local airflow_env_py27
pip install apache-airflow

Airflow配置

接下来主要参考Airflow - Setting up a Backend完成后续配置:

pip install "apache-airflow[crypto]"

获取fernet_key后放到airflow.cfg中:

from cryptography.fernet import Fernet
fernet_key= Fernet.generate_key()
print(fernet_key) # your fernet_key, keep it in secured place!

MYSQL+执行器

默认的执行器使用sqlite,不支持并行任务,通过airflow.cfg中更改配置切换执行器。

首先创建针对airflow的用户和数据库,并设置相关权限:

mysql> CREATE DATABASE airflow;
mysql> GRANT all privileges on airflow.* TO 'airflow'@'localhost' IDENTIFIED BY 'unitedmaster';
mysql> FLUSH PRIVILEGES;

然后在cfg中改执行器和sqla的链接:

executor = LocalExecutor
sql_alchemy_conn = mysql://airflow:unitedmaster@localhost/airflow

测试

airflow webserver -p 8089
airflow scheduler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment