(摘自百度百科)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

【往期精选】

● 如何将一个python应用以docker镜像的方式来运行?

● python-celery专注于实现分布式异步任务处理、任务调度的插件!

● python远程服务操作工具:fabric,远程命令、本地命令、服务器操作利器!

● python超赞插件you-get,执行一行命令即可下载、命令行下载工具推荐!

● 办公自动化:Python-win32com自动将word文档转换成pdf格式!

● pandas数据统计插件的连接函数concat()妙用,灵活处理数据对象!

● Git LFS 3.0.0 发布,对大文件进行版本控制的 Git 扩展

● python有序序列的字典序列推导式运用技巧!

● Django 4.0 alpha 1 发布

● python经典有序序列的list列表推导式实践运用

● python常用转义字符串总结:各种字符转义的不同、如何取消转义字符效果?

● python内置函数通过字符串的方式来执行函数代码块,类似java的反射机制相当强大!

● 磨刀不误砍柴工,PyCharm开发工具的常规配置,充分提高开发效率!

● python-openpyxl Excel的单元格样式设置,包括字体、样式、宽高等等!

内容来源于网络如有侵权请私信删除

文章来源: 博客园

原文链接: https://www.cnblogs.com/lwsbc/p/15422068.html

你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!