【问题标题】:Install and configure supervisord on centos 7 to run Laravel queues permanently在 centos 7 上安装和配置 supervisord 以永久运行 Laravel 队列
【发布时间】:2017-12-26 17:46:54
【问题描述】:

我想在我的项目中使用 Laravel 队列系统,我想在服务器后台永久运行 php artisan queue:work,我对此进行了一些搜索,我找到了一个可以运行的命令行即使从 ssh 终端退出后它也会出现,但在某些情况下它可能会关闭,并且会给我带来可怕的问题。所以过了一会儿我发现有一个名为 Supervisord 的包,即使在服务器重新启动后也可以重新启动命令。所以我想请人从0到100一步一步地帮助如何安装Supervisord并在centos 7上配置它,然后设置队列命令行。非常感谢。。

【问题讨论】:

    标签: laravel centos7 supervisord laravel-queue


    【解决方案1】:

    在我的 Bluehost 帐户上,systemctl 没有运行,而是 chkserv 用于监视和重新启动进程,因此这里的两个答案对我来说并不完全有效。

    另外,我遇​​到了easy_install supervisor 的错误,因为它尝试安装新的 4.x.x 版本,这需要Python > 2.6,而 2.6 是在我的机器上运行的 Python 的确切版本。

    这对我有用:

    1. yum install -y python-setuptools

    2. easy_install supervisor==3.4.0

    3. 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
    
    1. nano /etc/chkserv.d/chkservd.conf,添加supervisord:1这一行,然后保存文件

    2. touch /etc/chkserv.d/supervisord 创建 chkservd 配置文件

    3. nano /etc/chkserv.d/supervisord,添加service[supervisord]=x,x,x,service supervisord restart,supervisord,root这一行,然后保存文件

    4. supervisord 现在将显示在 WHM 中的 Service Manager 下,chkservd 将启动它并确保它继续运行,但要手动启动它,只需运行 supervisord

    有关向chkservdclick here 添加服务的更多信息。

    【讨论】:

      【解决方案2】:

      希望这对某人有用,这是我除了@Abdu 的回答之外所经历的过程,以使事情在 CentOS 7 上运行。

      1.安装主管

      easy_install supervisor

      * 如果未安装,请运行yum install -y python-setuptools,然后运行easy_install supervisor

      2。准备工作

      要运行理想的设置,您应该运行以下命令...

      # 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
      

      完成此操作后,您现在应该可以使用 systemctl 启动和停止 supervisor。要启动 systemctl,请运行 systemctl start supervisord。要查看主管的状态,请运行systemctl status supervisord

      您可以在/etc/supervisor/conf.d下创建任意数量的自定义配置

      3.在系统启动时启用

      您还应该在启动时通过运行启用 supervisord

      systemctl enable supervisord
      

      【讨论】:

      • 如果您收到错误消息“unix:///var/run/supervisor.sock no such file”[unix_http_server] file=/var/run/supervisor.sock ; (the path to the socket file) chmod=0700 ; sockef file mode (default 0700),请将这些添加到 /etc/supervisor/supervisord.conf 的顶部>
      【解决方案3】:

      这里是如何在 centos 7 上安装和配置 supervisord 以永久运行 Laravel 队列:

      1. easy_install supervisor
      2. yum install supervisor
      3. 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
      
      1. systemctl enable supervisord 启动时自动运行
      2. systemctl restart supervisord重启服务

      【讨论】:

      • 你假设人们有easy_install,在我的情况下,我的新 CentOS 没有。得到它:yum install -y python-setuptools 然后你可以继续(所有以sudo 开头的命令,除非你是root ......)。这不起作用:yum install supervisor:它已经通过 easy_install 安装了。
      • 如果你有一个像fabric这样的部署工具并且想在.conf文件中有多个脚本/程序。
      猜你喜欢
      • 2015-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-12
      • 1970-01-01
      • 1970-01-01
      • 2020-10-09
      • 2015-06-08
      相关资源
      最近更新 更多