Centos7 下 Supervisor 安装配置

2017-08-17 03:39:12   服务器

  supervisord  

安装

  1. yum install python-setuptools
  2. easy_install supervisor
  3. echo_supervisord_conf > /etc/supervisord.conf

配置

/etc/supervisord.conf说明

  1. ;[program:theprogramname]
  2. ;command=/bin/cat ; 命令路径
  3. ;process_name=%(program_name)s ; 进程名称格式化
  4. ;numprocs=1 ; 进程数量
  5. ;directory=/tmp ; 执行目录
  6. ;umask=022 ; 掩码:--- -w- -w-, 转换后rwx r-x w-x
  7. ;priority=999 ; 优先级,值越高,最后启动,最先被关闭,默认值999
  8. ;autostart=true ; *自动重启
  9. ;startsecs=1 ; 启动延时执行,默认1
  10. ;startretries=3 ; 失败最大尝试次数
  11. ;autorestart=unexpected ; when to restart if exited after running (def: unexpected)
  12. ;exitcodes=0,2 ; 当退出码是0,2时,执行重启,默认值0,2
  13. ;stopsignal=QUIT ; signal used to kill process (default TERM)
  14. ;stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10)
  15. ;stopasgroup=false ; send stop signal to the UNIX process group (default false)
  16. ;killasgroup=false ; SIGKILL the UNIX process group (def false)
  17. ;user=chrism ; #运行用户
  18. ;redirect_stderr=true ; redirect proc stderr to stdout (default false)
  19. ;stdout_logfile=/a/path ; stdout log path, NONE for none; default AUTO
  20. ;stdout_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
  21. ;stdout_logfile_backups=10 ; # of stdout logfile backups (0 means none, default 10)
  22. ;stdout_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0)
  23. ;stdout_events_enabled=false ; emit events on stdout writes (default false)
  24. ;stderr_logfile=/a/path ; stderr log path, NONE for none; default AUTO
  25. ;stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
  26. ;stderr_logfile_backups=10 ; # of stderr logfile backups (0 means none, default 10)
  27. ;stderr_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0)
  28. ;stderr_events_enabled=false ; emit events on stderr writes (default false)
  29. ;environment=A="1",B="2" ; process environment additions (def no adds)
  30. ;serverurl=AUTO ; override serverurl computation (childutils)

Laravel 队列进程实例

  1. [program:demo]
  2. process_name=%(program_name)s_%(process_num)02d
  3. command=/usr/local/php7/bin/php /www/demo/artisan queue:work --queue=demo --sleep=3
  4. --tries=3
  5. autostart=true
  6. autorestart=true
  7. user=root
  8. numprocs=3
  9. redirect_stderr=true
  10. stdout_logfile=/www/demo/storage/logs/worker.log

(inet_http_server) 配置说明

配置后可使用浏览器查看和控制进程状态

  1. [inet_http_server] ; inet (TCP) server disabled by default
  2. port=0.0.0.0:9001 ; (ip_address:port specifier, *:port for all iface)
  3. username=user ; 用户名 (default is no username (open server))
  4. password=123 ; 密码 (default is no password (open server))

启动和关闭

启动 supervisord

supervisord -c /etc/supervisord.conf

查看服务器进程

ps -ef | grep super

关闭 supervisord

supervisorctl shutdown

重新载入配置

supervisorctl reload

其他客户端命令

  1. supervisorctl status #查看程序状态
  2. supervisorctl stop theprogramname # 停止 theprogramname
  3. supervisorctl start theprogramname # 启动theprogramname
  4. supervisorctl restart theprogramname # 重启
  5. supervisorctl reread # 读取有更新(增加)的配置文件,不会启动新添加的程序
  6. supervisorctl update # 重启配置文件修改过的程序

设置开机启动

创建 supervisord.service

  1. # supervisord service for systemd (CentOS 7.0+)
  2. # by ET-CS (https://github.com/ET-CS)
  3. [Unit]
  4. Description=Supervisor daemon
  5. [Service]
  6. Type=forking
  7. ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf
  8. ExecStop=/usr/bin/supervisorctl shutdown
  9. ExecReload=/usr/bin/supervisorctl reload
  10. KillMode=process
  11. Restart=on-failure
  12. RestartSec=42s
  13. [Install]
  14. WantedBy=multi-user.target

supervisord.service 代码仓库: https://github.com/Supervisor/initscripts/blob/master/centos-systemd-etcs

加入开机启动

  1. cp supervisord.service /usr/lib/systemd/system/supervisord.service
  2. systemctl enable supervisord
  3. systemctl is-enabled supervisord

参考链接