gunicorn.service: 无法确定用户凭据:没有这样的进程 - django、gunicorn和nginx

5
当我运行sudo systemctl status gunicorn时,会出现以下错误:
● gunicorn.service - gunicorn daemon
   Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2022-02-08 07:29:18 UTC; 17min ago
 Main PID: 21841 (code=exited, status=217/USER)

Feb 08 07:29:18 ip-172-31-37-113 systemd[1]: Started gunicorn daemon.
Feb 08 07:29:18 ip-172-31-37-113 systemd[21841]: gunicorn.service: Failed to determine user credentials: No such process
Feb 08 07:29:18 ip-172-31-37-113 systemd[21841]: gunicorn.service: Failed at step USER spawning /home/ubuntu/bookclub/venv/bin/gun
Feb 08 07:29:18 ip-172-31-37-113 systemd[1]: gunicorn.service: Main process exited, code=exited, status=217/USER
Feb 08 07:29:18 ip-172-31-37-113 systemd[1]: gunicorn.service: Failed with result 'exit-code'.

我正在按照DigitalOcean的这篇教程将我的Django网站放到EC2实例上。我使用Nginx和Gunicorn与Django一起完成这个操作。

这是我位于/etc/systemd/system/gunicorn.servicegunicorn.service文件:

[Unit]
Description=gunicorn daemon
After=network.target

[Service]
User=sammy
Group=www-data
WorkingDirectory=/home/ubuntu/bookclub
ExecStart=/home/ubuntu/bookclub/venv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/ubuntu/bookclub/books.sock books.wsgi:application

[Install]
WantedBy=multi-user.target

我使用ls命令在我的项目文件夹中检查了books.sock,发现books.sock文件不存在

编辑

我将Gunicorn服务文件中的Usersammy(不存在)更改为ubuntu(是服务器上唯一存在的用户)。

所以我的gunicorn.service现在看起来是这样的:

[Unit]
Description=gunicorn daemon
After=network.target

[Service]
User=sammy
Group=www-data
WorkingDirectory=/home/ubuntu/bookclub
ExecStart=/home/ubuntu/bookclub/venv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/ubuntu/bookclub/books.sock books.wsgi:application

[Install]
WantedBy=multi-user.target

但我又遇到了另一个错误:

● gunicorn.service - gunicorn daemon
   Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2022-02-08 09:23:41 UTC; 19s ago
 Main PID: 22533 (code=exited, status=203/EXEC)

Feb 08 09:23:41 ip-172-31-37-113 systemd[1]: Started gunicorn daemon.
Feb 08 09:23:41 ip-172-31-37-113 systemd[1]: gunicorn.service: Main process exited, code=exited, status=203/EXEC
Feb 08 09:23:41 ip-172-31-37-113 systemd[1]: gunicorn.service: Failed with result 'exit-code'.

1
你确定那个系统上存在用户 sammy 吗?试着将 User=ubuntu 放进去(我记得这是亚马逊 EC2 Ubuntu 的默认用户)。 - undefined
谢谢,@SUTerliakov!这解决了错误“无法确定用户凭据”,但是systemctl status gunicorn显示gunicorn已经失败。我会编辑我的问题以包含这个信息。 - undefined
现在尝试运行sudo chown ubuntu /home/ubuntu/bookclub/venv/bin/gunicorn,看看是否有帮助。如果没有 - 还请提供journalctl --since="-1h"的输出内容。 - undefined
但我已经安装了它......我应该重新安装吗? - undefined
让我们在聊天中继续这个讨论。 - undefined
显示剩余2条评论
1个回答

1
你被误导了,因为在会话开始时有一个外部程序要遵循:初始服务器设置指南
要做的事情:
创建用户sammy
重要提示
usermod -aG sudo sammy

切换到sammy个人资料
在sammy个人资料下创建django项目
pwd
/home/sammy

一切都会顺利进行的。
原因可能是:1_可能是数据库用户的问题;2_可能是root配置文件无效。 只有上帝知道。 祝你好运。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接