gpt4 book ai didi

redis - 运行时警告 :You're running the worker with superuser privileges:this is absolutely not recommended

转载 作者:行者123 更新时间:2023-12-03 06:35:54 24 4
gpt4 key购买 nike

我在本地使用 django+celery+redis,celery==4.4.0 它工作正常但是当我对它进行 dockerizing 时,出现上述错误。

我正在使用以下命令在本地和容器内运行

**CMDs**
celery -A nrn worker -l info
docker run -d -p 6379:6379 redis
flower -A nrn --port=5555

任何帮助都受到高度赞赏

*设置.py**
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'

CELERY_BROKER_URL = os.environ.get('redis', 'redis://127.0.0.1:6379/')

最佳答案

看看 documentation .不过,这是一个警告,而不是错误(请参阅 code )。仅当您允许默认未启用的 pickle 序列化时,在 root 下运行 Celery 才会出错(请参阅 here )。

但是,以较低的权限运行 Celery 仍然是最佳实践。在 Docker(基于 Debian 的镜像)中,我选择在 nobody 下运行 Celery :nogroup .我用这个 Dockerfile :

FROM python:3.6

ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1

WORKDIR /srv/celery

COPY ./app app
COPY ./requirements.txt /tmp/requirements.txt
COPY ./celery.sh celery.sh

RUN pip install --no-cache-dir \
-r /tmp/requirements.txt

VOLUME ["/var/log/celery", "/var/run/celery"]

CMD ["./celery.sh"]

哪里 celery.sh如下所示:
#!/usr/bin/env bash

mkdir -p /var/run/celery /var/log/celery
chown -R nobody:nogroup /var/run/celery /var/log/celery

exec celery --app=app worker \
--loglevel=INFO --logfile=/var/log/celery/worker-example.log \
--statedb=/var/run/celery/worker-example@%h.state \
--hostname=worker-example@%h \
--queues=celery.example -O fair \
--uid=nobody --gid=nogroup

关于redis - 运行时警告 :You're running the worker with superuser privileges:this is absolutely not recommended,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59651428/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com