supervisor起動celeryおよび起動中の問題

3860 ワード

一、前言


このチュートリアルではsupervisorの構成手順に重点を置きます.celeryのインストール構成は他のチュートリアルを参照してください.

二、supervisorのインストール


1.インストールコマンド
pip install supervisor#supervisorは現在python 2のみサポートされていますが、コンテナとしてはモニタがpython 3のプログラムであることには影響しません.
2.プロファイル生成コマンドの実行
echo_supervisord_conf >/etc/supervisord.conf
3.プロファイル作成に必要なフォルダ
mkdir /var/log/celery/
mkdir /var/log/celery/
mkdir /var/log/supervisor/
mkdir /var/run/supervisor/
4.権限の変更
mkdir /var/log/celery/
mkdir /var/log/celery/
mkdir /var/log/supervisor/
mkdir /var/run/supervisor/
5.プロファイルの編集/etc/supervisord.confはcelery構成項目に追加されます(本構成ではbeatは使用されていません)
; ==================================
;  celery worker supervisor example
; ==================================

[program:celery]
;           (virtualenv )  celery      
command=/home/hiveme/env/cznews/bin/celery worker -A cznews --loglevel=INFO

; Alternatively,
;command=celery --app=your_app.celery:app worker --loglevel=INFO -n worker.%%h
; Or run a script
;command=celery.sh

directory=/home/hiveme/cznews/  ;      
user=nobody
numprocs=1
stdout_logfile=/var/log/celery/worker.log ;celery      
stderr_logfile=/var/log/celery/workererr.log ;celery      
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

; Causes supervisor to send the termination signal (SIGTERM) to the whole process group.
stopasgroup=true

; Set Celery priority higher than default (999)
; so, if rabbitmq is supervised, it will start first.
priority=1000


; ================================
;  celery beat supervisor example
; ================================

;[program:celerybeat]
; Set full path to celery program if using virtualenv
;command=/home/hiveme/env/cznews/bin/celery beat --schedule /var/lib/celery/beat.db --loglevel=INFO
;command=celery beat -A myapp --schedule /var/lib/celery/beat.db --loglevel=INFO ;the ordinary

; remove the -A myapp argument if you aren't using an app instance

;directory=/home/hiveme/cznews/
;user=nobody
;numprocs=1
;stdout_logfile=/var/log/celery/beat.log
;stderr_logfile=/var/log/celery/beaterr.log
;autostart=true
;autorestart=true
;startsecs=10

; Causes supervisor to send the termination signal (SIGTERM) to the whole process group.
;stopasgroup=true

; if rabbitmq is supervised, set its priority higher
; so it starts first
;priority=999

三、supervisorを起動する(root権限を使用する必要がある)


supervisord -c/etc/supervisord.conf

四、起動中の問題(supervisord.logとceleryのエラーログを表示)

サーバの再起動に注意
1.INFO spawnerr: can't find command 'celery'(supervisord.log)
ソリューション:
celeryが仮想環境にインストールされているかどうかを確認し、プロファイルですべてのceleryのコマンドを完全なパスに変更する必要がある場合は
2.INFO spawnerr: unknown error making dispatchers for 'celery': EACCES(supervisord.log)
主にログファイルを操作する権限がありません
ソリューション:
chown youruser:youruser -R/var/log/supervisor/
chown youruser:youruser -R/var/run/supervisor/
chown youruser:youruser -R/var/log/celery/
chown youruser:youruser -R/var/log/celery/
3.exited: celery (exit status 127; not expected)(supervisord.log)
このログは間違っています.ネット上では127というコマンドは合法ではありませんが、コマンドを単独で外部に持ち出して実行することもできます.celeryログを見てみると、supervisor:couldn't setuid to 65534:Can't drop privilege as nonroot usersupervisor:child process was not spawned
それとも権限の問題なのか、
ソリューション:
現在はroot運用で解決されており、より良い方法のあるパートナーはみんなと交流することができます.
4.supervisorctl: error: , [Errno 101] Network is unreachable: file:/data/openfalcon/open-falcon/python/lib/python2.7/socket.py line: 575
ソリューション
supervisorctlを実行するときにプロファイルを指定してこそ、supervisorctlを正常に実行できます.そうしないと、supervisorctlのデフォルトは/etc/supervisordです.confは構成を読み取り、エラーを引き起こします.
supervisorctl -c your/path/to/your/conf