运行 使用 Systemd 的 EC2 Centos 上的 Airflow 网络服务器:权限被拒绝

run Airflow webserver on EC2 Centos using Systemd: Permission denied

我正在使用 Airflow in EC2 CentOS with systemd 来管理用于启动气流进程的守护进程(即:网络服务器、工作程序和调度程序)。 当我运行sudo systemctl start airflow-webserver

: ec2-user : TTY=pts/0 ; PWD=/ ; USER=root ; COMMAND=/bin/systemctl enable airflow-webserver
Oct 30 01:27:37 ip-171-32-6-92.us-east-2.compute.internal sudo[11680]: ec2-user : TTY=pts/0 ; PWD=/ ; USER=root ; COMMAND=/bin/systemctl start airflow-webserver
Oct 30 01:27:37 ip-171-32-6-92.us-east-2.compute.internal systemd[11684]: Failed at step EXEC spawning /home/ec2-user/.local/bin/airflow: Permission denied
Oct 30 01:27:37 ip-171-32-6-92.us-east-2.compute.internal systemd[1]: airflow-webserver.service: main process exited, code=exited, status=203/EXEC
Oct 30 01:27:37 ip-171-32-6-92.us-east-2.compute.internal systemd[1]: Unit airflow-webserver.service entered failed state.
Oct 30 01:27:37 ip-171-32-6-92.us-east-2.compute.internal systemd[1]: airflow-webserver.service failed

气流-webserver.service

[Unit]
Description=Airflow webserver 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/sysconfig/airflow
User=airflow
Group=airflow
Type=simple
ExecStart=/home/ec2-user/.local/bin/airflow webserver --pid /run/airflow/webserver.pid
RestartSec=5s
PrivateTmp=true

[Install]
WantedBy=multi-user.target

气流组和用户存在:

$ less /etc/group
# airflow:x:1001:ec2-user
$less etc/psswd
# ec2-user:x:1000:1000:EC2 Default User:/home/ec2-user:/bin/bash
# tss:x:59:59:Account used by the trousers package to sandbox the tcsd # daemon:/dev/null:/sbin/nologin
# airflow:x:1001:1001::/home/airflow:/bin/bash

THIS 没有帮助。

更新

在创建 airflow 用户并在 usr/local/bin 下安装气流然后将 ExecStart 更改为 usr/local/bin/airflow webserver --pid /run/airflow/webserver.pid 之后,我能够通过初始权限被拒绝。但是现在我得到这个错误:

Oct 31 18:44:12 ip-172-31-6-92.us-east-2.compute.internal airflow[31430]: PermissionError: [Errno 13] Permission denied: '${AIRFLOW_HOME}'
Oct 31 18:44:12 ip-172-31-6-92.us-east-2.compute.internal airflow[31430]: During handling of the above exception, another exception occurred:
Oct 31 18:44:12 ip-172-31-6-92.us-east-2.compute.internal airflow[31430]: Traceback (most recent call last):
Oct 31 18:44:12 ip-172-31-6-92.us-east-2.compute.internal airflow[31430]: File "/usr/local/bin/airflow", line 25, in <module>
Oct 31 18:44:12 ip-172-31-6-92.us-east-2.compute.internal airflow[31430]: from airflow.configuration import conf
Oct 31 18:44:12 ip-172-31-6-92.us-east-2.compute.internal airflow[31430]: File "/usr/local/lib/python3.7/site-packages/airflow/__init__.py", line 31, in <module>
Oct 31 18:44:12 ip-172-31-6-92.us-east-2.compute.internal airflow[31430]: from airflow.utils.log.logging_mixin import LoggingMixin
Oct 31 18:44:12 ip-172-31-6-92.us-east-2.compute.internal airflow[31430]: File "/usr/local/lib/python3.7/site-packages/airflow/utils/__init__.py", line 24, in <module>
Oct 31 18:44:12 ip-172-31-6-92.us-east-2.compute.internal airflow[31430]: from .decorators import apply_defaults as _apply_defaults
Oct 31 18:44:12 ip-172-31-6-92.us-east-2.compute.internal airflow[31430]: File "/usr/local/lib/python3.7/site-packages/airflow/utils/decorators.py", line 34, in <module>
Oct 31 18:44:12 ip-172-31-6-92.us-east-2.compute.internal airflow[31430]: from airflow import settings
Oct 31 18:44:12 ip-172-31-6-92.us-east-2.compute.internal airflow[31430]: File "/usr/local/lib/python3.7/site-packages/airflow/settings.py", line 36, in <module>
Oct 31 18:44:12 ip-172-31-6-92.us-east-2.compute.internal airflow[31430]: from airflow.configuration import conf, AIRFLOW_HOME, WEBSERVER_CONFIG  # NOQA F401
Oct 31 18:44:12 ip-172-31-6-92.us-east-2.compute.internal airflow[31430]: File "/usr/local/lib/python3.7/site-packages/airflow/configuration.py", line 523, in <module>
Oct 31 18:44:12 ip-172-31-6-92.us-east-2.compute.internal airflow[31430]: mkdir_p(AIRFLOW_HOME)
Oct 31 18:44:12 ip-172-31-6-92.us-east-2.compute.internal airflow[31430]: File "/usr/local/lib/python3.7/site-packages/airflow/configuration.py", line 505, in mkdir_p
Oct 31 18:44:12 ip-172-31-6-92.us-east-2.compute.internal airflow[31430]: 'Error creating {}: {}'.format(path, exc.strerror))
Oct 31 18:44:12 ip-172-31-6-92.us-east-2.compute.internal airflow[31430]: airflow.exceptions.AirflowConfigException: Error creating ${AIRFLOW_HOME}: Permission denied

这是因为您正在尝试 运行 作为 airflow 用户,但是 airflow 二进制文件的路径在 /home/ec2-user/.local/bin/airflow 中,这是 [=13] 的主目录=].

将 airflow 安装在您的 airflow 用户有权访问的目录中。