Airflow BashOperator OSError:[Errno 2]没有这样的文件或目录

问题描述 投票:0回答:3

我不断从当前正在回填的预定 BashOperator 中收到相同的错误(“落后”了一个多月)。

[2018-06-10 22:06:33,558] {base_task_runner.py:115} INFO - Running: ['bash', '-c', u'airflow run dag_name task_name 2018-03-14T00:00:00 --job_id 50 --raw -sd DAGS_FOLDER/dag_file.py']
Traceback (most recent call last):
  File "/anaconda/bin//airflow", line 27, in <module>
    args.func(args)
  File "/anaconda/lib/python2.7/site-packages/airflow/bin/cli.py", line 387, in run
    run_job.run()
  File "/anaconda/lib/python2.7/site-packages/airflow/jobs.py", line 198, in run
    self._execute()
  File "/anaconda/lib/python2.7/site-packages/airflow/jobs.py", line 2512, in _execute
    self.task_runner.start()
  File "/anaconda/lib/python2.7/site-packages/airflow/task_runner/bash_task_runner.py", line 29, in start
    self.process = self.run_command(['bash', '-c'], join_args=True)
  File "/anaconda/lib/python2.7/site-packages/airflow/task_runner/base_task_runner.py", line 120, in run_command
    universal_newlines=True
  File "/anaconda/lib/python2.7/subprocess.py", line 394, in __init__
    errread, errwrite)
  File "/anaconda/lib/python2.7/subprocess.py", line 1047, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory
[2018-06-10 22:06:33,633] {sequential_executor.py:47} ERROR - Failed to execute task Command 'airflow run dag_name task_name 2018-03-14T00:00:00 --local -sd /var/lib/airflow/dags/dag_file.py' returned non-zero exit status 1.

我记得看到一些内容表明这可能是权限问题,但我无法弄清楚可能涉及哪些权限。

我正在使用 systemd 配置——在我无能为力的情况下——我已经开始以 root 身份运行气流网络服务器和调度程序。

我可以将第一行中的列表逐字输入到 ipython shell 中作为 subprocess.Popen 实例的参数(就像在

airflow/task_runner/base_task_runner.py
中一样;不保存环境),它不仅会运行,而且会正确地通知airflow db 表明任务已完成。我可以以 Airflow、root 或 ubuntu 用户身份执行此操作。

我已将

/anaconda/bin
添加到 .bashrc 中 Airflow、root、ubuntu 和
/etc/bash.bashrc
的 PATH 中,此外还有 AIRFLOW_HOME 的值,该值也在我的环境文件
/etc/airflow
中。

这就是我的 systemd 条目的样子:

[Unit]
Description=Airflow scheduler daemon
After=network.target postgresql.service mysql.service redis.service rabbitmq-server.service
Wants=postgresql.service mysql.service redis.service rabbitmq-server.service    

[Service]
EnvironmentFile=/etc/airflow
User=root
Group=root
Type=simple
ExecStart=/anaconda/bin/airflow scheduler
Restart=always
RestartSec=5s    

[Install]
WantedBy=multi-user.target

我的环境文件:

PATH=$PATH:/anaconda/bin/
AIRFLOW_HOME=/var/lib/airflow
AIRFLOW_CONFIG=$AIRFLOW_HOME/airflow.cfg

使用 apache-airflow==1.9.0 并迫切需要解决方案。预先感谢。

气流.cfg:

[core]
airflow_home = /var/lib/airflow
dags_folder = /var/lib/airflow/dags
base_log_folder = /var/lib/airflow/logs
remote_log_conn_id =
encrypt_s3_logs = False
logging_level = INFO
logging_config_class =
log_format = [%%(asctime)s] {%%(filename)s:%%(lineno)d} %%(levelname)s - %%(message)s
simple_log_format = %%(asctime)s %%(levelname)s - %%(message)s
executor = SequentialExecutor
sql_alchemy_conn = {actual value hidden}
sql_alchemy_pool_size = 5
sql_alchemy_pool_recycle = 3600
parallelism = 4
dag_concurrency = 2
dags_are_paused_at_creation = True
non_pooled_task_slot_count = 16
max_active_runs_per_dag = 1
load_examples = False
plugins_folder = /var/lib/airflow/plugins
fernet_key = {actual value hidden}
donot_pickle = False
dagbag_import_timeout = 30
task_runner = BashTaskRunner
default_impersonation =
security =
unit_test_mode = False
task_log_reader = file.task
enable_xcom_pickling = True
killed_task_cleanup_time = 60
[cli]
api_client = airflow.api.client.local_client
endpoint_url = http://localhost:8080
[api]
auth_backend = airflow.api.auth.backend.default
[operators]
default_owner = root
default_cpus = 1
default_ram = 512
default_disk = 512
default_gpus = 0
[webserver]
base_url = http://localhost:8080
web_server_host = 0.0.0.0
web_server_port = 8080
web_server_ssl_cert =
web_server_ssl_key =
web_server_worker_timeout = 120
worker_refresh_batch_size = 1
worker_refresh_interval = 60
secret_key = temporary_key
workers = 1
worker_class = sync
access_logfile = -
error_logfile = -
expose_config = False
authenticate = False
filter_by_owner = False
owner_mode = user
dag_default_view = tree
dag_orientation = LR
demo_mode = False
log_fetch_timeout_sec = 5
hide_paused_dags_by_default = False
page_size = 100
[email]
email_backend = airflow.utils.email.send_email_smtp
[smtp]
smtp_host = localhost
smtp_starttls = True
smtp_ssl = False
smtp_port = 25
smtp_mail_from = [email protected]
[celery]
...
[dask]
cluster_address = 127.0.0.1:8786
[scheduler]
job_heartbeat_sec = 120
scheduler_heartbeat_sec = 120
run_duration = -1
min_file_process_interval = 0
dag_dir_list_interval = 300
print_stats_interval = 300
child_process_log_directory = /var/lib/airflow/logs/scheduler
scheduler_zombie_task_threshold = 900
catchup_by_default = True
max_tis_per_query = 0
statsd_on = False
statsd_host = localhost
statsd_port = 8125
statsd_prefix = airflow
max_threads = 1
authenticate = False
[ldap]
...
[mesos]
...
[kerberos]
...
[github_enterprise]
...
[admin]
hide_sensitive_variable_fields = True

