3

버전 :AWS Elastic Beanstalk에서 샐러리 작업자를 실행하는 방법은 무엇입니까?

  • 장고 1.9.8
  • 2.7

내 셀러리 노동자를 실행하기 위해 노력하고있어 셀러리 3.1.23

  • 장고 - 셀러리 3.1.17
  • 파이썬 AWS Elastic Beanstalk에서 확인하십시오. 셀러리 중개인으로 Amazon SQS를 사용합니다. 내가 터미널에 다음 줄을 입력하면

    가 여기 내 settings.py

    INSTALLED_APPS += ('djcelery',) 
    import djcelery 
    djcelery.setup_loader() 
    BROKER_URL = "sqs://%s:%[email protected]" % (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY.replace('/', '%2F')) 
    

    , 그것은 내 로컬에 작업자를 시작합니다. 또한 몇 가지 작업을 만들었고 올바르게 실행되었습니다. AWS EB에서 어떻게해야합니까?

    python manage.py celery worker --loglevel=INFO 
    

    I에 유래에 this 질문을 발견했습니다. 배포 후에 스크립트를 실행하는 .ebextensions 폴더에 셀러리 구성을 추가해야한다고 나와 있습니다. 그러나 그것은 효과가 없습니다. 나는 어떤 도움을 주셔서 감사합니다. 관리자를 설치 한 후에는 아무 것도하지 않았습니다. 어쩌면 그게 내가 놓친거야. 다음은 스크립트입니다.

    files: 
        "/opt/elasticbeanstalk/hooks/appdeploy/post/run_supervised_celeryd.sh": 
        mode: "000755" 
        owner: root 
        group: root 
        content: | 
         #!/usr/bin/env bash 
    
         # Get django environment variables 
         celeryenv=`cat /opt/python/current/env | tr '\n' ',' | sed 's/export //g' | sed 's/$PATH/%(ENV_PATH)s/g' | sed 's/$PYTHONPATH//g' | sed 's/$LD_LIBRARY_PATH//g'` 
         celeryenv=${celeryenv%?} 
    
         # Create celery configuration script 
         celeryconf="[program:celeryd] 
         command=/opt/python/run/venv/bin/celery worker --loglevel=INFO 
    
         directory=/opt/python/current/app 
         user=nobody 
         numprocs=1 
         stdout_logfile=/var/log/celery-worker.log 
         stderr_logfile=/var/log/celery-worker.log 
         autostart=true 
         autorestart=true 
         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 rabbitmq is supervised, set its priority higher 
         ; so it starts first 
         ; priority=998 
    
         environment=$celeryenv" 
    
         # Create the celery supervisord conf script 
         echo "$celeryconf" | tee /opt/python/etc/celery.conf 
    
         # Add configuration script to supervisord conf (if not there already) 
         if ! grep -Fxq "[include]" /opt/python/etc/supervisord.conf 
          then 
          echo "[include]" | tee -a /opt/python/etc/supervisord.conf 
          echo "files: celery.conf" | tee -a /opt/python/etc/supervisord.conf 
         fi 
    
         # Reread the supervisord config 
         supervisorctl -c /opt/python/etc/supervisord.conf reread 
    
         # Update supervisord in cache without restarting all services 
         supervisorctl -c /opt/python/etc/supervisord.conf update 
    
         # Start/Restart celeryd through supervisord 
         supervisorctl -c /opt/python/etc/supervisord.conf restart celeryd 
    

    EB의 로그 : 작동하는 것처럼 보이지만 여전히 내 작업을 실행하지 않습니다.

    ------------------------------------- 
    /opt/python/log/supervisord.log 
    ------------------------------------- 
    2016-08-02 10:45:27,713 CRIT Supervisor running as root (no user in config file) 
    2016-08-02 10:45:27,733 INFO RPC interface 'supervisor' initialized 
    2016-08-02 10:45:27,733 CRIT Server 'unix_http_server' running without any HTTP authentication checking 
    2016-08-02 10:45:27,733 INFO supervisord started with pid 2726 
    2016-08-02 10:45:28,735 INFO spawned: 'httpd' with pid 2812 
    2016-08-02 10:45:29,737 INFO success: httpd entered RUNNING state, process has stayed up for > than 1 seconds (startsecs) 
    2016-08-02 10:47:14,684 INFO stopped: httpd (exit status 0) 
    2016-08-02 10:47:15,689 INFO spawned: 'httpd' with pid 4092 
    2016-08-02 10:47:16,727 INFO success: httpd entered RUNNING state, process has stayed up for > than 1 seconds (startsecs) 
    2016-08-02 10:47:23,701 INFO spawned: 'celeryd' with pid 4208 
    2016-08-02 10:47:23,854 INFO stopped: celeryd (terminated by SIGTERM) 
    2016-08-02 10:47:24,858 INFO spawned: 'celeryd' with pid 4214 
    2016-08-02 10:47:35,067 INFO success: celeryd entered RUNNING state, process has stayed up for > than 10 seconds (startsecs) 
    2016-08-02 10:52:36,240 INFO stopped: httpd (exit status 0) 
    2016-08-02 10:52:37,245 INFO spawned: 'httpd' with pid 4460 
    2016-08-02 10:52:38,278 INFO success: httpd entered RUNNING state, process has stayed up for > than 1 seconds (startsecs) 
    2016-08-02 10:52:45,677 INFO stopped: celeryd (exit status 0) 
    2016-08-02 10:52:46,682 INFO spawned: 'celeryd' with pid 4514 
    2016-08-02 10:52:46,860 INFO stopped: celeryd (terminated by SIGTERM) 
    2016-08-02 10:52:47,865 INFO spawned: 'celeryd' with pid 4521 
    2016-08-02 10:52:58,054 INFO success: celeryd entered RUNNING state, process has stayed up for > than 10 seconds (startsecs) 
    2016-08-02 10:55:03,135 INFO stopped: httpd (exit status 0) 
    2016-08-02 10:55:04,139 INFO spawned: 'httpd' with pid 4745 
    2016-08-02 10:55:05,173 INFO success: httpd entered RUNNING state, process has stayed up for > than 1 seconds (startsecs) 
    2016-08-02 10:55:13,143 INFO stopped: celeryd (exit status 0) 
    2016-08-02 10:55:14,147 INFO spawned: 'celeryd' with pid 4857 
    2016-08-02 10:55:14,316 INFO stopped: celeryd (terminated by SIGTERM) 
    2016-08-02 10:55:15,321 INFO spawned: 'celeryd' with pid 4863 
    2016-08-02 10:55:25,518 INFO success: celeryd entered RUNNING state, process has stayed up for > than 10 seconds (startsecs) 
    
  • +0

    귀하는 depression을 확인하기 위해 eb-tools.log에서 내려다 보았습니까 (http://stackoverflow.com/questions/12836834/where-and-how-to-read-results-of-ebextensions-execution 참조) 했습니까? ? –

    +0

    또한이 훅은 공식이 아니므로 조금 더 할 필요가 있습니다. http://junkheap.net/blog/2013/05/20/elastic-beanstalk-post-deployment- scripts/ –

    +0

    예, 공식적인 것은 아니지만 제가 언급 한 것처럼 누군가가 작동하도록했습니다. 나는 네가 보낸 것을보고 너에게 답장 할 것이다. 감사합니다. –

    답변

    2

    해결 후 답변을 추가하는 것을 잊었습니다. 이것이 내가 고쳐 놓은 방법입니다. 내 .ebextensions 폴더에 "99-celery.config"라는 새 파일을 만들었습니다. 이 파일에이 코드를 추가했으며 완벽하게 작동합니다.

    files: 
        "/opt/elasticbeanstalk/hooks/appdeploy/post/run_supervised_celeryd.sh": 
        mode: "000755" 
        owner: root 
        group: root 
        content: | 
         #!/usr/bin/env bash 
    
         # Get django environment variables 
         celeryenv=`cat /opt/python/current/env | tr '\n' ',' | sed 's/export //g' | sed 's/$PATH/%(ENV_PATH)s/g' | sed 's/$PYTHONPATH//g' | sed 's/$LD_LIBRARY_PATH//g'` 
         celeryenv=${celeryenv%?} 
    
         # Create celery configuraiton script 
         celeryconf="[program:celeryd] 
         ; Set full path to celery program if using virtualenv 
         command=/opt/python/current/app/molocate_eb/manage.py celery worker --loglevel=INFO 
    
         directory=/opt/python/current/app 
         user=nobody 
         numprocs=1 
         stdout_logfile=/var/log/celery-worker.log 
         stderr_logfile=/var/log/celery-worker.log 
         autostart=true 
         autorestart=true 
         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 rabbitmq is supervised, set its priority higher 
         ; so it starts first 
         priority=998 
    
         environment=$celeryenv" 
    
         # Create the celery supervisord conf script 
         echo "$celeryconf" | tee /opt/python/etc/celery.conf 
    
         # Add configuration script to supervisord conf (if not there already) 
         if ! grep -Fxq "[include]" /opt/python/etc/supervisord.conf 
          then 
          echo "[include]" | tee -a /opt/python/etc/supervisord.conf 
          echo "files: celery.conf" | tee -a /opt/python/etc/supervisord.conf 
         fi 
    
         # Reread the supervisord config 
         supervisorctl -c /opt/python/etc/supervisord.conf reread 
    
         # Update supervisord in cache without restarting all services 
         supervisorctl -c /opt/python/etc/supervisord.conf update 
    
         # Start/Restart celeryd through supervisord 
         supervisorctl -c /opt/python/etc/supervisord.conf restart celeryd 
    

    편집 (변화를 줄 번호 16에서 프로젝트 이름을 잊지 마세요 광산은 molocate_eb입니다) : AWS에 관리자 오류가 발생하는 경우, 그냥해야합니다;

    • 당신은 상사가 당신의 requirements.txt에 관리자를 추가하는 것을 잊지 마십시오
    • 파이썬 3에서 작동하지 않기 때문에 3 파이썬을하지 파이썬 2를 사용하고 있습니다.
    • 여전히 오류가 발생하면 ('나에게 일어난 일') '환경 재구성'만하면됩니다.
    +0

    ** ** celeryenv = $ {celeryenv %? ** **이게 무슨 일을합니까? –

    +0

    나는 스크립트를 작성하지 않았다. 당신은 질문에 작가를 찾을 수있다. –

    +0

    이 방법을 사용하면 문제를 해결할 수 있지만이 방법에는 하나의 중요한 문제가 있습니다. 이 파일은 deploy 훅 디렉토리 내에 남아 있으며 이전 응용 프로그램 버전으로 롤백하면 삭제되지 않습니다. 즉 내 앱의 V1이 배포되면 내 앱의 V2에 셀러리를 추가합니다. 배포 후 V2에 심각한 버그가 있으며 서버를 V1로 롤백해야한다는 사실을 알고 있습니다. 이 후크 스크립트가 post deploy 폴더에 계속 존재하지만 셀러리 코드가 더 이상 환경에 없기 때문에 beanstalk 환경에 V1을 배포하는 데 실패합니다. – brocksamson

    -3

    셀로리를 실행하려면 관리자를 사용할 수 있습니다. 그것은 악마 프로세스에서 샐러리를 실행합니다.

    [program:tornado-8002] 
    directory: name of the director where django project lies 
    command: command to run celery // python manage.py celery 
    stderr_logfile = /var/log/supervisord/tornado-stderr.log 
    stdout_logfile = /var/log/supervisord/tornado-stdout.log 
    
    +0

    정확하게 OP가하고있는 것이 었습니다 ... –

    관련 문제