在 centos 7 上安装和配置 supervisord 以永久运行 Laravel 队列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45224707/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Install and configure supervisord on centos 7 to run Laravel queues permanently
提问by Tohid Dadashnezhad
I want to use Laravel queue system in my project and I want to run php artisan queue:workpermanently on server's background, I did some searches about this and I found a command line which can run it even after quit from ssh terminal but It can be down in some cases and can make terrible problems for me. So after a while I found out that there is a package named Supervisord which can restart command even after server is rebooted. So I want to ask someone to help from 0 to 100 step by step how to install Supervisord and configure it on centos 7 and after that set the queue command line. Thank you so much..
我想在我的项目中使用 Laravel 队列系统,我想在服务器的后台运行php artisan queue:work永久,我对此做了一些搜索,我找到了一个命令行,即使从 ssh 终端退出后也可以运行它,但它可以在某些情况下会沮丧,会给我带来可怕的问题。所以过了一段时间我发现有一个名为 Supervisord 的包,即使在服务器重新启动后它也可以重新启动命令。所以我想请人从0到100分步帮助如何安装Supervisord并在centos 7上配置它,然后设置队列命令行。非常感谢..
回答by Abdu
here is how to install and config supervisord on centos 7 to run Laravel queues permanently:
以下是如何在 centos 7 上安装和配置 supervisord 以永久运行 Laravel 队列:
easy_install supervisor
yum install supervisor
vim /etc/supervisord.conf
edit section program as following:
easy_install supervisor
yum install supervisor
vim /etc/supervisord.conf
编辑截面程序如下:
[program:laravel-worker] command=php /path/to/app.com/artisan queue:work process_name=%(program_name)s_%(process_num)02d numprocs=8 priority=999 autostart=true autorestart=true startsecs=1 startretries=3 user=apache redirect_stderr=true stdout_logfile=/path/to/log/worker.log
[program:laravel-worker] command=php /path/to/app.com/artisan queue:work process_name=%(program_name)s_%(process_num)02d numprocs=8 priority=999 autostart=true autorestart=true startsecs=1 startretries=3 user=apache redirect_stderr=true stdout_logfile=/path/to/log/worker.log
systemctl enable supervisord
to autorun at startsystemctl restart supervisord
to restart the service
systemctl enable supervisord
在开始时自动运行systemctl restart supervisord
重新启动服务
回答by Chris
Hopefully this will be of use to someone, this is the process I have been through in addition to @Abdu's answer to get things working on CentOS 7.
希望这对某人有用,这是除了@Abdu 的回答之外我还经历过的过程,以便在 CentOS 7 上工作。
1. Install Supervisor
1.安装Supervisor
easy_install supervisor
easy_install supervisor
* If not installed, run yum install -y python-setuptools
and then easy_install supervisor
* 如果没有安装,运行yum install -y python-setuptools
然后easy_install supervisor
2. Prep work
2. 准备工作
To get the ideal setup running, you should run the following...
要运行理想的设置,您应该运行以下...
# create directory for supervisor logs
mkdir /var/log/supervisor
# create directory for supervisor configs
mkdir -p /etc/supervisor/conf.d
# create config directory for supervisor
cat <<EOT >> /etc/supervisor/supervisord.conf
; supervisor config file
[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/var/log/supervisor ; ('AUTO' child log dir, default $TEMP)
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix socket
[include]
files = /etc/supervisor/conf.d/*.conf
EOT
# create systemctl service script
cat <<EOT >> /lib/systemd/system/supervisord.service
[Unit]
Description=Supervisor process control system for UNIX
Documentation=http://supervisord.org
After=network.target
[Service]
ExecStart=/usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf
ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown
ExecReload=/usr/bin/supervisorctl -c /etc/supervisor/supervisord.conf $OPTIONS reload
KillMode=process
Restart=on-failure
RestartSec=50s
[Install]
WantedBy=multi-user.target
EOT
Once you've done this, you should now be able to start and stop supervisor using systemctl. To start systemctl, run systemctl start supervisord
. To view the status of supervisor, run systemctl status supervisord
.
完成此操作后,您现在应该能够使用 systemctl 启动和停止主管。要启动 systemctl,请运行systemctl start supervisord
. 要查看主管的状态,请运行systemctl status supervisord
。
You can create as many custom configurations as you like under /etc/supervisor/conf.d
您可以根据需要创建任意数量的自定义配置 /etc/supervisor/conf.d
3. Enable on system startup
3.在系统启动时启用
You should also enable supervisord on startup by running
您还应该通过运行在启动时启用 supervisord
systemctl enable supervisord
回答by kregus
On my Bluehost account systemctl
was not running, but instead chkserv
was used to monitor and restart processes, so the two answers here did not fully work for me.
我的 Bluehost 帐户systemctl
没有运行,而是chkserv
用于监视和重新启动进程,因此这里的两个答案对我来说并不完全适用。
Also, I ran into an error with easy_install supervisor
, since it tried to install the new 4.x.x version, which requires Python > 2.6
, while 2.6 was the exact version of Python running on my machine.
另外,我遇到了一个错误easy_install supervisor
,因为它试图安装新的 4.xx 版本,这需要Python > 2.6
,而 2.6 是我机器上运行的 Python 的确切版本。
Here is what worked for me:
这是对我有用的:
yum install -y python-setuptools
easy_install supervisor==3.4.0
nano /etc/supervisord.conf
and add
yum install -y python-setuptools
easy_install supervisor==3.4.0
nano /etc/supervisord.conf
并添加
[supervisord]
nodaemon=true
[include]
files = /etc/supervisor/conf.d/*.conf
[program:laravel-worker]
command=php artisan queue:work --tries=1
autostart=true
autorestart=true
stderr_logfile=/var/log/queue.err.log
stdout_logfile=/var/log/queue.out.log
nano /etc/chkserv.d/chkservd.conf
, add the linesupervisord:1
, and then save the filetouch /etc/chkserv.d/supervisord
to create chkservd config filenano /etc/chkserv.d/supervisord
, add the lineservice[supervisord]=x,x,x,service supervisord restart,supervisord,root
, and then save the filesupervisord
will now show up in WHM underService Manager
, andchkservd
will start it and make sure it keeps running, but to manually start it, simply runsupervisord
nano /etc/chkserv.d/chkservd.conf
,添加行supervisord:1
,然后保存文件touch /etc/chkserv.d/supervisord
创建 chkservd 配置文件nano /etc/chkserv.d/supervisord
,添加行service[supervisord]=x,x,x,service supervisord restart,supervisord,root
,然后保存文件supervisord
现在将显示在 WHM 下Service Manager
,chkservd
并将启动它并确保它继续运行,但要手动启动它,只需运行supervisord
For more information on adding a service to chkservd
, click here.
有关向 中添加服务的更多信息chkservd
,请单击此处。