添加

ls -hal

root@ubuntu:/var/lib/airflow# ls -hal /var
total 52K
drwxr-xr-x 13 root root   4.0K Jun  3 11:58 .
root@ubuntu:/var/lib/airflow# ls -hal /var/lib
total 164K
drwxr-xr-x 42 root     root     4.0K Jun 10 19:00 .
root@ubuntu:/var/lib/airflow# ls -hal
total 40K
drwxr-xr-x  4 airflow airflow 4.0K Jun 11 06:41 .
drwxr-xr-x 42 root    root    4.0K Jun 10 19:00 ..
-rw-r--r--  1 airflow airflow  13K Jun 11 06:41 airflow.cfg
-rw-r--r--  1 airflow airflow  579 Jun 10 19:00 airflow.conf
drwxr-xr-x  2 airflow airflow 4.0K Jun 10 21:27 dags
drwxr-xr-x  4 airflow airflow 4.0K Jun 10 20:31 logs
-rw-r--r--  1 airflow airflow 1.7K Jun 10 19:00 unittests.cfg
root@ubuntu:/var/lib/airflow# ls -hal dags/
total 16K
drwxr-xr-x 2 airflow airflow 4.0K Jun 10 21:27 .
drwxr-xr-x 4 airflow airflow 4.0K Jun 11 06:41 ..
-rw-r--r-- 1 airflow airflow 3.4K Jun 10 21:26 dag_file.py
-rw-r--r-- 1 airflow airflow 1.7K Jun 10 21:27 dag_file.pyc

dag_file.py
的内容:

import airflow
from airflow import DAG
from airflow.operators.bash_operator import BashOperator
from datetime import datetime, timedelta
default_args = {
    'owner': 'root',
    'run_as': 'root',
    'depends_on_past': True,
    'start_date': datetime(2018, 2, 20),
    'email': ['[email protected]'],
    'email_on_failure': False,
    'email_on_retry': False,
    'retries': 1,
    'retry_delay': timedelta(minutes=5),
    'end_date': datetime(2018, 11, 15),
}
env = {
    'PSQL': '{obscured}',
    'PATH': '/anaconda/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin',
    'PWD': '/home/ubuntu/{obs1}/',
    'HOME': '/home/ubuntu',
    'PYTHONPATH': '/home/ubuntu/{obs1}',
}
dag = DAG(
    'dag_name',
    default_args=default_args,
    description='',
    schedule_interval=timedelta(days=1))
t1 = BashOperator(
    env=env,
    task_id='dag_file',
    bash_command='export PYTHONPATH=/home/ubuntu/{obs1} && /anaconda/bin/ipython $PYTHONPATH/{obs2}/{obs3}.py {{ ds }}',
    dag=dag)

我提醒你,这可以在airflow、root 和 ubuntu 上正确运行:

airflow run dag_name dag_file 2018-03-17T00:00:00 --job_id 55 --raw -sd DAGS_FOLDER/dag_file.py

python permissions airflow airflow-scheduler
3个回答
0
投票

看起来 python 版本不匹配,用正确的 python 版本编辑 .bashrc 并运行:

source .bashrc

这将解决您的问题。

对于我的情况,我们正在使用

export PATH="/opt/miniconda3/bin":$PATH

还要检查我如何做到这一点:

/opt/miniconda3/bin/python /opt/miniconda3/bin/airflow 

这就是我过去运行气流的方式。


0
投票

在 Airflow v1.10.0 上,您只需指定文件路径,末尾不再有空格。

示例:

compact_output_task = BashOperator(**{
    'task_id': 'compact_output',
    'bash_command': './compact_output.sh',
    'xcom_push': True,
})

0
投票

Systemd

EnvironmentFile
不会扩展其中的变量,因此您的
PATH
只会查看
/anaconda/bin
如果您只想扩展
PATH
最好使用

ExecStart=/bin/bash -c 'PATH=/path/to/venv/bin/:$PATH exec /path/to/airflow scheduler

这解决了我的问题,没有这样的文件或目录,因为气流找不到我在 bash 操作符中调用的二进制文件。

© www.soinside.com 2019 - 2024. All rights reserved.