How to run celery workers by superuser?

老子叫甜甜 提交于 2019-12-20 03:30:39

问题


When I run celery workers with sudo, i get the following error:

Running a worker with superuser privileges when the
worker accepts messages serialized with pickle is a very bad idea!

If you really want to continue then you have to set the C_FORCE_ROOT
environment variable (but please think about this before you do).

User information: uid=0 euid=0 gid=0 egid=0

also my C_FORCE_ROOT environment variable is true:

echo $C_FORCE_ROOT
true

More information:
Python --> 2.7.6
celery --> 3.1.23 (Cipater)
OS --> Linux(Ubuntu 14.04)

How should I run celery with sudo? I know it's not secure but for some reasons I really need to do it!


回答1:


OK I found the solution!
In celery 3.1 and above, workers with pickle serialization will crash as mentioned in documentation:

Worker will now crash if running as the root user with pickle enabled.

So to use sudo, you need to disable pickle serialization in celery configs.I did it by using json:

app.conf.update(
     CELERY_ACCEPT_CONTENT = ['json'],
     CELERY_TASK_SERIALIZER = 'json',
     CELERY_RESULT_SERIALIZER = 'json',
)

and then if you run using sudo, it will work!



来源:https://stackoverflow.com/questions/37376684/how-to-run-celery-workers-by-superuser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!