(摘自百度百科)Supervisor是用Python开发的一套通用的过程管理程序,能将一个一般的命令行过程变为后盾daemon,并监控过程状态,异样退出时能主动重启。它是通过fork/exec的形式把这些被治理的过程当作supervisor的子过程来启动,这样只有在supervisor的配置文件中,把要治理的过程的可执行文件的门路写进去即可。也实现当子过程挂掉的时候,父过程能够精确获取子过程挂掉的信息的,能够抉择是否本人启动和报警。supervisor还提供了一个性能,能够为supervisord或者每个子过程,设置一个非root的user,这个user就能够治理它对应的过程。
【浏览全文】
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的单元格款式设置,包含字体、款式、宽低等等!