芹菜的生产设置



如何使用 AWS 或 digitalocean 在生产服务器中设置 Celery,并将代理设置为 Redis 或 Rabbitmq。

请详细说明我们如何在代理关闭时恢复连接拒绝错误。

对于那些仍然找到这个答案的人。

  • 在 AWS 中,您可以使用 elasticache(Redis),将此 Redis 集群与您的 EC2 实例连接,并从控制面板获取集群的主终端节点
  • 现在通过SSH密钥(使用腻子或mobaXterm)登录到您的ec2。
  • 现在在您的服务器上安装 Redis(无论您使用什么)
  • 安装后:
  • 键入redis-server它应该输出确定
  • 然后键入redis-cli -h <your redis cluster endpoint(assuming default port 6379)
  • 现在测试它PING它应该打印PONG

现在 redis 部分已完成 对于芹菜,考虑到你正在使用django

  • 导航到服务器中的此/etc/supervisor/conf.d/目录

  • 创建 celery.conf 文件(您可以随心所欲地命名它)并键入此内容

    ;  celery worker supervisor example
    ; ==================================
    ; the name of your supervisord program
    [program:myprojectcelery]
    ; Set full path to celery program if using virtualenv
    command=/home/ubuntu/.virtualenvs/myproject/bin/celery worker -A picha --loglevel=INFO
    ; The directory to your Django project
    directory=/home/ubuntu/myproject
    ; If supervisord is run as the root user, switch users to this UNIX user account
    ; before doing any processing.
    user=ubuntu(use your root user)
    ; Supervisor will start as many instances of this program as named by numprocs
    numprocs=1
    ; Put process stdout output in this file
    stdout_logfile=/var/log/celery/whatever_worker.log
    ; Put process stderr output in this file
    stderr_logfile=/var/log/celery/whatever_worker.log
    ; If true, this program will start automatically when supervisord is started
    autostart=true
    ; May be one of false, unexpected, or true. If false, the process will never
    ; be autorestarted. If unexpected, the process will be restart when the program
    ; exits with an exit code that is not one of the exit codes associated with this
    ; process’ configuration (see exitcodes). If true, the process will be
    ; unconditionally restarted when it exits, without regard to its exit code.
    autorestart=true
    ; The total number of seconds which the program needs to stay running after
    ; a startup to consider the start successful.
    startsecs=10
    ; Need to wait for currently executing tasks to finish at shutdown.
    ; Increase this if you have very long running tasks.
    stopwaitsecs = 600
    ; When resorting to send SIGKILL to the program to terminate it
    ; send SIGKILL to its whole process group instead,
    ; taking care of its children as well.
    killasgroup=true
    ; if your broker is supervised, set its priority higher
    ; so it starts first
    priority=998
    
  • 创建另一个文件celerybeat.conf并键入

    ;  celery beat supervisor example
    ; ================================
    ; the name of your supervisord program
    [program:celerybeat]
    ; Set full path to celery program if using virtualenv
    command=/home/ubuntu/.virtualenvs/myproject/bin/celerybeat -A picha --loglevel=INFO
    ; The directory to your Django project
    directory=/home/ubuntu/myproject
    ; If supervisord is run as the root user, switch users to this UNIX user account
    ; before doing any processing.
    user=mosh
    ; Supervisor will start as many instances of this program as named by numprocs
    numprocs=1
    ; Put process stdout output in this file
    stdout_logfile=/var/log/celery/whatever_beat.log
    ; Put process stderr output in this file
    stderr_logfile=/var/log/celery/whatever_beat.log
    ; If true, this program will start automatically when supervisord is started
    autostart=true
    ; May be one of false, unexpected, or true. If false, the process will never
    ; be autorestarted. If unexpected, the process will be restart when the program
    ; exits with an exit code that is not one of the exit codes associated with this
    ; process’ configuration (see exitcodes). If true, the process will be
    ; unconditionally restarted when it exits, without regard to its exit code.
    autorestart=true
    ; The total number of seconds which the program needs to stay running after
    ; a startup to consider the start successful.
    startsecs=10
    ; if your broker is supervised, set its priority higher
    ; so it starts first
    priority=999
    
  • 创建上述代码中提到的日志文件

    $ sudo touch /var/log/celery/whatever_beat.log
    
  • 现在让您的主管了解这些文件

    $ sudo supervisorctl update
    
  • 现在相应地使用这些命令

    $ sudo supervisorctl start myprojectcelery
    $ sudo supervisorctl status myprojectcelery
    

请参阅官方文档了解更多信息

相关内容

  • 没有找到相关文章

最新更新