使用supervisor管理后台进程
在linux中supervisor是用来管理后台进程的,是一个用python写的进程管理工具,可以让宕机的进程重启。这里我们大概讲一下用他来管理uWSGI。
一.安装supervisor
1.python2下的安装
supervisor不支持python3,所以你安装可以使用自带的python2安装,但是自带的python2没有安装pip
(1)要安装pip,首先要安装setuptools
wget https://pypi.python.org/packages/ff/d4/209f4939c49e31f5524fa0027bf1c8ec3107abaf7c61fdaad704a648c281/setuptools-21.0.0.tar.gz#md5=81964fdb89534118707742e6d1a1ddb4 tar xvf setuptools-21.0.0.tar.gz //解压文件 cd setuptools-21.0.0 python setup.py install
(2)安装pip
wget https://pypi.python.org/packages/11/b6/abcb525026a4be042b486df43905d6893fb04f05aac21c32c638e939e447/pip-9.0.1.tar.gz tar xvf pip-9.0.1.tar.gz cd pip-9.0.1 python setup.py install
(3)安装supervisor
pip install supervisor
2.python3下的安装
默认的pip安装的只支持python2,当然手动安装新版就支持python3了
pip install git+https://github.com/Supervisor/supervisor
二.配置supervisor
生成 supervisor 默认配置文件,放在 /etc/supervisord.conf 路径中(如果出现echo_supervisord_conf: command not **found** 则可能需要输入全路径,使用find / -name supervisor*找到路径):
echo_supervisord_conf > /etc/supervisord.conf
修改配置文件
# 修改配置文件
vi /etc/supervisord.conf # 加入以下配置信息在最下面
[include]
files = /etc/supervisord.d/*.conf # /etc/supervisord.d/下所有conf结尾的 [inet_http_server]
port=127.0.0.1:9001 # 端口号
username=user # web登录名
password=123 # 登录密码
配置文件详情
[unix_http_server]
file=/tmp/supervisor.sock ; UNIX socket 文件,supervisorctl 会使用
;chmod=0700 ; socket 文件的 mode,默认是 0700
;chown=nobody:nogroup ; socket 文件的 owner,格式: uid:gid
;username=user ; default is no username (open server)
;password=123 ; default is no password (open server) ;[inet_http_server] ; HTTP 服务器,提供 web 管理界面
;port=127.0.0.1:9001 ; Web 管理后台运行的 IP 和端口,如果开放到公网,需要注意安全性
;username=user ; 登录管理后台的用户名
;password=123 ; 登录管理后台的密码 [supervisord]
logfile=/tmp/supervisord.log ; 日志文件,默认是 $CWD/supervisord.log
logfile_maxbytes=50MB ; 日志文件大小,超出会 rotate,默认 50MB
logfile_backups=10 ; 日志文件保留备份数量默认 10
loglevel=info ; 日志级别,默认 info,其它: debug,warn,trace
pidfile=/tmp/supervisord.pid ; pid 文件
nodaemon=false ; 是否在前台启动,默认是 false,即以 daemon 的方式启动
minfds=1024 ; 可以打开的文件描述符的最小值,默认 1024
minprocs=200 ; 可以打开的进程数的最小值,默认 200 ; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface [supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; 通过 UNIX socket 连接 supervisord,路径与 unix_http_server 部分的 file 一致
;serverurl=http://127.0.0.1:9001 ; 通过 HTTP 的方式连接 supervisord ;包含其他的配置文件
[include]
files = relative/directory/*.ini ; 可以是 *.conf 或 *.ini
启动supervisor
supervisord -c /etc/supervisord.conf
再启动的时候可能会报错,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。
解决的是方式:
unlink /tmp/supervisor.sock
通过http://ip:9001/访问web界面,账户名密码就是你配置的,效果如下

三.加入监控程序
新建管理的监控文件夹,每个程序设置配置文件,达到隔离的效果
mkdir /etc/supervisord.d/
在/etc/supervisor.d/目录下面加入需要管理的程序
vi /etc/supervisor.d/orange_web.conf # 新建一个管理程序 # 程序的名字,在supervisor中可以用这个名字来管理该程序,随便起
[program:orange_web]
# 指定运行用户
user = root
# 启动程序的命令uwsgi启动命令
command = uwsgi --ini /var/www/script/uwsgi.ini
# 项目的目录
directory = /var/www/orange_web
# 开始的时候等待多少秒
startsecs = 0
# 停止的时候等待多少秒
stopwaitsecs = 0
# 设置改程序是否虽supervisor的启动而启动
autorstart = true
# 程序挂了是否需要重新将其启动
autorestart = true
# 是否将程序错误信息重定向到文件
redirect_stderr=true
# 输出的log文件位置
stdout_logfile = /var/www/script/supervisord.log
# 输出的错误文件位置
stderr_logfile = /var/www/script/supervisord.err [supervisord]
# log的级别
loglevel = info
重新启动supervisord
supervisorctl reload # 重启
重新访问supervisor管理界面

在这里就安装配置成功了,哈哈哈就可以去跟周围的女同学装逼了。。
四.supervisor常用命令
supervisorctl start programXX # 启动进程programXX supervisorctl stop programXX # 停止进程programXX supervisorctl restart programXX # 重启进程programXX supervisorctl stop groupworker # 停止所有名为groupworker这个分组的进程(start,restart都可用) supervisorctl stop all # 停止所有进程(start,restart都可用,但是都不会载入最新的配置文件) supervisorctl reload # 载入最新的配置文件,重载进程
参考链接:
Django+uWSGI+Nginx部署 https://www.cnblogs.com/zzqit/p/10103303.html
https://www.jianshu.com/p/23762bd086e1
使用supervisor管理后台进程的更多相关文章
- ubuntu supervisor管理uwsgi+nginx
一.概述 superviosr是一个Linux/Unix系统上的进程监控工具,他/她upervisor是一个Python开发的通用的进程管理程序,可以管理和监控Linux上面的进程,能将一个普通的命令 ...
- Supervisor 管理后台守护进程
Supervisor 管理后台守护进程 参考原文如下: http://codinn.com/people/brant/notes/110948/ 做了一些注释 +++++++++++引用开始+++++ ...
- 如何使用supervisor管理你的应用
1.前言 Supervisor(http://supervisord.org/)是用Python开发的一个client/server服务,是UNIX-like系统下的一个进程管理工具,不支持Windo ...
- Supervisor管理进程
Supervisor管理进程 转载 2016年04月14日 18:26:45 标签: supervisord 28344 Supervisor重新加载配置启动新的进程 liaojie 发布于 1年前, ...
- 配置supervisor管理beego应用
一.golang.beego等环境安装与配置 二.supervisor安装 github项目地址:https://github.com/Supervisor/supervisor 克隆项目:git c ...
- supervisor管理进程工具配置
Supervisor(http://supervisord.org/)是用Python开发的一个client/server服务,是Linux/Unix系统下的一个进程管理工具,不支持Windows系统 ...
- Supervisor 管理进程,Cloud Insight 监控进程,完美!
Supervisor 是由 Python 语言编写.基于 linux 操作系统的一款服务器管理工具,用于监控服务器的运行,发现问题能立即自动预警及自动重启等. Cloud Insight 是一款次世代 ...
- supervisor管理进程 superlance对进程状态报警
supervisor介绍 首先,介绍一下supervisor.Supervisor(http://supervisord.org/)是用Python开发的一个client/server服务,是Linu ...
- 使用Supervisor管理Linux进程
使用Supervisor管理Linux进程 简介 Supervisor是一个C/S系统,它可以在类UNIX系统上控制系统进程,由python编写,提供了大量的功能来实现对进程的管理. 安装 sudo ...
随机推荐
- 【C++对象模型】第五章 构造、解构、拷贝 语意学
1.构造语义学 C++的构造函数可能内带大量的隐藏码,因为编译器会扩充每一个构造函数,扩充程度视 class 的继承体系而定.一般而言编译器所做的扩充操作大约如下: 所有虚基类成员构造函数必须被调用, ...
- JNLP Slave connection error解决办法
Replace in jnlp-file <argument>-workDir</argument> <argument /> with <argume ...
- 「6月雅礼集训 2017 Day4」qyh(bzoj2687 交与并)
原题传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2687 [题目大意] 给出若干区间,求一个区间的大于等于2的子集,使得 |区间并| 和 | ...
- codechef September Challenge 2017 Fill The Matrix
这道题我们发现0就代表相同1代表少1或者大1 那么我们根据题目连边 如果存在1(边权只为或0)个数为奇数的环就是无解 #include<cstdio> #include<cstrin ...
- 最短路之spfa系列
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2544 Problem Description 在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮的t ...
- python3中字典的遍历和合并
#字典的遍历方式 dic={"a":1,"b":2,"c":3} for k in dic: print (k,dic[k]) for k, ...
- vue_axios请求后台接口cookie无法传值
2018年3月7日: 当我们使用http向后台发送请求的时候,需要通过cookie把一些密匙传递给后台做判断授权登陆,当然前提是后台会先把cookie保持到本地. 使用vue开发的时候,会出现这个问题 ...
- Python自动化运维 - Django(二)Ajax基础 - 自定义分页
Ajax基础 AJAX 不是新的编程语言,而是一种使用现有标准的新方法. AJAX 是与服务器交换数据并更新部分网页的艺术,在不重新加载整个页面的情况下. 什么是Ajax AJAX = 异步 Java ...
- linux编程之多线程编程
我们知道,进程在各自独立的地址空间中运行,进程之间共享数据需要用mmap或者进程间通信机制,有些情况需要在一个进程中同时执行多个控制流程,这时候线程就派上了用场,比如实现一个图形界面的下载软件,一方面 ...
- linux内核启动分析(3)
主要分析do_basic_setup函数里面的do_initcalls()函数,这个函数用来调用所有编译内核的驱动模块中的初始化函数. static void __init do_initcalls( ...