继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

你不知道的CS模式的进程管理工具,状态监测、项目启停一目了然!

OverWrite_235
关注TA
已关注
手记 138
粉丝 10
获赞 65

(摘自百度百科)Supervisor是用Python开发的一套通用的进程管理程序,能将一个普通的命令行进程变为后台daemon,并监控进程状态,异常退出时能自动重启。它是通过fork/exec的方式把这些被管理的进程当作supervisor的子进程来启动,这样只要在supervisor的配置文件中,把要管理的进程的可执行文件的路径写进去即可。也实现当子进程挂掉的时候,父进程可以准确获取子进程挂掉的信息的,可以选择是否自己启动和报警。supervisor还提供了一个功能,可以为supervisord或者每个子进程,设置一个非root的user,这个user就可以管理它对应的进程。

file

Supervisor安装

'''
环境:Centos7
安装wget:yum install wget
下载Supervisor源码包
'''
# [root@localhost software]# yum install wget
# 已加载插件:fastestmirror
# Loading mirror speeds from cached hostfile
#  * base: mirror.lzu.edu.cn
#  * extras: mirror.lzu.edu.cn
#  * updates: mirrors.163.com
# 正在解决依赖关系
# --> 正在检查事务
# ---> 软件包 wget.x86_64.0.1.14-18.el7_6.1 将被 安装


# [root@localhost software]# wget https://files.pythonhosted.org/packages/d3/7f/c780b7471ba0ff4548967a9f7a8b0bfce222c3a496c3dfad0164172222b0/supervisor-4.2.2.tar.gz
# --2021-09-24 15:45:28--  https://files.pythonhosted.org/packages/d3/7f/c780b7471ba0ff4548967a9f7a8b0bfce222c3a496c3dfad0164172222b0/supervisor-4.2.2.tar.gz
# 正在解析主机 files.pythonhosted.org (files.pythonhosted.org)... 151.101.77.63, 2a04:4e42:12::319
# 正在连接 files.pythonhosted.org (files.pythonhosted.org)|151.101.77.63|:443... 已连接。
# 已发出 HTTP 请求,正在等待回应... 200 OK
# 长度:463657 (453K) [application/x-tar]
# 正在保存至: “supervisor-4.2.2.tar.gz”

Supervisor配置

'''
1、解压源码包
tar -zxvf supervisor-4.2.2.tar.gz
'''

# root@localhost software]# tar -zxvf supervisor-4.2.2.tar.gz
# supervisor-4.2.2/
# supervisor-4.2.2/CHANGES.rst
# supervisor-4.2.2/COPYRIGHT.txt

'''
2、安装python支持
yum install python-setuptools
'''

# [root@localhost supervisor-4.2.2]# yum install python-setuptools
# 已加载插件:fastestmirror
# Loading mirror speeds from cached hostfile

'''
3、编译源码包
python setup.py install
'''

# [root@localhost supervisor-4.2.2]# python setup.py install
# running install
# running bdist_egg
# running egg_info
# writing requirements to supervisor.egg-info/requires.txt

'''
4、编译后删除其他多余文件、除了build、dist两个文件夹其他都是多余的
'''

# [root@localhost supervisor-4.2.2]# ll
# 总用量 0
# drwxr-xr-x. 4 root root 43 9月  24 15:51 build
# drwxr-xr-x. 2 root root 40 9月  24 15:51 dist

'''
5、创建配置文件、编辑配置文件、赋予文件权限
'''

# echo_supervisord_conf > /usr/etc/supervisord.conf

# [root@localhost supervisor-4.2.2]# vi  /usr/etc/supervisord.conf

# chmod 777 /usr/etc/supervisord.conf

# [root@localhost supervisor-4.2.2]# mkdir config

# /usr/etc/supervisord.conf文件主要配置两个关键项

# [supervisord]
# user=普通用户名称            ; setuid to this UNIX account at startup; recommended if root

# [include]
# files = /software/supervisor-4.2.2/config   # 这个是以后的项目路径

'''
6、查看版本
'''

# [root@localhost supervisor-4.2.2]# supervisord -v
# 4.2.2

'''
7、解决python2.7.sock报错的问题
'''

# [root@localhost supervisor-4.2.2]# /usr/bin/python2 /usr/bin/supervisord -c /usr/etc/supervisord.conf

'''
8、更新配置
'''

# supervisorctl update

'''
9、配置一个程序项目配置
注意:这里使用hello_world只是作为一个说明,一般项目指的都是一直运行的进程服务,比如:redis、tomcat、nginx等等。
'''
# [root@localhost config]# vi hello_world.config

# [program:hello_world]
# command=/usr/bin/python2 /software/supervisor-4.2.2/hello_world.py
# priority=998
# autostart=true
# autorestart=true
# startsecs=60
# startretries=3
# stopsignal=TERM
# stopwaitsecs=10
# user=root
# stdout_logfile=/software/supervisor-4.2.2/logs/hello_world.log
# stdout_logfile_maxbytes=100MB
# stdout_logfile_backups=10
# stdout_capture_maxbytes=1MB
# stderr_logfile=/software/supervisor-4.2.2/logs/hello_world.log
# stderr_logfile_maxbytes=100MB
# stderr_logfile_backups=10
# stderr_capture_maxbytes=1MB

'''
10、创建hello_world项目
注意:这里使用hello_world只是作为一个说明,一般项目指的都是一直运行的进程服务,比如:redis、tomcat、nginx等等。
'''

# [root@localhost supervisor-4.2.2]# vi hello_world.py

# # -*- coding:utf-8 -*-
# print "我是hello_world程序"

'''
11、重启配置的所有程序
'''

# [root@localhost supervisor-4.2.2]# supervisorctl reload
# Restarted supervisord

'''
12、启动或停止某个项目
注意:这里使用hello_world只是作为一个说明,一般项目指的都是一直运行的进程服务,比如:redis、tomcat、nginx等等。
'''

# supervisorctl start 项目名称
# supervisorctl start hello_world

# supervisorctl stop 项目名称

# supervisorctl stop hello_world
打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP