[TOC]
Supervisor最佳實踐
1、簡介
Supervisor是一個客戶端/服務器系統(tǒng),允許其用戶在類UNIX操作系統(tǒng)上控制許多進程。
它可以使進程(非守護進程)以守護進程的方式運行。
2、安裝
官網(wǎng)介紹了多種安裝方式:
- yum
- pip
- 下載安裝包
詳見:官方安裝教程:(http://www.supervisord.org/installing.html)
建議用系統(tǒng)工具安裝,開機會自動啟動。
Centos 用yum,Ubuntu 用apt-get。
其他安裝方式可以用chkconfig設置開機啟動。
yum install supervisor
3、使用流程
安裝完成后有以下三個命令
- echo_supervisord_conf 生成配置文件模板
- supervisord supervisor 服務端命令
- supervisorctl supervisor 客戶端命令
3.1 生成配置文件
echo_supervisord_conf > supervisord.conf
配置文件存放建議:
Supervisord 相關配置放 /etc/supervisord.conf ;
/etc/supervisord.conf 中[include]配置 /etc/supervisord.d/*.ini
[include]
files = /etc/supervisord.d/*.ini
/etc/supervisord.d/.ini 可以配置多個*程序。
可以用echo_supervisord_conf生成配置文件,只截取[program:sample]的相關配置。
程序具體配置參考文檔。
Supervisor 配置文件查找順序:
- $CWD/supervisord.conf
- $CWD/etc/supervisord.conf
- /etc/supervisord.conf
- /etc/supervisor/supervisord.conf (since Supervisor 3.3.0)
- ../etc/supervisord.conf (Relative to the executable)
- ../supervisord.conf (Relative to the executable)
3.2 運行
# 啟動 Supervisord 服務
service supervisord start
# 查看運行狀態(tài)
supervisorctl status
# 重啟
supervisorctl reload|restart

image.png