这篇文章更多侧重于如何使用Supervisor,所以安装方法我采用通用的方法,python来安装。
CentOS安装:
yum install python-pip git -y
yum -y install git gcc python-setuptools lsof lrzsz python-devel libffi-devel openssl-devel iptables
yum -y groupinstall "Development Tools"
easy_install supervisor
pip install --upgrade pip
wget -N -P /etc/ --no-check-certificate https://raw.githubusercontent.com/mmmwhy/ss-panel-and-ss-py-mu/master/supervisord.conf
supervisorctl shutdown
Debian&Ubuntu安装:
apt-get upgrade -y
apt-get install supervisor python-pip lsof -y
apt-get install build-essential wget -y
apt-get install iptables git -y
apt-get install python-pip git -y
wget -N -P /etc/ --no-check-certificate https://raw.githubusercontent.com/mmmwhy/ss-panel-and-ss-py-mu/master/supervisord.conf
supervisorctl shutdown
这样我们就安装完supervisor了。为什么要下载supervisord.conf文件呢?
因为python安装的不带配置文件,详见Linux下Supervisor详细配置
上面下载的supervisord.conf文件自带了魔改V3的后端守护进程,我也不打算做修改,具体在最后这几行:
;files = relative/directory/*.ini
[program:ssr]
command = python /root/shadowsocks/server.py
user = root
autostart = true
autorestart = true
一般人看到这个也就明白了。 command这行这就是你守护的进程如何启动,举个例子:
启动SSR服务:
启动魔改V3后端:
如何守护多个进程?
command = python /root/shadowsocks/server.py
user = root
autostart = true
autorestart = true
[program:2]
command = python /root/shadowsocks/server.py
user = root
autostart = true
autorestart = true
所以,对于配置文件,我们只需要手动修改/etc/supervisord.conf文件就行。
守护一个,底部的那个修改下command
守护两个,底部追加一个[program:2] 开头的守护进程即可。
守护脚本写好了,我们接下来需要启动Supervisor了
测试下:
/usr/lib/python2.7/site-packages/supervisor-3.3.4-py2.7.egg/supervisor/options.py:461: UserWarning: Supervisord is running as root and it is searching for its configuration file in default locations (including its current working directory); you probably want to specify a "-c" argument specifying an absolute path to a configuration file for improved security.
'Supervisord is running as root and it is searching '
Error: Another program is already listening on a port that one of our HTTP servers is configured to use. Shut this program down first before starting supervisord.
For help, use /usr/bin/supervisord -h
这个告诉我们,需要带参数运行。
下面附上常用命令:
开启supervisor:supervisord -c /etc/supervisord.conf
开机自启:
chmod +x /etc/rc.local
注意一个问题,运行的程序需要绝对路径+绝对指令运行,所以无法执行例如:
这样的程序,我们如何找到程序的入口呢?以ssr为例子:
终端执行:
里面可以找到ssr的进程具体脚本:
复制这个指令到配置文件,然后关闭进程,再开启supervisor即可进行守护。
上个测试:
简单说说运行方法:
安装-修改配置文件-启动程序-配置开机自启。