项目中的微服务较多,需要一个工具对多个进程进行管理,supervisor完全符合了要求。
一、安装
本来想偷懒,用yum install supervisor安装,留意了一下,发现yum中的还是2.*的版本,只好通过Python工具来安装,其实也很简单:
yum install python-setuptools
easy_install supervisor
echo_supervisord_conf (测试安装是否成功,这里输出的是默认配置内容)
我这里安装的是3.3.1版本,还可以手动下载tar包安装。
#tar解压到指定目录yourDir
tar -zxvf supervisor-3.3.1.tar.gz -C /yourDir
cd /yourDir
python setup.py install
二、配置
建立目录/etc/supervisor/,这里存放配置文件。官网上说明3.*版本启动时如果没指定配置文件,会到这个目录找配置文件。
mkdir -m 755 -p /etc/supervisor/
mkdir -m 755 -p /etc/supervisor/conf.d/
echo_supervisord_conf > /etc/supervisor/supervisord.conf
#添加以下内容,即include这个目录下的配置文件:
[include]
files = ./conf.d/*.conf
三、使用
supervisord -c /etc/supervisor/supervisord.conf (启动)
supervisorctl -c /etc/supervisor/supervisord.conf (查看)