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



我在EC2 CentOS中使用Airflow和systemd来管理用于启动气流进程的守护进程(即:Web服务器,worker和调度程序)。 当我跑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

气流-网络服务器.服务

[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

这无济于事。

更新

在创建一个airflow用户并在usr/local/bin下安装 Airflow 然后将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中,这是ec2-user的主目录。

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

相关内容

最新更新