supervisor 啟動 celery 及啟動中的問題
阿新 • • 發佈:2018-12-30
一、前言
本教程重點在於supervisor的配置過程,celery的安裝配置請參考其他教程
二、安裝supervisor
1.安裝命令pip install supervisor # supervisor目前只支援python2,但是作為容器來說,並不影響監控程式是python3的程式
2.執行 配置檔案 生成命令
echo_supervisord_conf > /etc/supervisord.conf
3.建立配置檔案需要的資料夾
4.更改許可權mkdir /var/log/celery/ mkdir /var/log/celery/ mkdir /var/log/supervisor/ mkdir /var/run/supervisor/
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: <class 'socket.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