Ubuntu 下 Supervisor 安装与配置

1,安装

$sudo apt-get install supervisor

2,配置

/etc/supervisor/supervisord.conf 一般不用动

3,创建子进程配置文件,修改权限

$ touch /etc/supervisor/conf.d/laravel-worker.conf

$ chmod -R 777 /etc/supervisor/conf.d/

一般配置:

[program:laravel-worker]

process_name=%(program_name)s

command=php /项目文件地址/artisan queue:work --sleep=3 --timeout=50 (这个配置需要替换,此处是我laravel 开启队列监听的指令)

autostart=true (自动开启)

autorestart=true (自动重启)

numprocs=1(同时开启进程数,进程数不同,上面的 process_name 配置也不同 为1 时是 %(program_name)s )

redirect_stderr=true

4,杀掉原有进程

$ps -ef | grep supervisor

$kill 9 (对应 pid 号)        |  例如 $kill 9 7381

root        6689        1  0 10:30 ?          00:00:00 /usr/bin/python /usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf
bitnami   7381  5967  0 11:06 pts/0    00:00:00 grep --color=auto supervisor

5,启动

$sudo supervisord –c /etc/supervisor/supervisord.conf (配置文件)
报错1:
bitnami@ip-172-31-33-147:/etc/supervisor/conf.d$supervisord -c /etc/supervisor/supervisord.conf

Traceback(most recent call last):

 File "/usr/bin/supervisord", line9, in

  load_entry_point('supervisor==3.2.0','console_scripts', 'supervisord')()

 File"/usr/lib/python2.7/dist-packages/supervisor/supervisord.py", line367, in main

  go(options)

 File"/usr/lib/python2.7/dist-packages/supervisor/supervisord.py", line377, in go

  d.main()

 File"/usr/lib/python2.7/dist-packages/supervisor/supervisord.py", line77, in main

  info_messages)

 File"/usr/lib/python2.7/dist-packages/supervisor/options.py", line 1388,in make_logger

  stdout = self.nodaemon,

 File"/usr/lib/python2.7/dist-packages/supervisor/loggers.py", line 346,in getLogger

  handlers.append(RotatingFileHandler(filename,'a',maxbytes,backups))

 File"/usr/lib/python2.7/dist-packages/supervisor/loggers.py", line 172,in __init__

  FileHandler.__init__(self, filename, mode)

 File"/usr/lib/python2.7/dist-packages/supervisor/loggers.py", line 98, in__init__

  self.stream = open(filename, mode)

IOError: [Errno 13]Permission denied: '/var/log/supervisor/supervisord.log'

解决方法: 更改/var/log/supervisor/supervisord.log 权限为 777

报错2:
bitnami@ip-172-31-33-147:/etc/supervisor$

supervisord -c /etc/supervisor/supervisord.conf

Error: Cannot open anHTTP server: socket.error reported errno.EACCES (13)

解决方法:更改 /var/run 文件夹的权限,这里注意是只更改这个文件夹的权限不要连里面的文件也更改,不要加–R 参数,不然会更改 ssh 秘钥权限,导致你上不去服务器,只能重启服务器,这里执行

$sudo chmod 777 /run 

(/var/run 是 /run 的软链接)

原文链接https://blog.csdn.net/weixin_33965305/article/details/92385494

/var/run 文件详解:https://blog.csdn.net/weixin_43279032/article/details/84302830?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.nonecase

6,重新加载配置文件,启动子进程守护进程

$sudo supervisorctl reread

$sudo supervisorctl update

$sudo supervisorctl start laravel-worker:*

你可能感兴趣的:(Ubuntu 下 Supervisor 安装与配置)